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 4 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,8 @@ 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,
"true", ((User) user.getResults().get(0)).getId());
pfurio marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcoded ssl = "true" should be in the configuration file. And should be a boolean instead of String.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the variables that are set in the code and are not in the configuration are necessary for the current version to work..... The objective of this task was to change the body of the email message. In the tests I discovered that it did not work with the current configuration, I have added those properties to make it work, if you want to bring that to the configuration it must be done in another requirement, which must be planned for the corresponding version because this must be released now.

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 @@ -33,20 +35,17 @@
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 ssl, String user_id) throws Exception {
pfurio marked this conversation as resolved.
Show resolved Hide resolved

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", ssl);
props.put("mail.smtp.ssl.enable", ssl);
props.put("mail.smtp.host", mailHost);
props.put("mail.smtp.port", mailPort);

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.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
pfurio marked this conversation as resolved.
Show resolved Hide resolved
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
Expand All @@ -59,20 +58,35 @@
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(user_id,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");
sb.append("*This email and any attachments are confidential and may contain privileged information " +
"intended solely for the use of the individual or entity to whom they are addressed. " +
"If you have received this email in error, please notify the sender immediately and delete the email" +
" and any attachments from your system. Any unauthorized use, disclosure, distribution, " +
"or copying of this email or its attachments is strictly prohibited.*");


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