bludit/admin/controllers/add-user.php

72 lines
2.0 KiB
PHP
Raw Normal View History

2015-05-05 01:00:01 +00:00
<?php defined('BLUDIT') or die('Bludit CMS.');
2015-05-14 22:07:45 +00:00
// ============================================================================
// Check role
// ============================================================================
if($Login->role()!=='admin') {
2015-07-20 00:14:12 -03:00
Alert::set($Language->g('you-do-not-have-sufficient-permissions'));
2015-05-14 22:07:45 +00:00
Redirect::page('admin', 'dashboard');
}
2015-05-05 01:00:01 +00:00
// ============================================================================
// Functions
// ============================================================================
function addUser($args)
{
global $dbUsers;
2015-07-20 00:14:12 -03:00
global $Language;
2015-05-05 01:00:01 +00:00
// Check if the username already exist in db.
2015-07-22 00:15:02 -03:00
if( Text::isEmpty($args['username']) )
2015-05-05 01:00:01 +00:00
{
2015-07-22 00:15:02 -03:00
Alert::set($Language->g('username-field-is-empty'));
2015-08-02 21:49:12 -03:00
return false;
2015-07-22 00:15:02 -03:00
}
if( $dbUsers->userExists($args['username']) )
{
Alert::set($Language->g('username-already-exists'));
2015-05-05 01:00:01 +00:00
return false;
}
// Validate password.
2015-05-30 22:06:55 -03:00
if( ($args['password'] != $args['confirm-password'] ) || Text::isEmpty($args['password']) )
2015-05-05 01:00:01 +00:00
{
2015-07-22 00:15:02 -03:00
Alert::set($Language->g('The password and confirmation password do not match'));
2015-05-05 01:00:01 +00:00
return false;
}
// Add the user.
if( $dbUsers->add($args) )
{
2015-07-20 00:14:12 -03:00
Alert::set($Language->g('user-has-been-added-successfully'));
2015-05-05 01:00:01 +00:00
return true;
}
else
{
2015-07-22 00:15:02 -03:00
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the account.');
2015-05-05 01:00:01 +00:00
return false;
}
}
2015-08-02 21:49:12 -03:00
// ============================================================================
// Main before POST
// ============================================================================
2015-05-05 01:00:01 +00:00
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
if( addUser($_POST) ) {
Redirect::page('admin', 'users');
}
}
2015-05-14 22:07:45 +00:00
// ============================================================================
2015-08-02 21:49:12 -03:00
// Main after POST
2015-05-14 22:07:45 +00:00
// ============================================================================