2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Check role
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
if($Login->role()!=='admin') {
|
2015-07-20 05:14:12 +02:00
|
|
|
Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
|
2015-05-15 00:07:45 +02:00
|
|
|
Redirect::page('admin', 'dashboard');
|
|
|
|
}
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Functions
|
|
|
|
// ============================================================================
|
|
|
|
|
2017-06-05 22:36:09 +02:00
|
|
|
function addUser($args) {
|
2015-05-05 03:00:01 +02:00
|
|
|
global $dbUsers;
|
2015-07-20 05:14:12 +02:00
|
|
|
global $Language;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-11-07 01:23:50 +01:00
|
|
|
// Check empty username
|
2017-06-05 22:36:09 +02:00
|
|
|
if( Text::isEmpty($args['new_username']) ) {
|
2015-11-07 01:23:50 +01:00
|
|
|
Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
|
2015-08-03 02:49:12 +02:00
|
|
|
return false;
|
2015-07-22 05:15:02 +02:00
|
|
|
}
|
|
|
|
|
2015-11-07 01:23:50 +01:00
|
|
|
// Check already exist username
|
2017-06-05 22:36:09 +02:00
|
|
|
if( $dbUsers->userExists($args['new_username']) ) {
|
2015-11-07 01:23:50 +01:00
|
|
|
Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
|
2015-05-05 03:00:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:23:50 +01:00
|
|
|
// Password length
|
2017-06-05 22:36:09 +02:00
|
|
|
if( strlen($args['new_password']) < 6 ) {
|
2015-11-07 01:23:50 +01:00
|
|
|
Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
|
2015-05-05 03:00:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:23:50 +01:00
|
|
|
// Check new password and confirm password are equal
|
2017-06-05 22:36:09 +02:00
|
|
|
if( $args['new_password'] != $args['confirm_password'] ) {
|
2015-11-07 01:23:50 +01:00
|
|
|
Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter form fields
|
|
|
|
$tmp = array();
|
|
|
|
$tmp['username'] = $args['new_username'];
|
|
|
|
$tmp['password'] = $args['new_password'];
|
|
|
|
$tmp['role'] = $args['role'];
|
2017-05-05 20:14:27 +02:00
|
|
|
$tmp['email'] = $args['email'];
|
2015-11-07 01:23:50 +01:00
|
|
|
|
|
|
|
// Add the user to the database
|
2017-06-05 22:36:09 +02:00
|
|
|
if( $dbUsers->add($tmp) ) {
|
|
|
|
// Add to syslog
|
|
|
|
$Syslog->add(array(
|
|
|
|
'dictionaryKey'=>'new-user',
|
|
|
|
'notes'=>$tmp['username']
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2015-11-07 01:23:50 +01:00
|
|
|
Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
|
2015-05-05 03:00:01 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-06-05 22:36:09 +02:00
|
|
|
|
|
|
|
return false;
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 02:49:12 +02:00
|
|
|
// ============================================================================
|
|
|
|
// Main before POST
|
|
|
|
// ============================================================================
|
|
|
|
|
2015-05-05 03:00:01 +02:00
|
|
|
// ============================================================================
|
|
|
|
// POST Method
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
|
|
|
{
|
|
|
|
if( addUser($_POST) ) {
|
2017-06-05 22:36:09 +02:00
|
|
|
Redirect::page('users');
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
|
|
|
}
|
2015-05-15 00:07:45 +02:00
|
|
|
|
|
|
|
// ============================================================================
|
2015-08-03 02:49:12 +02:00
|
|
|
// Main after POST
|
2015-05-15 00:07:45 +02:00
|
|
|
// ============================================================================
|