Changeset 1357 for trunk/src/org/expeditee/auth/Actions.java
- Timestamp:
- 05/07/19 14:08:23 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/auth/Actions.java
r1348 r1357 22 22 import java.util.Collection; 23 23 import java.util.HashMap; 24 import java.util.Iterator; 24 25 import java.util.List; 25 26 import java.util.Map; … … 38 39 import org.expeditee.auth.account.Authenticate.AuthenticationResult; 39 40 import org.expeditee.auth.account.Create; 41 import org.expeditee.auth.account.Create.CreateResult; 40 42 import org.expeditee.auth.account.Password; 41 43 import org.expeditee.auth.gui.MailBay; … … 49 51 import org.expeditee.items.Text; 50 52 import org.expeditee.settings.UserSettings; 53 import org.expeditee.settings.identity.passwordrecovery.Colleagues; 51 54 import org.expeditee.settings.identity.secrets.KeyList; 52 55 import org.expeditee.stats.Formatter; … … 78 81 Mail.sendMail(mail, recipient); 79 82 MessageBay.displayMessage("Test message sent."); 83 } 84 public static void SetPWColleagues(String colleagueOne, String colleagueTwo) { 85 Colleagues.Colleague_One.set(colleagueOne); 86 Colleagues.Colleague_Two.set(colleagueTwo); 87 Colleagues.Colleague_One_Email.set("[email protected]"); 88 Colleagues.Colleague_Two_Email.set("[email protected]"); 80 89 } 81 90 … … 181 190 } 182 191 183 Create.createAccount(userData); 184 Authenticate.login(userData); 185 AuthenticatorBrowser.Authenticated = true; 192 CreateResult result = Create.createAccount(userData); 193 if (result == CreateResult.SuccessCreateAccount) { 194 Authenticate.login(userData); 195 AuthenticatorBrowser.Authenticated = true; 196 } else { 197 MessageBay.errorMessage(result.toString()); 198 } 186 199 } else { 187 200 MessageBay.errorMessage("Please fill out all the supplied text boxes."); … … 196 209 */ 197 210 public static void AuthLogin() { 198 finalCollection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();199 finalOptional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password);211 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems(); 212 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, AuthenticationTag.Password); 200 213 if (userdata.isPresent()) { 201 214 AuthenticationResult result = Authenticate.login(userdata.get()); 202 215 if (result == AuthenticationResult.SuccessLogin) { 203 216 MessageBay.displayMessage(result.toString()); 217 AuthenticatorBrowser.Authenticated = true; 204 218 } else { 205 219 MessageBay.errorMessage(result.toString()); 206 220 } 207 //login(userdata.get());208 AuthenticatorBrowser.Authenticated = true;209 221 } else { 210 222 MessageBay.errorMessage("Please fill out all the supplied text boxes."); … … 258 270 } 259 271 260 public static void Auth ResetPasswordPt1() {272 public static void AuthDistributeIntergalacticNumber() { 261 273 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems(); 262 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username); 274 Optional<Map<AuthenticationTag, String>> userdata = 275 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username); 263 276 if (userdata.isPresent()) { 264 277 Map<AuthenticationTag, String> userData = userdata.get(); … … 267 280 userData.put(AuthenticationTag.Email, email); 268 281 Password.generateAndDeliverIntergalacticNumber(userData); 269 MessageBay.displayMessage("A Intergalactic number has been sent to the email associated with your account. Enter it below to proceed."); 270 } 271 } 272 273 public static void AuthResetPasswordPt2() { 282 MessageBay.displayMessage("A identity number has been sent to the email " 283 + "associated with your account. Enter it below to proceed."); 284 } 285 } 286 287 public static void AuthSubmitIntergalacticNumber() { 274 288 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems(); 275 Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, 276 AuthenticationTag.IntergalacticNumber, AuthenticationTag.NewPassword, AuthenticationTag.NewPasswordAgain); 289 Optional<Map<AuthenticationTag, String>> userdata = 290 AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username, 291 AuthenticationTag.IntergalacticNumber); 277 292 if (userdata.isPresent()) { 278 Map<AuthenticationTag, String> userData = userdata.get(); 279 String username = userData.get(AuthenticationTag.Username); 280 String email = getEmailFromUsername(username); 281 userData.put(AuthenticationTag.Email, email); 282 Password.confirmIntergalacticNumberAndGenerateSubstituteAccount(userData); 293 Map<AuthenticationTag, String> tags = userdata.get(); 294 String username = tags.get(AuthenticationTag.Username); 295 String intergalacticNumber = tags.get(AuthenticationTag.IntergalacticNumber); 296 boolean match = false; 297 try { 298 match = AuthenticatorBrowser.getInstance().confirmIntergalaticNumber(username, intergalacticNumber); 299 } catch (NoSuchAlgorithmException | KeyStoreException | CertificateException | ClassNotFoundException 300 | IOException | SQLException e) { 301 e.printStackTrace(); 302 return; 303 } 304 if (!match) { 305 MessageBay.errorMessage("The provided identity number does not match the one stored on file."); 306 return; 307 } 308 String[] colleagues = getPasswordColleaguesFromUsername(username); 309 Password.confirmIntergalacticNumberAndAlertColleagues(userdata.get(), colleagues); 283 310 } 284 311 } 285 312 286 313 private static String getEmailFromUsername(String username) { 287 Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();288 314 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials"); 289 315 Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf"); … … 303 329 int number = Integer.parseInt(fileName.replace(".exp", "")); 304 330 Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH); 305 textItems = credentialsFrame.getTextItems();331 Collection<Text> textItems = credentialsFrame.getTextItems(); 306 332 textItems.removeIf(text -> !text.getText().startsWith("Email: ")); 307 333 if (textItems.isEmpty()) { … … 313 339 return email; 314 340 } 341 } 342 343 private static String[] getPasswordColleaguesFromUsername(String username) { 344 Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials"); 345 Path credentialsFilePath = credentialsDirPath.resolve("pwcolleagues.inf"); 346 String fileName = null; 347 if (credentialsFilePath.toFile().exists()) { 348 try (Scanner in = new Scanner(credentialsFilePath)) { 349 fileName = in.nextLine(); 350 } catch (IOException e) { 351 MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?"); 352 return null; 353 } 354 } else { 355 MessageBay.errorMessage("Unable to password colleague frame for specified user, are they registered on this computer?"); 356 return null; 357 } 358 359 int number = Integer.parseInt(fileName.replace(".exp", "")); 360 Frame pwColleagueFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH); 361 Collection<Text> textItems = pwColleagueFrame.getTextItems(); 362 textItems.removeIf(text -> !text.getText().startsWith("Colleague")); 363 364 String[] ret = new String[4]; 365 Iterator<Text> it = textItems.iterator(); 366 while(it.hasNext()) { 367 String content = it.next().getText().toLowerCase().trim(); 368 if (content.contains("colleague_one:")) { 369 ret[0] = content.replace("colleague_one:", "").trim(); 370 } else if (content.contains("colleague_two:")) { 371 ret[1] = content.replace("colleague_two:", "").trim(); 372 } else if (content.contains("colleague_one_email:")) { 373 ret[2] = content.replace("colleague_one_email:", "").trim(); 374 } else if (content.contains("colleague_two_email:")) { 375 ret[3] = content.replace("colleague_two_email:", "").trim(); 376 } 377 } 378 return ret; 315 379 } 316 380
Note:
See TracChangeset
for help on using the changeset viewer.