From dc3df30ef66eb7c53731bdf8392a9dd3c664271a Mon Sep 17 00:00:00 2001 From: AntonyAntonio Date: Fri, 22 Jul 2016 04:44:55 -0300 Subject: [PATCH] (Guillermo) recover password --- server/controllers/user.php | 4 +-- server/controllers/user/recoverpassword.php | 27 ++++++++----------- .../controllers/user/sendrecoverpassword.php | 2 +- tests/init.rb | 4 +-- tests/user/recoverpassword.rb | 10 +++---- tests/user/sendrecoverpassword.rb | 8 +++--- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/server/controllers/user.php b/server/controllers/user.php index af0e15ef..f096bb08 100644 --- a/server/controllers/user.php +++ b/server/controllers/user.php @@ -2,8 +2,8 @@ include 'user/login.php'; include 'user/signup.php'; include 'user/logout.php'; -include 'user/recoverpassword.php'; -include 'user/sendrecoverpassword.php'; +include 'user/recover-password.php'; +include 'user/send-recover-password.php'; $userControllers = new ControllerGroup(); $userControllers->setGroupPath('/user'); diff --git a/server/controllers/user/recoverpassword.php b/server/controllers/user/recoverpassword.php index 8e264d94..519968c8 100644 --- a/server/controllers/user/recoverpassword.php +++ b/server/controllers/user/recoverpassword.php @@ -2,12 +2,11 @@ use Respect\Validation\Validator as DataValidator; class RecoverPasswordController extends Controller { - const PATH = '/recoverpassword'; + const PATH = '/recover-password'; private $email; private $token; private $password; - private $recoverPassword; public function validations() { return [ @@ -36,24 +35,20 @@ class RecoverPasswordController extends Controller { $this->password = Controller::request('password'); } public function changePassword(){ - if ($this->email && $this->token) { - $this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token'); + $recoverPassword = RecoverPassword::getDatastore($this->token, 'token'); + $user = User::getDataStore($this->email, 'email'); - if($this->recoverPassword) { - $user = User::getDataStore($this->email, 'email'); + if($recoverPassword && $user) { + $recoverPassword->trash(); - if ($user) { - $this->recoverPassword->trash(); + $user->setProperties([ + 'password' => Hashing::hashPassword($this->password) + ]); - $user->setProperties([ - 'password' => Hashing::hashPassword($this->password) - ]); + $user->store(); + Response::respondSuccess('password changed'); + return; - $user->store(); - Response::respondSuccess('password changed'); - return; - } - } } Response::respondError(ERRORS::NO_PERMISSION); diff --git a/server/controllers/user/sendrecoverpassword.php b/server/controllers/user/sendrecoverpassword.php index 46a7c8ba..e8355f74 100644 --- a/server/controllers/user/sendrecoverpassword.php +++ b/server/controllers/user/sendrecoverpassword.php @@ -2,7 +2,7 @@ use Respect\Validation\Validator as DataValidator; class SendRecoverPasswordController extends Controller { - const PATH = '/sendrecoverpassword'; + const PATH = '/send-recover-password'; public function validations() { return [ diff --git a/tests/init.rb b/tests/init.rb index 464b6615..9a3a25e6 100644 --- a/tests/init.rb +++ b/tests/init.rb @@ -10,6 +10,6 @@ require './scripts.rb' # TESTS require './user/signup.rb' require './user/login.rb' -require './user/sendrecoverpassword.rb' -require './user/recoverpassword.rb' +require './user/send-recover-password.rb' +require './user/recover-password.rb' #require './ticket/create.rb' diff --git a/tests/user/recoverpassword.rb b/tests/user/recoverpassword.rb index f689daa2..7b00949f 100644 --- a/tests/user/recoverpassword.rb +++ b/tests/user/recoverpassword.rb @@ -1,16 +1,16 @@ -describe '/user/recoverpassword' do +describe '/user/recover-password' do @recoverEmail = 'recover@os4.com' @newRecoverPass = 'newrecover' it 'should fail if email is incorrect' do - result = request('/user/recoverpassword', { + result = request('/user/recover-password', { email: 'login@os4com', password: @newRecoverPass }) (result['status']).should.equal('fail'); - result = request('/user/recoverpassword', { + result = request('/user/recover-password', { email: 'loginos4.com', password: @newRecoverPass }) @@ -19,7 +19,7 @@ describe '/user/recoverpassword' do end it 'should fail if password is incorrect' do - result = request('/user/recoverpassword',{ + result = request('/user/recover-password',{ email: @recoverEmail, password: 'log' }) @@ -29,7 +29,7 @@ describe '/user/recoverpassword' do long_text = '' 250.times {long_text << 'a'} - result = request('/user/recoverpassword',{ + result = request('/user/recover-password',{ email: @recoverEmail, password: long_text }) diff --git a/tests/user/sendrecoverpassword.rb b/tests/user/sendrecoverpassword.rb index 6ec63697..4295fd49 100644 --- a/tests/user/sendrecoverpassword.rb +++ b/tests/user/sendrecoverpassword.rb @@ -1,24 +1,24 @@ -describe '/user/sendrecoverpassword' do +describe '/user/send-recover-password' do @recoverEmail = 'recover@os4.com' @recoverPass = 'recover' Scripts.createUser(@recoverEmail, @recoverPass) it 'should fail if email is incorrect' do - result = request('/user/sendrecoverpassword', { + result = request('/user/send-recover-password', { email: 'login@os4com' }) (result['status']).should.equal('fail'); - result = request('/user/sendrecoverpassword', { + result = request('/user/send-recover-password', { email: 'loginos4.com' }) (result['status']).should.equal('fail'); end it 'should success if email is correct' do - result = request('/user/sendrecoverpassword', { + result = request('/user/send-recover-password', { email: @recoverEmail })