mirror of
https://github.com/opensupports/opensupports.git
synced 2025-07-31 01:35:15 +02:00
Ivan - Add local storage class [skip ci]
This commit is contained in:
parent
d648aff2b3
commit
9d378d07e5
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
use RedBeanPHP\Facade as RedBean;
|
use RedBeanPHP\Facade as RedBean;
|
||||||
|
|
||||||
use Respect\Validation\Validator as DataValidator;
|
use Respect\Validation\Validator as DataValidator;
|
||||||
|
|
||||||
class CreateController extends Controller {
|
class CreateController extends Controller {
|
||||||
@ -54,10 +53,10 @@ class CreateController extends Controller {
|
|||||||
'unread' => false,
|
'unread' => false,
|
||||||
'closed' => false
|
'closed' => false
|
||||||
));
|
));
|
||||||
|
|
||||||
//TODO: Add logged user as author
|
//TODO: Add logged user as author
|
||||||
$ticket->setAuthor(User::getUser(1));
|
$ticket->setAuthor(User::getUser(1));
|
||||||
|
|
||||||
$ticket->store();
|
$ticket->store();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Respect\Validation\Validator as DataValidator;
|
||||||
|
|
||||||
class RecoverPasswordController extends Controller {
|
class RecoverPasswordController extends Controller {
|
||||||
const PATH = '/recoverpassword';
|
const PATH = '/recoverpassword';
|
||||||
@ -11,27 +12,50 @@ class RecoverPasswordController extends Controller {
|
|||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
return [
|
||||||
'permission' => 'any',
|
'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(){
|
public function handler(){
|
||||||
$this->email = Controller::request('email');
|
$this->requestData();
|
||||||
$this->token = Controller::request('token');
|
$this->changePassword();
|
||||||
$this->password = Controller::request('password');
|
}
|
||||||
|
|
||||||
|
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) {
|
if ($this->email && $this->token) {
|
||||||
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
$this->recoverPassword = RecoverPassword::getDatastore($this->token, 'token');
|
||||||
|
|
||||||
if($this->recoverPassword){
|
if($this->recoverPassword) {
|
||||||
// TODO: borar item en base de datos
|
$user = User::getDataStore($this->email, 'email');
|
||||||
$changePassword = 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
|
<?php
|
||||||
|
use Respect\Validation\Validator as DataValidator;
|
||||||
|
|
||||||
class SendRecoverPasswordController extends Controller {
|
class SendRecoverPasswordController extends Controller {
|
||||||
const PATH = '/sendrecoverpassword';
|
const PATH = '/sendrecoverpassword';
|
||||||
|
|
||||||
private $email;
|
|
||||||
private $token;
|
|
||||||
|
|
||||||
public function validations() {
|
public function validations() {
|
||||||
return [
|
return [
|
||||||
'permission' => 'any',
|
'permission' => 'any',
|
||||||
'requestData' => []
|
'requestData' => [
|
||||||
|
'email' => [
|
||||||
|
'validation' => DataValidator::email(),
|
||||||
|
'error' => ERRORS::INVALID_EMAIL
|
||||||
|
]
|
||||||
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handler() {
|
public function handler() {
|
||||||
$this->email = Controller::request('email');
|
$email = Controller::request('email');
|
||||||
|
|
||||||
if($this->email) {
|
$token = Hashing::generateRandomToken();
|
||||||
$this->token = Hashing::generateRandomToken();
|
|
||||||
|
|
||||||
$recoverPassword = new RecoverPassword();
|
$recoverPassword = new RecoverPassword();
|
||||||
|
$recoverPassword->setProperties(array(
|
||||||
|
'email' => $email,
|
||||||
|
'token' => $token
|
||||||
|
));
|
||||||
|
$recoverPassword->store();
|
||||||
|
|
||||||
$recoverPassword->setProperties(array(
|
Response::respondSuccess();
|
||||||
'email' => $this->email,
|
//TODO: mandar mail con token
|
||||||
'token' => $this->token
|
|
||||||
));
|
|
||||||
|
|
||||||
$recoverPassword->store();
|
|
||||||
Response::respondSuccess();
|
|
||||||
//TODO: mandar mail con token
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,4 +72,8 @@ abstract class DataStore {
|
|||||||
|
|
||||||
return ($validProp) ? $propToValidate : 'id';
|
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 INVALID_CREDENTIALS = 'User or password is not defined';
|
||||||
const SESSION_EXISTS = 'User is already logged in';
|
const SESSION_EXISTS = 'User is already logged in';
|
||||||
const NO_PERMISSION = 'You have no permission to access';
|
const NO_PERMISSION = 'You have no permission to access';
|
||||||
|
const INVALID_EMAIL = 'Invalid email';
|
||||||
const INVALID_TITLE = 'Invalid title';
|
const INVALID_TITLE = 'Invalid title';
|
||||||
const INVALID_CONTENT = 'Invalid content';
|
const INVALID_CONTENT = 'Invalid content';
|
||||||
|
const INVALID_PASSWORD = 'Invalid password';
|
||||||
}
|
}
|
||||||
|
@ -10,4 +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/recoverpassword.rb'
|
||||||
#require './ticket/create.rb'
|
#require './ticket/create.rb'
|
||||||
|
39
tests/user/recoverpassword.rb
Normal file
39
tests/user/recoverpassword.rb
Normal file
@ -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
|
27
tests/user/sendrecoverpassword.rb
Normal file
27
tests/user/sendrecoverpassword.rb
Normal file
@ -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…
x
Reference in New Issue
Block a user