Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK-464 - Login - Forgot Password option #2439

Merged
merged 13 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public OpenCGAResult resetPassword(String userId) throws CatalogException {
String mailHost = this.emailConfig.getHost();
String mailPort = this.emailConfig.getPort();
try {
MailUtils.sendResetPasswordMail(email, newPassword, mailUser, mailPassword, mailHost, mailPort);
MailUtils.sendResetPasswordMail(email, newPassword, mailUser, mailPassword, mailHost, mailPort, userId);
result = userDBAdaptor.resetPassword(userId, email, newPassword);
} catch (Exception e) {
throw new CatalogException("Email could not be sent.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.opencb.opencga.core.common;

import org.opencb.opencga.core.models.user.User;
import org.opencb.opencga.core.response.OpenCGAResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -32,20 +34,21 @@ public class MailUtils {

private static final Logger logger = LoggerFactory.getLogger(MailUtils.class);

public static void sendResetPasswordMail(String to, String newPassword, final String mailUser, final String mailPassword,
String mailHost, String mailPort) throws Exception {
sendResetPasswordMail(to, newPassword, mailUser, mailPassword,
mailHost, mailPort, "true");
}


public static void sendResetPasswordMail(String to, String newPassword, final String mailUser, final String mailPassword,
String mailHost, String mailPort, String ssl) throws Exception {
String mailHost, String mailPort, String userId) throws Exception {

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", ssl);
props.put("mail.smtp.host", mailHost);
props.put("mail.smtp.port", mailPort);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.starttls.required", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
props.put("mail.smtp.ssl.checkserveridentity", "true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
pfurio marked this conversation as resolved.
Show resolved Hide resolved
pfurio marked this conversation as resolved.
Show resolved Hide resolved

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
Expand All @@ -59,20 +62,31 @@ protected PasswordAuthentication getPasswordAuthentication() {
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));

message.setSubject("Your password has been reset");
message.setText("Hello, \n" +
"You can now login using this new password:" +
"\n\n" +
newPassword +
"\n\n\n" +
"Please change it when you first login" +
"\n\n" +
"Best regards,\n\n" +
"Systems Genomics Laboratory" +
"\n");
message.setSubject("XetaBase: Password Reset");
message.setText(getEmailContent(userId,newPassword));
Transport.send(message);
}

public static String getEmailContent(String userId, String temporaryPassword) {
StringBuilder sb = new StringBuilder();

sb.append("Hi ").append(userId).append(",\n\n");
sb.append("We confirm that your password has been successfully reset.\n\n");
sb.append("Please find your new login credentials below:\n\n");
sb.append("User ID: ").append(userId).append("\n");
sb.append("Temporary Password: ").append(temporaryPassword).append("\n\n");
sb.append("For your security, we strongly recommend that you log in using the temporary password provided ");
sb.append("and promptly create a new password that is unique and known only to you. ");
sb.append("You can change your password by accessing \"Your Profile > Change Password\" in your User Profile.\n\n");
sb.append("If you did not request a password reset, please contact our support team immediately at [email protected].\n\n");
sb.append("Best regards,\n\n");
sb.append("ZettaGenomics Support Team \n\n");



return sb.toString();
}

public static void sendMail(String smtpServer, String to, String from, String subject, String body) throws Exception {

Properties props = System.getProperties();
Expand Down
Loading