* Validate a email.
*
* @return email page with flash error or success
*/
public static Result validateEmail(String token) {
User user = User.findByEmail(request().username());
if (token == null) {
flash("error", Messages.get("error.technical"));
return badRequest(emailValidate.render(user));
}
Token resetToken = Token.findByTokenAndType(token, Token.TypeToken.email);
if (resetToken == null) {
flash("error", Messages.get("error.technical"));
return badRequest(emailValidate.render(user));
}
if (resetToken.isExpired()) {
resetToken.delete();
flash("error", Messages.get("error.expiredmaillink"));
return badRequest(emailValidate.render(user));
}
user.email = resetToken.email;
user.save();
session("email", resetToken.email);
flash("success", Messages.get("account.settings.email.successful", user.email));