(Guillermo) recover password
This commit is contained in:
parent
0c27a96113
commit
8b8ac11b97
|
@ -2,6 +2,7 @@
|
|||
include 'user/login.php';
|
||||
include 'user/signup.php';
|
||||
include 'user/logout.php';
|
||||
include 'user/recoverpassword.php';
|
||||
|
||||
$userControllers = new ControllerGroup();
|
||||
$userControllers->setGroupPath('/user');
|
||||
|
@ -9,5 +10,6 @@ $userControllers->setGroupPath('/user');
|
|||
$userControllers->addController(new LoginController);
|
||||
$userControllers->addController(new SignUpController);
|
||||
$userControllers->addController(new LogoutController);
|
||||
$userControllers->addController(new RecoverPasswordController);
|
||||
|
||||
$userControllers->finalize();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue