bludit/admin/controllers/add-user.php

72 lines
2.0 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
// Check if the username already exist in db.
2015-07-22 05:15:02 +02:00
if( Text::isEmpty($args['username']) )
2015-05-05 03:00:01 +02:00
{
2015-07-22 05:15:02 +02:00
Alert::set($Language->g('username-field-is-empty'));
2015-08-03 02:49:12 +02:00
return false;
2015-07-22 05:15:02 +02:00
}
if( $dbUsers->userExists($args['username']) )
{
Alert::set($Language->g('username-already-exists'));
2015-05-05 03:00:01 +02:00
return false;
}
// Validate password.
2015-05-31 03:06:55 +02:00
if( ($args['password'] != $args['confirm-password'] ) || Text::isEmpty($args['password']) )
2015-05-05 03:00:01 +02:00
{
2015-07-22 05:15:02 +02:00
Alert::set($Language->g('The password and confirmation password do not match'));
2015-05-05 03:00:01 +02:00
return false;
}
// Add the user.
if( $dbUsers->add($args) )
{
2015-07-20 05:14:12 +02:00
Alert::set($Language->g('user-has-been-added-successfully'));
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
// ============================================================================