(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/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');

View File

@ -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);

View File

@ -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 [

View File

@ -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'

View File

@ -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
})

View File

@ -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
})