Пример #1
1
 public function execute()
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     foreach ($this->arguments as $argument) {
         try {
             $user = $DB->get_record('user', array('username' => $argument));
         } catch (Exception $e) {
             print get_class($e) . " thrown within the exception handler. Message: " . $e->getMessage() . " on line " . $e->getLine();
         }
         if ($user instanceof \stdClass) {
             user_delete_user($user);
         } else {
             print "User not found\n";
         }
     }
 }
Пример #2
0
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
global $config;
check_login();
include_once 'include/functions_user.php';
$get_group_details = (bool) get_parameter('get_group_details');
$id = (int) get_parameter('id');
$delete_user = get_parameter('delete_user', 0);
if ($delete_user) {
    $id_user_delete = get_parameter('id_user_delete');
    user_delete_user($id_user_delete);
}
if ($get_group_details) {
    if (!give_acl($config["id_user"], $id, "IR")) {
        return;
    }
    $default_user = get_db_value('id_user_default', 'tgrupo', 'id_grupo', $id);
    $real_name = get_db_value('nombre_real', 'tusuario', 'id_usuario', $default_user);
    $group = array();
    $group['forced_email'] = get_db_value('forced_email', 'tgrupo', 'id_grupo', $id);
    $group['user_real_name'] = $real_name;
    $group['id_user_default'] = $default_user;
    echo json_encode($group);
    if (defined('AJAX')) {
        return;
    }
Пример #3
0
    if (!$admin_can_add_user) {
        // If adding users is not allowed...
        send_to_preferred_view();
        exit;
    }
} else {
    // User is editing their account info.
    if (!access_can_access_function(ACCESS_ACCOUNT_INFO)) {
        send_to_preferred_view();
    }
}
// Handle delete.
if (!empty($delete) && $formtype == 'edituser') {
    if (access_can_access_function(ACCESS_USER_MANAGEMENT)) {
        if ($admin_can_delete_user) {
            user_delete_user($user);
            // Will also delete user's events.
            activity_log(0, $login, $user, LOG_USER_DELETE, '');
        } else {
            $error = $deleteStr;
        }
    } else {
        $error = print_not_auth(15);
    }
} else {
    // Handle update of password.
    if ($formtype == 'setpassword' && strlen($user)) {
        if (!access_can_access_function(ACCESS_USER_MANAGEMENT) && !access_can_access_function(ACCESS_ACCOUNT_INFO)) {
            $error = print_not_auth(17);
        } else {
            if ($upassword1 != $upassword2) {
Пример #4
0
 /**
  * Delete users
  *
  * @param array $userids
  * @return null
  * @since Moodle 2.2
  */
 public static function delete_users($userids)
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . "/user/lib.php";
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     require_capability('moodle/user:delete', $context);
     self::validate_context($context);
     $params = self::validate_parameters(self::delete_users_parameters(), array('userids' => $userids));
     $transaction = $DB->start_delegated_transaction();
     foreach ($params['userids'] as $userid) {
         $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), '*', MUST_EXIST);
         // must not allow deleting of admins or self!!!
         if (is_siteadmin($user)) {
             throw new moodle_exception('useradminodelete', 'error');
         }
         if ($USER->id == $user->id) {
             throw new moodle_exception('usernotdeletederror', 'error');
         }
         user_delete_user($user);
     }
     $transaction->allow_commit();
     return null;
 }
Пример #5
0
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// Load globar vars
global $config;
check_login();
if (!give_acl($config["id_user"], 0, "UM")) {
    audit_db($config["id_user"], $config["REMOTE_ADDR"], "ACL Violation", "Trying to access User Management");
    require "general/noaccess.php";
    exit;
}
include_once 'include/functions_user.php';
if (isset($_GET["borrar_usuario"])) {
    // if delete user
    $nombre = safe_input($_GET["borrar_usuario"]);
    user_delete_user($nombre);
}
$offset = get_parameter("offset", 0);
$search_text = get_parameter("search_text", "");
$disabled_user = get_parameter("disabled_user", -1);
$level = get_parameter("level", -10);
$group = get_parameter("group", 0);
echo '<h2>' . __('User management') . '</h2>';
echo '<h4>' . __('List users') . '</h4>';
echo "<div style='width:100%' class='divform'>";
if (!isset($filter_form)) {
    $filter_form = '';
}
form_search_users(false, $filter_form);
echo "<form method=post action='index.php?sec=users&sec2=godmode/usuarios/configurar_usuarios&alta=1'>";
echo "<table style='width:20%' class='search-table'>";
Пример #6
0
// If adding a user, make sure a password was provided
if (empty($error) && $add && empty($user_password)) {
    $error = translate('You have not entered a password.');
}
if (empty($error) && !$add && !$delete && empty($user_password)) {
    $user_password = $old_password;
}
// admin must be 'Y' or 'N' for call to user_add_user ()
$user_admin = empty($user_admin) || $user_admin != '1' ? 'N' : 'Y';
// If user is editing themself, do not let them take away admin setting.
// We don't want them to accidentally have no admin users left.
if (empty($error) && $user_login == $login && $user_admin == 'N') {
    $error = translate('You cannot remove admin rights from yourself!');
}
if (empty($error) && $delete) {
    user_delete_user($user_login);
} else {
    if (empty($error) && $add) {
        //TODO add $user_enabled
        if (user_add_user($user_login, $user_password, $user_firstname, $user_lastname, $user_email, $user_admin)) {
            // success    :-)
        } else {
            // error
            $error = empty($error) ? translate('Unknown error saving user') : ws_escape_xml($error);
        }
    } else {
        if (empty($error)) {
            // update
            //TODO add $user_enabled
            if (user_update_user($user_login, $user_firstname, $user_lastname, $user_email, $user_admin)) {
                // success    :-)
Пример #7
0
    /**
     * Test update_users
     */
    public function test_update_users() {
        global $USER, $CFG, $DB;

        $this->resetAfterTest(true);

        $wsuser = self::getDataGenerator()->create_user();
        self::setUser($wsuser);

        $context = context_user::instance($USER->id);
        $contextid = $context->id;
        $filename = "reddot.png";
        $filecontent = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38"
            . "GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==";

        // Call the files api to create a file.
        $draftfile = core_files_external::upload($contextid, 'user', 'draft', 0, '/',
                $filename, $filecontent, null, null);
        $draftfile = external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile);

        $draftid = $draftfile['itemid'];

        $user1 = self::getDataGenerator()->create_user();

        $user1 = array(
            'id' => $user1->id,
            'username' => 'usernametest1',
            'password' => 'Moodle2012!',
            'idnumber' => 'idnumbertest1',
            'firstname' => 'First Name User Test 1',
            'lastname' => 'Last Name User Test 1',
            'middlename' => 'Middle Name User Test 1',
            'lastnamephonetic' => '最後のお名前のテスト一号',
            'firstnamephonetic' => 'お名前のテスト一号',
            'alternatename' => 'Alternate Name User Test 1',
            'email' => '*****@*****.**',
            'description' => 'This is a description for user 1',
            'city' => 'Perth',
            'userpicture' => $draftid,
            'country' => 'AU'
            );

        $context = context_system::instance();
        $roleid = $this->assignUserCapability('moodle/user:update', $context->id);

        // Check we can't update deleted users, guest users, site admin.
        $user2 = $user3 = $user4 = $user1;
        $user2['id'] = $CFG->siteguest;

        $siteadmins = explode(',', $CFG->siteadmins);
        $user3['id'] = array_shift($siteadmins);

        $userdeleted = self::getDataGenerator()->create_user();
        $user4['id'] = $userdeleted->id;
        user_delete_user($userdeleted);

        // Call the external function.
        core_user_external::update_users(array($user1, $user2, $user3, $user4));

        $dbuser2 = $DB->get_record('user', array('id' => $user2['id']));
        $this->assertNotEquals($dbuser2->username, $user2['username']);
        $dbuser3 = $DB->get_record('user', array('id' => $user3['id']));
        $this->assertNotEquals($dbuser3->username, $user3['username']);
        $dbuser4 = $DB->get_record('user', array('id' => $user4['id']));
        $this->assertNotEquals($dbuser4->username, $user4['username']);

        $dbuser = $DB->get_record('user', array('id' => $user1['id']));
        $this->assertEquals($dbuser->username, $user1['username']);
        $this->assertEquals($dbuser->idnumber, $user1['idnumber']);
        $this->assertEquals($dbuser->firstname, $user1['firstname']);
        $this->assertEquals($dbuser->lastname, $user1['lastname']);
        $this->assertEquals($dbuser->email, $user1['email']);
        $this->assertEquals($dbuser->description, $user1['description']);
        $this->assertEquals($dbuser->city, $user1['city']);
        $this->assertEquals($dbuser->country, $user1['country']);
        $this->assertNotEquals(0, $dbuser->picture, 'Picture must be set to the new icon itemid for this user');

        // Confirm no picture change when parameter is not supplied.
        unset($user1['userpicture']);
        core_user_external::update_users(array($user1));
        $dbusernopic = $DB->get_record('user', array('id' => $user1['id']));
        $this->assertEquals($dbuser->picture, $dbusernopic->picture, 'Picture not change without the parameter.');

        // Confirm delete of picture deletes the picture from the user record.
        $user1['userpicture'] = 0;
        core_user_external::update_users(array($user1));
        $dbuserdelpic = $DB->get_record('user', array('id' => $user1['id']));
        $this->assertEquals(0, $dbuserdelpic->picture, 'Picture must be deleted when sent as 0.');


        // Call without required capability.
        $this->unassignUserCapability('moodle/user:update', $context->id, $roleid);
        $this->expectException('required_capability_exception');
        core_user_external::update_users(array($user1));
    }
Пример #8
0
 /**
  * overwrite
  * @see auth_plugin_base::user_delete()
  * 
  * Delete user course and employee_user
  */
 function user_delete($olduser)
 {
     global $DB;
     $user = $DB->get_record('user', array('idnumber' => $olduser->id));
     if ($user) {
         user_delete_user($user);
     }
     $course = $DB->get_record('course', array('shortname' => 'skillmgmt' . $olduser->id));
     if ($course) {
         delete_course($course);
     }
     return true;
 }
Пример #9
0
 /**
  * Delete a user
  *
  * @param object $record One record of import data
  * @param string $filename The import file name, used for logging
  * @return boolean true on success, otherwise false
  */
 function user_delete($record, $filename)
 {
     global $CFG, $DB;
     require_once $CFG->dirroot . '/user/lib.php';
     //field length checking
     $lengthcheck = $this->check_user_field_lengths($record, $filename);
     if (!$lengthcheck) {
         return false;
     }
     // Find existing user record
     $errors = array();
     $error = false;
     $errsuffix = '';
     $uid = $this->get_userid_for_user_actions($record, $filename, $error, $errors, $errsuffix);
     if ($error) {
         $this->fslogger->log_failure(implode($errors, ", ") . $errsuffix, 0, $filename, $this->linenumber, $record, "user");
         return false;
     }
     // make the appropriate changes
     if ($user = $DB->get_record('user', array('id' => $uid))) {
         user_delete_user($user);
         //string to describe the user
         $user_descriptor = $this->get_user_descriptor($record);
         //log success
         $this->fslogger->log_success("User with {$user_descriptor} successfully deleted.", 0, $filename, $this->linenumber);
         if (!$this->fslogger->get_logfile_status()) {
             return false;
         }
         return true;
     } else {
         // string to describe the user
         $userdescriptor = $this->get_user_descriptor($record);
         // Generic error
         $this->fslogger->log_failure("Error deleting user with {$userdescriptor}", 0, $filename, $this->linenumber, $record, "user");
     }
     return false;
 }