(Guillermo) recover password
This commit is contained in:
parent
9d378d07e5
commit
dc3df30ef6
|
@ -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');
|
||||
|
|
|
@ -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,14 +35,11 @@ class RecoverPasswordController extends Controller {
|
|||
$this->password = Controller::request('password');
|
||||
}
|
||||
public function changePassword(){
|
||||
if ($this->email && $this->token) {
|
||||
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
||||
|
||||
if($this->recoverPassword) {
|
||||
$recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
||||
$user = User::getDataStore($this->email, 'email');
|
||||
|
||||
if ($user) {
|
||||
$this->recoverPassword->trash();
|
||||
if($recoverPassword && $user) {
|
||||
$recoverPassword->trash();
|
||||
|
||||
$user->setProperties([
|
||||
'password' => Hashing::hashPassword($this->password)
|
||||
|
@ -52,8 +48,7 @@ class RecoverPasswordController extends Controller {
|
|||
$user->store();
|
||||
Response::respondSuccess('password changed');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
|
|
|
@ -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 [
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue