From 8b8ac11b9745af467835a2b92213ed70fcfccd39 Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Wed, 20 Jul 2016 01:38:34 -0300 Subject: [PATCH] (Guillermo) recover password --- server/controllers/user.php | 2 + server/controllers/user/recoverpassword.php | 51 +++++++++++++++++++++ server/models/RecoverPassword.php | 15 ++++++ 3 files changed, 68 insertions(+) create mode 100644 server/controllers/user/recoverpassword.php create mode 100644 server/models/RecoverPassword.php diff --git a/server/controllers/user.php b/server/controllers/user.php index 7ad1054c..5eb5694e 100644 --- a/server/controllers/user.php +++ b/server/controllers/user.php @@ -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(); diff --git a/server/controllers/user/recoverpassword.php b/server/controllers/user/recoverpassword.php new file mode 100644 index 00000000..ffcc915b --- /dev/null +++ b/server/controllers/user/recoverpassword.php @@ -0,0 +1,51 @@ + '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); + } + } +} \ No newline at end of file diff --git a/server/models/RecoverPassword.php b/server/models/RecoverPassword.php new file mode 100644 index 00000000..1cf15f1b --- /dev/null +++ b/server/models/RecoverPassword.php @@ -0,0 +1,15 @@ +