bludit/bl-kernel/admin/controllers/add-user.php

86 lines
2.4 KiB
PHP
Raw Normal View History

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
// ============================================================================
function addUser($args)
{
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
if( Text::isEmpty($args['new_username']) )
2015-05-05 03:00:01 +02:00
{
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
if( $dbUsers->userExists($args['new_username']) )
2015-07-22 05:15:02 +02:00
{
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
if( strlen($args['new_password']) < 6 )
2015-05-05 03:00:01 +02:00
{
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
if( $args['new_password'] != $args['confirm_password'] )
2015-05-05 03:00:01 +02:00
{
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'];
// Add the user to the database
if( $dbUsers->add($tmp) )
{
Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
2015-05-05 03:00:01 +02:00
return true;
}
else
{
2015-07-22 05:15:02 +02:00
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the account.');
2015-05-05 03:00:01 +02:00
return false;
}
}
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) ) {
Redirect::page('admin', 'users');
}
}
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
// ============================================================================