(Guillermo) recover password

This commit is contained in:
AntonyAntonio 2016-07-22 04:44:55 -03:00
parent 9d378d07e5
commit dc3df30ef6
6 changed files with 25 additions and 30 deletions

View File

@ -2,8 +2,8 @@
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'; include 'user/recover-password.php';
include 'user/sendrecoverpassword.php'; include 'user/send-recover-password.php';
$userControllers = new ControllerGroup(); $userControllers = new ControllerGroup();
$userControllers->setGroupPath('/user'); $userControllers->setGroupPath('/user');

View File

@ -2,12 +2,11 @@
use Respect\Validation\Validator as DataValidator; use Respect\Validation\Validator as DataValidator;
class RecoverPasswordController extends Controller { class RecoverPasswordController extends Controller {
const PATH = '/recoverpassword'; const PATH = '/recover-password';
private $email; private $email;
private $token; private $token;
private $password; private $password;
private $recoverPassword;
public function validations() { public function validations() {
return [ return [
@ -36,14 +35,11 @@ class RecoverPasswordController extends Controller {
$this->password = Controller::request('password'); $this->password = Controller::request('password');
} }
public function changePassword(){ public function changePassword(){
if ($this->email && $this->token) { $recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
if($this->recoverPassword) {
$user = User::getDataStore($this->email, 'email'); $user = User::getDataStore($this->email, 'email');
if ($user) { if($recoverPassword && $user) {
$this->recoverPassword->trash(); $recoverPassword->trash();
$user->setProperties([ $user->setProperties([
'password' => Hashing::hashPassword($this->password) 'password' => Hashing::hashPassword($this->password)
@ -52,8 +48,7 @@ class RecoverPasswordController extends Controller {
$user->store(); $user->store();
Response::respondSuccess('password changed'); Response::respondSuccess('password changed');
return; return;
}
}
} }
Response::respondError(ERRORS::NO_PERMISSION); Response::respondError(ERRORS::NO_PERMISSION);

View File

@ -2,7 +2,7 @@
use Respect\Validation\Validator as DataValidator; use Respect\Validation\Validator as DataValidator;
class SendRecoverPasswordController extends Controller { class SendRecoverPasswordController extends Controller {
const PATH = '/sendrecoverpassword'; const PATH = '/send-recover-password';
public function validations() { public function validations() {
return [ return [

View File

@ -10,6 +10,6 @@ require './scripts.rb'
# TESTS # TESTS
require './user/signup.rb' require './user/signup.rb'
require './user/login.rb' require './user/login.rb'
require './user/sendrecoverpassword.rb' require './user/send-recover-password.rb'
require './user/recoverpassword.rb' require './user/recover-password.rb'
#require './ticket/create.rb' #require './ticket/create.rb'

View File

@ -1,16 +1,16 @@
describe '/user/recoverpassword' do describe '/user/recover-password' do
@recoverEmail = 'recover@os4.com' @recoverEmail = 'recover@os4.com'
@newRecoverPass = 'newrecover' @newRecoverPass = 'newrecover'
it 'should fail if email is incorrect' do it 'should fail if email is incorrect' do
result = request('/user/recoverpassword', { result = request('/user/recover-password', {
email: 'login@os4com', email: 'login@os4com',
password: @newRecoverPass password: @newRecoverPass
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail');
result = request('/user/recoverpassword', { result = request('/user/recover-password', {
email: 'loginos4.com', email: 'loginos4.com',
password: @newRecoverPass password: @newRecoverPass
}) })
@ -19,7 +19,7 @@ describe '/user/recoverpassword' do
end end
it 'should fail if password is incorrect' do it 'should fail if password is incorrect' do
result = request('/user/recoverpassword',{ result = request('/user/recover-password',{
email: @recoverEmail, email: @recoverEmail,
password: 'log' password: 'log'
}) })
@ -29,7 +29,7 @@ describe '/user/recoverpassword' do
long_text = '' long_text = ''
250.times {long_text << 'a'} 250.times {long_text << 'a'}
result = request('/user/recoverpassword',{ result = request('/user/recover-password',{
email: @recoverEmail, email: @recoverEmail,
password: long_text password: long_text
}) })

View File

@ -1,24 +1,24 @@
describe '/user/sendrecoverpassword' do describe '/user/send-recover-password' do
@recoverEmail = 'recover@os4.com' @recoverEmail = 'recover@os4.com'
@recoverPass = 'recover' @recoverPass = 'recover'
Scripts.createUser(@recoverEmail, @recoverPass) Scripts.createUser(@recoverEmail, @recoverPass)
it 'should fail if email is incorrect' do it 'should fail if email is incorrect' do
result = request('/user/sendrecoverpassword', { result = request('/user/send-recover-password', {
email: 'login@os4com' email: 'login@os4com'
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail');
result = request('/user/sendrecoverpassword', { result = request('/user/send-recover-password', {
email: 'loginos4.com' email: 'loginos4.com'
}) })
(result['status']).should.equal('fail'); (result['status']).should.equal('fail');
end end
it 'should success if email is correct' do it 'should success if email is correct' do
result = request('/user/sendrecoverpassword', { result = request('/user/send-recover-password', {
email: @recoverEmail email: @recoverEmail
}) })