Skip to content

Commit

Permalink
[kbss-cvut/termit-ui#332] Add missing validity to password reset mail.
Browse files Browse the repository at this point in the history
  • Loading branch information
ledsoft committed Jul 19, 2024
1 parent 507e916 commit 182e388
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import cz.cvut.kbss.termit.service.mail.MessageComposer;
import cz.cvut.kbss.termit.service.mail.Postman;
import cz.cvut.kbss.termit.util.Configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.util.UriComponentsBuilder;

Expand All @@ -18,25 +17,22 @@
public class PasswordChangeNotifier {
private static final String PASSWORD_RESET_TEMPLATE = "password-change.vm";

private final String baseUrl;
private final String language;
private final Configuration config;
private final MessageComposer messageComposer;
private final Postman postman;

@Autowired
public PasswordChangeNotifier(Configuration configuration, MessageComposer messageComposer, Postman postman) {
this.baseUrl = configuration.getUrl();
this.language = configuration.getPersistence().getLanguage();
this.config = configuration;
this.messageComposer = messageComposer;
this.postman = postman;
}

private String buildResetLink(PasswordChangeRequest request) {
return UriComponentsBuilder.fromHttpUrl(baseUrl)
.fragment(
"/reset-password/"+
request.getToken()+"/"+
URLEncoder.encode(request.getUri().toString(), StandardCharsets.UTF_8)
return UriComponentsBuilder.fromHttpUrl(config.getUrl())
.fragment("/reset-password/" +
request.getToken() + "/" +
URLEncoder.encode(request.getUri().toString(),
StandardCharsets.UTF_8)
).toUriString();
}

Expand All @@ -49,11 +45,13 @@ private String buildResetLink(PasswordChangeRequest request) {
private Message createMessage(PasswordChangeRequest request) {
Map<String, Object> variables = Map.of(
"resetLink", buildResetLink(request),
"username", request.getUserAccount().getUsername()
"username", request.getUserAccount().getUsername(),
"validity", config.getSecurity().getPasswordChangeRequestValidity()
);
return Message.to(request.getUserAccount().getUsername())
.content(messageComposer.composeMessage(PASSWORD_RESET_TEMPLATE, variables))
.subject(new MessageFormatter(language).formatMessage("password-change.email.subject"))
.subject(new MessageFormatter(config.getPersistence().getLanguage()).formatMessage(
"password-change.email.subject"))
.build();
}

Expand Down

0 comments on commit 182e388

Please sign in to comment.