(Guillermo) recover password

This commit is contained in:
AntonyAntonio 2016-07-20 01:38:34 -03:00
parent 0c27a96113
commit 8b8ac11b97
3 changed files with 68 additions and 0 deletions

View File

@ -2,6 +2,7 @@
include 'user/login.php'; include 'user/login.php';
include 'user/signup.php'; include 'user/signup.php';
include 'user/logout.php'; include 'user/logout.php';
include 'user/recoverpassword.php';
$userControllers = new ControllerGroup(); $userControllers = new ControllerGroup();
$userControllers->setGroupPath('/user'); $userControllers->setGroupPath('/user');
@ -9,5 +10,6 @@ $userControllers->setGroupPath('/user');
$userControllers->addController(new LoginController); $userControllers->addController(new LoginController);
$userControllers->addController(new SignUpController); $userControllers->addController(new SignUpController);
$userControllers->addController(new LogoutController); $userControllers->addController(new LogoutController);
$userControllers->addController(new RecoverPasswordController);
$userControllers->finalize(); $userControllers->finalize();

View File

@ -0,0 +1,51 @@
<?php
class RecoverPasswordController extends Controller {
const PATH = '/recoverpassword';
private $email;
private $token;
private $password;
private $recoverPassword;
public function validations() {
return [
'permission' => 'any',
'requestData' => []
];
}
public function handler() {
$this->email = Controller::request('email');
$this->token = Controller::request('token');
$this->password = Controller::request('password');
if($this->email && $this->token === null ) {
$this->token = Hashing::generateRandomToken();
$this->recoverPassword = new RecoverPassword();
$this->recoverPassword->setProperties(array(
'email' => $this->email,
'token' => $this->token
));
$this->recoverPassword->store();
Response::respondSuccess($this->token);
/*mandar mail con token*/
} else if ($this->email && $this->token) {
if($this->recoverPassword->token === $this->token){
/*borrar base de datos */
$changePassword = User::getDataStore($this->email, 'email');
$changePassword->password = $this->password;
Response::respondSuccess($changePassword->password);
}
} else {
Response::respondError(ERRORS::INVALID_CREDENTIALS);
}
}
}

View File

@ -0,0 +1,15 @@
<?php
class RecoverPassword extends DataStore {
const TABLE = 'recoverpassword';
public static function getProps() {
return array (
'email',
'token'
);
}
public function getDefaultProps() {
return array();
}
}