Guillermo - paths enable/disable registration[skip ci]

This commit is contained in:
AntonyAntonio 2017-01-10 16:04:25 -03:00
parent a317f6a29c
commit 397246aa4b
5 changed files with 85 additions and 1 deletions

View File

@ -28,9 +28,10 @@ class GetSettingsController extends Controller {
'smtp-port' => Setting::getSetting('smtp-port')->getValue(),
'smtp-host' => Setting::getSetting('smtp-port')->getValue(),
'smtp-user' => Setting::getSetting('smtp-port')->getValue(),
'registration' => Setting::getSetting('registration')->getValue(),
'departments' => Department::getDepartmentNames(),
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages()
'allowedLanguages' => Language::getAllowedLanguages(),
];
} else {
$settingsList = [
@ -42,6 +43,7 @@ class GetSettingsController extends Controller {
'allow-attachments' => Setting::getSetting('allow-attachments')->getValue(),
'max-size' => Setting::getSetting('max-size')->getValue(),
'title' => Setting::getSetting('title')->getValue(),
'registration' => Setting::getSetting('registration')->getValue(),
'departments' => Department::getDepartmentNames(),
'supportedLanguages' => Language::getSupportedLanguages(),
'allowedLanguages' => Language::getAllowedLanguages()

View File

@ -50,6 +50,10 @@ class SignUpController extends Controller {
Response::respondError(ERRORS::ALREADY_BANNED);
return;
}
if (!Setting::getSetting('registration')->value) {
Response::respondError(ERRORS::NO_PERMISSION);
return;
}
$userId = $this->createNewUserAndRetrieveId();
$this->sendRegistrationMail();

View File

@ -51,3 +51,5 @@ require './staff/last-events.rb'
require './system/get-mail-templates.rb'
require './system/edit-mail-template.rb'
require './system/recover-mail-template.rb'
require './system/disable-registration.rb'
require './system/enable-registration.rb'

View File

@ -0,0 +1,43 @@
describe'/system/disable-registration' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should not disable registration if password is not correct' do
result= request('/system/disable-registration', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password: 'hello'
})
(result['status']).should.equal('fail')
row = $database.getRow('setting', 'registration', 'name')
(row['value']).should.equal('1')
end
it 'should disable registration' do
result= request('/system/disable-registration', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password: $staff[:password]
})
(result['status']).should.equal('success')
row = $database.getRow('setting', 'registration', 'name')
(row['value']).should.equal('0')
end
it 'should not create user in database if registration is false' do
response = request('/user/signup', {
:name => 'ponzio',
:email => 'jc@ponziolandia.com',
:password => 'tequila'
})
(response['status']).should.equal('fail')
end
end

View File

@ -0,0 +1,33 @@
describe'/system/enable-registration' do
request('/user/logout')
Scripts.login($staff[:email], $staff[:password], true)
it 'should not enable registration if password is not correct' do
result= request('/system/enable-registration', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password: 'hello'
})
(result['status']).should.equal('fail')
row = $database.getRow('setting', 'registration', 'name')
(row['value']).should.equal('0')
end
it 'should enable registration' do
result= request('/system/enable-registration', {
csrf_userid: $csrf_userid,
csrf_token: $csrf_token,
password: $staff[:password]
})
(result['status']).should.equal('success')
row = $database.getRow('setting', 'registration', 'name')
(row['value']).should.equal('1')
end
end