Merge branch 'master' into captcha
This commit is contained in:
commit
5972427cf2
|
@ -8,6 +8,7 @@ class RecoverPasswordController extends Controller {
|
|||
private $email;
|
||||
private $token;
|
||||
private $password;
|
||||
private $user;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
|
@ -37,19 +38,31 @@ class RecoverPasswordController extends Controller {
|
|||
}
|
||||
public function changePassword() {
|
||||
$recoverPassword = RecoverPassword::getDataStore($this->token, 'token');
|
||||
$user = User::getDataStore($this->email, 'email');
|
||||
$this->user = User::getDataStore($this->email, 'email');
|
||||
|
||||
if (!$recoverPassword->isNull() && !$user->isNull()) {
|
||||
if (!$recoverPassword->isNull() && !$this->user->isNull()) {
|
||||
$recoverPassword->delete();
|
||||
|
||||
$user->setProperties([
|
||||
$this->user->setProperties([
|
||||
'password' => Hashing::hashPassword($this->password)
|
||||
]);
|
||||
|
||||
$user->store();
|
||||
$this->user->store();
|
||||
|
||||
$this->sendMail();
|
||||
Response::respondSuccess();
|
||||
} else {
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
}
|
||||
public function sendMail() {
|
||||
$mailSender = new MailSender();
|
||||
|
||||
$mailSender->setTemplate(MailTemplate::PASSWORD_RECOVERED, [
|
||||
'to' => $this->user->email,
|
||||
'name' => $this->user->name,
|
||||
]);
|
||||
|
||||
$mailSender->send();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@ DataValidator::with('CustomValidations', true);
|
|||
class SendRecoverPasswordController extends Controller {
|
||||
const PATH = '/send-recover-password';
|
||||
|
||||
private $token;
|
||||
private $user;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
|
@ -19,17 +22,36 @@ class SendRecoverPasswordController extends Controller {
|
|||
|
||||
public function handler() {
|
||||
$email = Controller::request('email');
|
||||
$this->user = User::getUser($email,'email');
|
||||
|
||||
$token = Hashing::generateRandomToken();
|
||||
if(!$this->user->isNull()) {
|
||||
$this->token = Hashing::generateRandomToken();
|
||||
|
||||
$recoverPassword = new RecoverPassword();
|
||||
$recoverPassword->setProperties(array(
|
||||
'email' => $email,
|
||||
'token' => $token
|
||||
'token' => $this->token
|
||||
));
|
||||
$recoverPassword->store();
|
||||
|
||||
$this->sendEmail();
|
||||
|
||||
Response::respondSuccess();
|
||||
//TODO: mandar mail con token
|
||||
} else {
|
||||
Response::respondError(ERRORS::INVALID_EMAIL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function sendEmail() {
|
||||
$mailSender = new MailSender();
|
||||
|
||||
$mailSender->setTemplate(MailTemplate::PASSWORD_FORGOT, [
|
||||
'to' => $this->user->email,
|
||||
'name' => $this->user->name,
|
||||
'token' => $this->token
|
||||
]);
|
||||
|
||||
$mailSender->send();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,27 @@ class InitialMails {
|
|||
'subject' => 'Tu correo electronico a sido cambiada - OpenSupports',
|
||||
'body' => file_get_contents('data/mail-templates/user-edit-email-es.html')
|
||||
]
|
||||
],
|
||||
'PASSWORD_FORGOT' => [
|
||||
'en' => [
|
||||
'subject' => 'forgotten password - OpenSupports',
|
||||
'body' => file_get_contents('data/mail-templates/user-password-forgot-en.html')
|
||||
],
|
||||
'es' => [
|
||||
'subject' => 'Contraseña olvidada - OpenSupports',
|
||||
'body' => file_get_contents('data/mail-templates/user-password-forgot-es.html')
|
||||
]
|
||||
],
|
||||
'PASSWORD_RECOVERED' => [
|
||||
'en' => [
|
||||
'subject' => 'Recover Password - OpenSupports',
|
||||
'body' => file_get_contents('data/mail-templates/user-recovered-password-en.html')
|
||||
],
|
||||
'es' => [
|
||||
'subject' => 'Recuperación de contraseña - OpenSupports',
|
||||
'body' => file_get_contents('data/mail-templates/user-recovered-password-es.html')
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
Hi {{name}} , for change your password you most put in this code {{token}}
|
||||
</div>
|
|
@ -0,0 +1,4 @@
|
|||
<div>
|
||||
Hola {{name}} , has requerido un cambio de contraseña
|
||||
Usa el siguiente codigo para confirmar tu cambio {{token}}
|
||||
</div>
|
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
Hi {{name}} , OpenSupports' team wanna inform you that you password has been chageed successfully.
|
||||
</div>
|
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
Hola {{name}} , el equipo de OpenSupports te informa que tu contraseña ha sido cambiada
|
||||
</div>
|
|
@ -6,6 +6,8 @@ class MailTemplate extends DataStore {
|
|||
|
||||
const USER_SIGNUP = 'USER_SIGNUP';
|
||||
const USER_PASSWORD = 'USER_PASSWORD';
|
||||
const PASSWORD_FORGOT = 'PASSWORD_FORGOT';
|
||||
const PASSWORD_RECOVERED = 'PASSWORD_RECOVERED';
|
||||
|
||||
public static function getTemplate($type) {
|
||||
$globalLanguage = Setting::getSetting('language')->value;
|
||||
|
|
Loading…
Reference in New Issue