mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Ivan - Add local storage class [skip ci]
This commit is contained in:
parent
8b8ac11b97
commit
d648aff2b3
@ -3,6 +3,7 @@ include 'user/login.php';
|
|||||||
include 'user/signup.php';
|
include 'user/signup.php';
|
||||||
include 'user/logout.php';
|
include 'user/logout.php';
|
||||||
include 'user/recoverpassword.php';
|
include 'user/recoverpassword.php';
|
||||||
|
include 'user/sendrecoverpassword.php';
|
||||||
|
|
||||||
$userControllers = new ControllerGroup();
|
$userControllers = new ControllerGroup();
|
||||||
$userControllers->setGroupPath('/user');
|
$userControllers->setGroupPath('/user');
|
||||||
@ -10,6 +11,7 @@ $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 SendRecoverPasswordController);
|
||||||
$userControllers->addController(new RecoverPasswordController);
|
$userControllers->addController(new RecoverPasswordController);
|
||||||
|
|
||||||
$userControllers->finalize();
|
$userControllers->finalize();
|
||||||
|
@ -19,33 +19,19 @@ class RecoverPasswordController extends Controller {
|
|||||||
$this->email = Controller::request('email');
|
$this->email = Controller::request('email');
|
||||||
$this->token = Controller::request('token');
|
$this->token = Controller::request('token');
|
||||||
$this->password = Controller::request('password');
|
$this->password = Controller::request('password');
|
||||||
|
if ($this->email && $this->token) {
|
||||||
|
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
||||||
|
|
||||||
if($this->email && $this->token === null ) {
|
if($this->recoverPassword){
|
||||||
$this->token = Hashing::generateRandomToken();
|
// TODO: borar item en base de datos
|
||||||
|
|
||||||
$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 = User::getDataStore($this->email, 'email');
|
||||||
|
|
||||||
$changePassword->password = $this->password;
|
$changePassword->password = $this->password;
|
||||||
|
|
||||||
Response::respondSuccess($changePassword->password);
|
Response::respondSuccess('password changed');
|
||||||
}
|
}
|
||||||
|
|
||||||
}else {
|
}else {
|
||||||
Response::respondError(ERRORS::INVALID_CREDENTIALS);
|
Response::respondError(ERRORS::NO_PERMISSION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
35
server/controllers/user/sendrecoverpassword.php
Normal file
35
server/controllers/user/sendrecoverpassword.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class SendRecoverPasswordController extends Controller {
|
||||||
|
const PATH = '/sendrecoverpassword';
|
||||||
|
|
||||||
|
private $email;
|
||||||
|
private $token;
|
||||||
|
|
||||||
|
public function validations() {
|
||||||
|
return [
|
||||||
|
'permission' => 'any',
|
||||||
|
'requestData' => []
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handler() {
|
||||||
|
$this->email = Controller::request('email');
|
||||||
|
|
||||||
|
if($this->email) {
|
||||||
|
$this->token = Hashing::generateRandomToken();
|
||||||
|
|
||||||
|
$recoverPassword = new RecoverPassword();
|
||||||
|
|
||||||
|
$recoverPassword->setProperties(array(
|
||||||
|
'email' => $this->email,
|
||||||
|
'token' => $this->token
|
||||||
|
));
|
||||||
|
|
||||||
|
$recoverPassword->store();
|
||||||
|
Response::respondSuccess();
|
||||||
|
//TODO: mandar mail con token
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user