-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
293 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/de/l3s/learnweb/user/EmailConfirmationBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.l3s.learnweb.user; | ||
|
||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
|
||
import jakarta.enterprise.context.RequestScoped; | ||
import jakarta.inject.Inject; | ||
import jakarta.mail.MessagingException; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import de.l3s.learnweb.app.Learnweb; | ||
import de.l3s.mail.Mail; | ||
import de.l3s.mail.MailFactory; | ||
import de.l3s.mail.MailService; | ||
import de.l3s.util.StringHelper; | ||
|
||
@RequestScoped | ||
public class EmailConfirmationBean implements Serializable { | ||
@Serial | ||
private static final long serialVersionUID = -1427221214029851844L; | ||
private static final Logger log = LogManager.getLogger(EmailConfirmationBean.class); | ||
|
||
@Inject | ||
private TokenDao tokenDao; | ||
|
||
@Inject | ||
private MailService mailService; | ||
|
||
/** | ||
* @return FALSE if an error occurred while sending this message | ||
*/ | ||
public boolean sendEmailConfirmation(User user) { | ||
try { | ||
String token = RandomStringUtils.secure().nextAlphanumeric(32); | ||
int tokenId = tokenDao.override(user.getId(), Token.TokenType.EMAIL_CONFIRMATION, token, LocalDateTime.now().plusYears(1)); | ||
|
||
String confirmEmailUrl = Learnweb.config().getServerUrl() + "/lw/user/confirm_email.jsf?" + | ||
"email=" + StringHelper.urlEncode(user.getEmail()) + "&token=" + tokenId + ":" + token; | ||
|
||
Mail mail = MailFactory.buildConfirmEmail(user.getUsername(), confirmEmailUrl).build(user.getLocale()); | ||
mail.addRecipient(user.getEmail()); | ||
mailService.send(mail); | ||
return true; | ||
} catch (MessagingException e) { | ||
log.error("Can't send confirmation mail to {}", this, e); | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.