I am developing a web application using the framework play 1.4 (didatica version) and I want to implement the password recovery functionality where the user will put his email and will be sent a temporary link to reset his password. My question, how to generate this temporary link send to p email filled in and validate the new password?
My official MODEL where ja add public String token; Date tokenValidityDate; which I know will be necessary: 'package models;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import play.data.validation.MinSize;
import play.data.validation.Required;
import play.db.jpa.Model;
import sun.util.calendar.BaseCalendar.Date;
@Entity
public class Funcionario extends Model {
final static String chave = "0123456789abcdef";
private static final String ALGORITMO = "AES";
private static byte[] mensagemEncriptada;
private static byte[] mensagemDescriptada;
private static SecretKey key;
public String nome;
public String funcao;
public String nivelAcesso;
public String login;
@MinSize(4)
public String senha;
public String email;
public String token;
Date tokenValidityDate;
@Enumerated(EnumType.STRING)
public Status status;
public Funcionario() {
status = Status.ATIVO;
}
public boolean autenticar() throws Exception {
Funcionario u = Funcionario.find("login = ? and senha = ?", login, descriptografar(senha)).first();
if (u == null) {
return false;
} else {
return true;
}
}
public static String descriptografar(String mensagem) throws Exception {
key = new SecretKeySpec(chave.getBytes(), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, key);
mensagemDescriptada = cipher.doFinal(mensagem.getBytes());
return StringUtils.trim(Base64.encodeBase64String(mensagemDescriptada));
}
}
' My html page to recover password:
<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
<meta charset="ISO-8859-1">
<link rel="stylesheet" media="screen" href="@{'/public/stylesheets/login.css'}">
<title>Octopus</title>
</head>
<body background="/public/images/back.png">
<form action="@{Logins.logar}" method="post">
<input type="hidden" name="login.id" value="${u?.id}" />
<div class="login">
<p><center><small>Digite seu endereço de e-mail para redefinir a senha.</small></center></p></small>
<input type="text" placeholder="E-mail" name="funcionario.email" value="${flash['funcionario.email'] ? flash['funcionario.email'] : u?.email}" >
<span class="bg-danger">#{error 'login.email' /}</span>
<input type="submit" value="Enviar">
</div>
<div class="shadow"></div>
</form>
</body>
</html>