Ivan - Add local storage class [skip ci]
This commit is contained in:
parent
d648aff2b3
commit
9d378d07e5
|
@ -1,6 +1,5 @@
|
|||
<?php
|
||||
use RedBeanPHP\Facade as RedBean;
|
||||
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class CreateController extends Controller {
|
||||
|
@ -54,10 +53,10 @@ class CreateController extends Controller {
|
|||
'unread' => false,
|
||||
'closed' => false
|
||||
));
|
||||
|
||||
|
||||
//TODO: Add logged user as author
|
||||
$ticket->setAuthor(User::getUser(1));
|
||||
|
||||
$ticket->store();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class RecoverPasswordController extends Controller {
|
||||
const PATH = '/recoverpassword';
|
||||
|
@ -11,27 +12,50 @@ class RecoverPasswordController extends Controller {
|
|||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
'requestData' => []
|
||||
'requestData' => [
|
||||
'email' => [
|
||||
'validation' => DataValidator::email() ,
|
||||
'error' => ERRORS::INVALID_EMAIL
|
||||
],
|
||||
'password' => [
|
||||
'validation' => DataValidator::length(5, 200),
|
||||
'error' => ERRORS::INVALID_PASSWORD
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler(){
|
||||
$this->email = Controller::request('email');
|
||||
$this->token = Controller::request('token');
|
||||
$this->password = Controller::request('password');
|
||||
$this->requestData();
|
||||
$this->changePassword();
|
||||
}
|
||||
|
||||
public function requestData(){
|
||||
$this->email = Controller::request('email');
|
||||
$this->token = Controller::request('token');
|
||||
$this->password = Controller::request('password');
|
||||
}
|
||||
public function changePassword(){
|
||||
if ($this->email && $this->token) {
|
||||
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
||||
|
||||
if($this->recoverPassword){
|
||||
// TODO: borar item en base de datos
|
||||
$changePassword = User::getDataStore($this->email, 'email');
|
||||
if($this->recoverPassword) {
|
||||
$user = User::getDataStore($this->email, 'email');
|
||||
|
||||
$changePassword->password = $this->password;
|
||||
if ($user) {
|
||||
$this->recoverPassword->trash();
|
||||
|
||||
Response::respondSuccess('password changed');
|
||||
$user->setProperties([
|
||||
'password' => Hashing::hashPassword($this->password)
|
||||
]);
|
||||
|
||||
$user->store();
|
||||
Response::respondSuccess('password changed');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}else {
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
Response::respondError(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +1,34 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
class SendRecoverPasswordController extends Controller {
|
||||
const PATH = '/sendrecoverpassword';
|
||||
|
||||
private $email;
|
||||
private $token;
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
'requestData' => []
|
||||
'requestData' => [
|
||||
'email' => [
|
||||
'validation' => DataValidator::email(),
|
||||
'error' => ERRORS::INVALID_EMAIL
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$this->email = Controller::request('email');
|
||||
$email = Controller::request('email');
|
||||
|
||||
if($this->email) {
|
||||
$this->token = Hashing::generateRandomToken();
|
||||
$token = Hashing::generateRandomToken();
|
||||
|
||||
$recoverPassword = new RecoverPassword();
|
||||
$recoverPassword = new RecoverPassword();
|
||||
$recoverPassword->setProperties(array(
|
||||
'email' => $email,
|
||||
'token' => $token
|
||||
));
|
||||
$recoverPassword->store();
|
||||
|
||||
$recoverPassword->setProperties(array(
|
||||
'email' => $this->email,
|
||||
'token' => $this->token
|
||||
));
|
||||
|
||||
$recoverPassword->store();
|
||||
Response::respondSuccess();
|
||||
//TODO: mandar mail con token
|
||||
|
||||
}
|
||||
Response::respondSuccess();
|
||||
//TODO: mandar mail con token
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,4 +72,8 @@ abstract class DataStore {
|
|||
|
||||
return ($validProp) ? $propToValidate : 'id';
|
||||
}
|
||||
|
||||
public function trash() {
|
||||
RedBean::trash($this->_bean);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ class ERRORS {
|
|||
const INVALID_CREDENTIALS = 'User or password is not defined';
|
||||
const SESSION_EXISTS = 'User is already logged in';
|
||||
const NO_PERMISSION = 'You have no permission to access';
|
||||
const INVALID_EMAIL = 'Invalid email';
|
||||
const INVALID_TITLE = 'Invalid title';
|
||||
const INVALID_CONTENT = 'Invalid content';
|
||||
const INVALID_PASSWORD = 'Invalid password';
|
||||
}
|
||||
|
|
|
@ -10,4 +10,6 @@ require './scripts.rb'
|
|||
# TESTS
|
||||
require './user/signup.rb'
|
||||
require './user/login.rb'
|
||||
require './user/sendrecoverpassword.rb'
|
||||
require './user/recoverpassword.rb'
|
||||
#require './ticket/create.rb'
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
describe '/user/recoverpassword' do
|
||||
@recoverEmail = 'recover@os4.com'
|
||||
@newRecoverPass = 'newrecover'
|
||||
|
||||
it 'should fail if email is incorrect' do
|
||||
result = request('/user/recoverpassword', {
|
||||
email: 'login@os4com',
|
||||
password: @newRecoverPass
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
|
||||
result = request('/user/recoverpassword', {
|
||||
email: 'loginos4.com',
|
||||
password: @newRecoverPass
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
end
|
||||
|
||||
it 'should fail if password is incorrect' do
|
||||
result = request('/user/recoverpassword',{
|
||||
email: @recoverEmail,
|
||||
password: 'log'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
|
||||
long_text = ''
|
||||
250.times {long_text << 'a'}
|
||||
|
||||
result = request('/user/recoverpassword',{
|
||||
email: @recoverEmail,
|
||||
password: long_text
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
describe '/user/sendrecoverpassword' do
|
||||
@recoverEmail = 'recover@os4.com'
|
||||
@recoverPass = 'recover'
|
||||
|
||||
Scripts.createUser(@recoverEmail, @recoverPass)
|
||||
|
||||
it 'should fail if email is incorrect' do
|
||||
result = request('/user/sendrecoverpassword', {
|
||||
email: 'login@os4com'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
|
||||
result = request('/user/sendrecoverpassword', {
|
||||
email: 'loginos4.com'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail');
|
||||
end
|
||||
it 'should success if email is correct' do
|
||||
result = request('/user/sendrecoverpassword', {
|
||||
email: @recoverEmail
|
||||
})
|
||||
|
||||
(result['status']).should.equal('success')
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue