Changeset 1340 for trunk


Ignore:
Timestamp:
04/30/19 16:14:25 (5 years ago)
Author:
bln4
Message:

Progress on the 'Forgot Password' process

Location:
trunk/src/org/expeditee/auth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/auth/Actions.java

    r1336 r1340  
    2525import java.util.Map;
    2626import java.util.Optional;
     27import java.util.Scanner;
    2728import java.util.stream.Collectors;
    2829
     
    258259       
    259260        public static void AuthResetPasswordPt1() {
    260                 MessageBay.displayMessage("AuthResetPasswordPt1");
     261                Collection<Text> textItems = DisplayController.getCurrentFrame().getTextItems();
     262                Optional<Map<AuthenticationTag, String>> userdata = AuthenticationTag.fetchUserData(textItems, false, AuthenticationTag.Username);
     263                if (userdata.isPresent()) {
     264                        Map<AuthenticationTag, String> userData = userdata.get();
     265                       
     266                        String username = userData.get(AuthenticationTag.Username);
     267                        Path credentialsDirPath = Paths.get(FrameIO.PROFILE_PATH).resolve(username).resolve(username + "-credentials");
     268                        Path credentialsFilePath = credentialsDirPath.resolve("credentials.inf");
     269                        String fileName = null;
     270                        if (credentialsFilePath.toFile().exists()) {
     271                                try (Scanner in = new Scanner(credentialsFilePath)) {
     272                                        fileName = in.nextLine();
     273                                } catch (IOException e) {
     274                                        MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
     275                                        return;
     276                                }
     277                        } else {
     278                                MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
     279                                return;
     280                        }
     281                       
     282                        int number = Integer.parseInt(fileName.replace(".exp", ""));
     283                        Frame credentialsFrame = FrameIO.LoadFrame(username + number, FrameIO.PROFILE_PATH);
     284                        textItems = credentialsFrame.getTextItems();
     285                        textItems.removeIf(text -> !text.getText().startsWith("Email: "));
     286                        if (textItems.isEmpty()) {
     287                                MessageBay.errorMessage("Unable to locate public email for specified user, are they registered on this computer?");
     288                                return;
     289                        } else {
     290                                Text emailText = textItems.iterator().next();
     291                                String email = emailText.getText().replace("Email: ", "");
     292                                userData.put(AuthenticationTag.Email, email);
     293                                Password.generateAndDeliverIntergalacticNumber(userData);
     294                                MessageBay.displayMessage("A Intergalactic number has been sent to the email associated with your account.  Enter it below to proceed.");
     295                        }
     296                }
    261297        }
    262298       
     
    434470        }
    435471       
    436 //                      // establish properties
    437 //                      final String from = "[email protected]";
    438 //                      final Properties properties = System.getProperties();
    439 //                     
    440 //                      properties.setProperty("mail.transport.protocol", "smtp");
    441 //                      properties.setProperty("mail.smtp.host", "smtp.gmail.com");
    442 //                      properties.setProperty("mail.smtp.port", "465");
    443 //                      properties.setProperty("mail.smtp.starttls.enable", "true");
    444 //                      properties.setProperty("mail.smtp.auth", "true");
    445 //                      properties.setProperty("mail.smtp.debug", "true");
    446 //                      properties.setProperty("mail.smtp.auth", "true");
    447 //                      properties.setProperty("mail.smtp.socketFactory.port", "465");
    448 //                      properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    449 //                      properties.setProperty("mail.smtp.socketFactory.fallback", "false");
    450 //                     
    451 //                      final Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
    452 //                              @Override
    453 //                              protected PasswordAuthentication getPasswordAuthentication() {
    454 //                                      return new PasswordAuthentication("noreply.expeditee", "intergalacticnumber");
    455 //                              };
    456 //                      });
    457 
    458 //                              // construct email message
    459 //                              final MimeMessage message = new MimeMessage(session);
    460 //                              message.setFrom(new InternetAddress(from));
    461 //                              message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
    462 //                              message.setSubject("Expeditee Password Recovery");
    463 //                              message.setText(intergalacticNumber);
    464 //                             
    465 //                              // send email message
    466 //                              Transport.send(message);
    467 
    468 
    469472        public static void TickBox(final Text item) {
    470473                if (item.getBackgroundColor() != Colour.RED) {
  • trunk/src/org/expeditee/auth/account/Password.java

    r1336 r1340  
    88import java.sql.SQLException;
    99import java.util.Map;
     10import java.util.Properties;
    1011
    1112import javax.crypto.SecretKey;
     13import javax.mail.Message;
     14import javax.mail.MessagingException;
     15import javax.mail.PasswordAuthentication;
     16import javax.mail.Session;
     17import javax.mail.Transport;
     18import javax.mail.internet.InternetAddress;
     19import javax.mail.internet.MimeMessage;
    1220
    1321import org.expeditee.auth.AuthenticatorBrowser;
     
    3543                }
    3644        }
    37        
    38         public static void forgotPassword(Map<AuthenticationTag, String> userdata) {
    39                 String username = userdata.get(AuthenticationTag.Username);
    40                 String newpassword = userdata.get(AuthenticationTag.NewPassword);
    41                 //AuthenticatorBrowser.getInstance().putKey(label, password, key);
     45
     46        public static void generateAndDeliverIntergalacticNumber(Map<AuthenticationTag, String> userData) {
     47                String username = userData.get(AuthenticationTag.Username);
     48                String email = userData.get(AuthenticationTag.Email);
     49                try {
     50                        // Generate message text.
     51                        String intergalacticNumber = AuthenticatorBrowser.getInstance().newIntergalacticNumber(username, email);
     52                        String nl = System.getProperty("line.separator");
     53                        StringBuilder sb = new StringBuilder();
     54                        sb.append("You are receiving this email because someone is attempting to reset your Expeditee password." + nl);
     55                        sb.append("If you did not make this request then no action is required." + nl);
     56                        sb.append("If it was you who made this request, the following string of characters is your intergalactic number: " + intergalacticNumber + nl);
     57                       
     58                        // Establish properties for email.
     59                        Properties properties = System.getProperties();
     60                        properties.setProperty("mail.transport.protocol", "smtp");
     61                        properties.setProperty("mail.smtp.host", "smtp.gmail.com");
     62                        properties.setProperty("mail.smtp.port", "465");
     63                        properties.setProperty("mail.smtp.starttls.enable", "true");
     64                        properties.setProperty("mail.smtp.auth", "true");
     65                        properties.setProperty("mail.smtp.debug", "true");
     66                        properties.setProperty("mail.smtp.auth", "true");
     67                        properties.setProperty("mail.smtp.socketFactory.port", "465");
     68                        properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
     69                        properties.setProperty("mail.smtp.socketFactory.fallback", "false");
     70                       
     71                        Session session = Session.getDefaultInstance(properties, new javax.mail.Authenticator() {
     72                                @Override
     73                                protected PasswordAuthentication getPasswordAuthentication() {
     74                                        return new PasswordAuthentication("noreply.expeditee", "intergalacticnumber");
     75                                };
     76                        });
     77                       
     78                        // construct email message
     79                        final MimeMessage message = new MimeMessage(session);
     80                        message.setFrom(new InternetAddress("[email protected]"));
     81                        message.addRecipient(Message.RecipientType.TO, new InternetAddress(email));
     82                        message.setSubject("Expeditee Password Recovery");
     83                        message.setText(sb.toString());
     84                       
     85                        // send email message
     86                        Transport.send(message);               
     87                } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | ClassNotFoundException
     88                                | IOException | SQLException | MessagingException e) {
     89                        e.printStackTrace();
     90                }
    4291        }
    4392}
Note: See TracChangeset for help on using the changeset viewer.