Exemplo n.º 1
0
foreach ($authinstances as $authinstance) {
    $options[$authinstance->id] = $authinstance->displayname . ': ' . $authinstance->instancename;
    if (!$default && $authinstance->name == 'mahara') {
        $default = $authinstance->id;
    }
}
// Suspend users
$suspendform = pieform(array('name' => 'suspend', 'class' => 'bulkactionform', 'renderer' => 'oneline', 'elements' => array('users' => $userelement, 'reason' => array('type' => 'text', 'title' => get_string('suspendedreason', 'admin') . ': '), 'suspend' => array('type' => 'submit', 'value' => get_string('Suspend', 'admin')))));
// Change authentication method
$changeauthform = null;
if (count($options) > 1) {
    $changeauthform = pieform(array('name' => 'changeauth', 'class' => 'bulkactionform', 'renderer' => 'oneline', 'dieaftersubmit' => false, 'elements' => array('users' => $userelement, 'title' => array('type' => 'html', 'class' => 'bulkaction-title', 'value' => get_string('changeauthmethod', 'admin') . ': '), 'authinstance' => array('type' => 'select', 'options' => $options, 'defaultvalue' => $default), 'changeauth' => array('type' => 'submit', 'value' => get_string('submit')))));
}
// Set probation points
$probationform = null;
if (is_using_probation()) {
    $probationform = pieform(array('name' => 'probation', 'class' => 'bulkactionform', 'renderer' => 'oneline', 'elements' => array('users' => $userelement, 'probationpoints' => array('type' => 'select', 'title' => get_string('probationbulksetspamprobation', 'admin') . ': ', 'options' => probation_form_options(), 'defaultvalue' => '0'), 'setprobation' => array('type' => 'submit', 'confirm' => get_string('probationbulkconfirm', 'admin'), 'value' => get_string('probationbulkset', 'admin')))));
}
// Delete users
$deleteform = pieform(array('name' => 'delete', 'class' => 'bulkactionform delete', 'renderer' => 'oneline', 'elements' => array('users' => $userelement, 'title' => array('type' => 'html', 'class' => 'bulkaction-title', 'value' => get_string('deleteusers', 'admin') . ': '), 'delete' => array('type' => 'submit', 'confirm' => get_string('confirmdeleteusers', 'admin'), 'value' => get_string('delete')))));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('users', $users);
$smarty->assign('changeauthform', $changeauthform);
$smarty->assign('suspendform', $suspendform);
$smarty->assign('deleteform', $deleteform);
$smarty->assign('probationform', $probationform);
$smarty->display('admin/users/bulk.tpl');
function changeauth_validate(Pieform $form, $values)
{
    global $userids, $SESSION;
Exemplo n.º 2
0
function edituser_site_submit(Pieform $form, $values)
{
    global $USER, $authobj, $SESSION;
    if (!($user = get_record('usr', 'id', $values['id']))) {
        return false;
    }
    if (is_using_probation()) {
        // Value should be between 0 and 10 inclusive
        $user->probation = ensure_valid_probation_points($values['probationpoints']);
    }
    if ($USER->get('admin') || get_config_plugin('artefact', 'file', 'institutionaloverride')) {
        $user->quota = $values['quota'];
        // check if the user has gone over the quota notify limit
        $quotanotifylimit = get_config_plugin('artefact', 'file', 'quotanotifylimit');
        if ($quotanotifylimit <= 0 || $quotanotifylimit >= 100) {
            $quotanotifylimit = 100;
        }
        $user->quotausedpercent = $user->quotaused / $user->quota * 100;
        $overlimit = false;
        if ($quotanotifylimit <= $user->quotausedpercent) {
            $overlimit = true;
        }
        $notified = get_field('usr_account_preference', 'value', 'field', 'quota_exceeded_notified', 'usr', $user->id);
        if ($overlimit && '1' !== $notified) {
            require_once get_config('docroot') . 'artefact/file/lib.php';
            ArtefactTypeFile::notify_users_threshold_exceeded(array($user), false);
            // no need to email admin as we can alert them right now
            $SESSION->add_error_msg(get_string('useroverquotathreshold', 'artefact.file', display_name($user)));
        } else {
            if ($notified && !$overlimit) {
                set_account_preference($user->id, 'quota_exceeded_notified', false);
            }
        }
    }
    $unexpire = $user->expiry && strtotime($user->expiry) < time() && (empty($values['expiry']) || $values['expiry'] > time());
    $newexpiry = db_format_timestamp($values['expiry']);
    if ($user->expiry != $newexpiry) {
        $user->expiry = $newexpiry;
        if ($unexpire) {
            $user->expirymailsent = 0;
            $user->lastaccess = db_format_timestamp(time());
        }
    }
    // Try to kick the user from any active login sessions, before saving data.
    require_once get_config('docroot') . 'auth/session.php';
    remove_user_sessions($user->id);
    if ($USER->get('admin')) {
        // Not editable by institutional admins
        $user->staff = (int) ($values['staff'] == 'on');
        $user->admin = (int) ($values['admin'] == 'on');
        if ($user->admin) {
            activity_add_admin_defaults(array($user->id));
        }
    }
    if ($values['maildisabled'] == 0 && get_account_preference($user->id, 'maildisabled') == 1) {
        // Reset the sent and bounce counts otherwise mail will be disabled
        // on the next send attempt
        $u = new StdClass();
        $u->email = $user->email;
        $u->id = $user->id;
        update_bounce_count($u, true);
        update_send_count($u, true);
    }
    set_account_preference($user->id, 'maildisabled', $values['maildisabled']);
    // process the change of the authinstance and or the remoteuser
    if (isset($values['authinstance']) && isset($values['remoteusername'])) {
        // Authinstance can be changed by institutional admins if both the
        // old and new authinstances belong to the admin's institutions
        $authinst = get_records_select_assoc('auth_instance', 'id = ? OR id = ?', array($values['authinstance'], $user->authinstance));
        // But don't bother if the auth instance doesn't take a remote username
        $authobj = AuthFactory::create($values['authinstance']);
        if ($USER->get('admin') || $USER->is_institutional_admin($authinst[$values['authinstance']]->institution) && ($USER->is_institutional_admin($authinst[$user->authinstance]->institution) || $user->authinstance == 1)) {
            if ($authobj->needs_remote_username()) {
                // determine the current remoteuser
                $current_remotename = get_field('auth_remote_user', 'remoteusername', 'authinstance', $user->authinstance, 'localusr', $user->id);
                if (!$current_remotename) {
                    $current_remotename = $user->username;
                }
                // if the remoteuser is empty
                if (strlen(trim($values['remoteusername'])) == 0) {
                    delete_records('auth_remote_user', 'authinstance', $user->authinstance, 'localusr', $user->id);
                }
                // what should the new remoteuser be
                $new_remoteuser = get_field('auth_remote_user', 'remoteusername', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                // save the remotename for the target existence check
                $target_remotename = $new_remoteuser;
                if (!$new_remoteuser) {
                    $new_remoteuser = $user->username;
                }
                if (strlen(trim($values['remoteusername'])) > 0) {
                    // value changed on page - use it
                    if ($values['remoteusername'] != $current_remotename) {
                        $new_remoteuser = $values['remoteusername'];
                    }
                }
                // only update remote name if the input actually changed on the page  or it doesn't yet exist
                if ($current_remotename != $new_remoteuser || !$target_remotename) {
                    // only remove the ones related to this traget authinstance as we now allow multiple
                    // for dual login mechanisms
                    delete_records('auth_remote_user', 'authinstance', $values['authinstance'], 'localusr', $user->id);
                    insert_record('auth_remote_user', (object) array('authinstance' => $values['authinstance'], 'remoteusername' => $new_remoteuser, 'localusr' => $user->id));
                }
            }
            // update the ai on the user master
            $user->authinstance = $values['authinstance'];
            // update the global $authobj to match the new authinstance
            // this is used by the password/username change methods
            // if either/both has been requested at the same time
            $authobj = AuthFactory::create($user->authinstance);
        }
    }
    // Only change the pw if the new auth instance allows for it
    if (method_exists($authobj, 'change_password')) {
        $user->passwordchange = (int) (isset($values['passwordchange']) && $values['passwordchange'] == 'on' ? 1 : 0);
        if (isset($values['password']) && $values['password'] !== '') {
            $userobj = new User();
            $userobj = $userobj->find_by_id($user->id);
            $user->password = $authobj->change_password($userobj, $values['password']);
            $user->salt = $userobj->salt;
            unset($userobj);
        }
    } else {
        // inform the user that the chosen auth instance doesn't allow password changes
        // but only if they tried changing it
        if (isset($values['password']) && $values['password'] !== '') {
            $SESSION->add_error_msg(get_string('passwordchangenotallowed', 'admin'));
            // Set empty pw with salt
            $user->password = '';
            $user->salt = auth_get_random_salt();
        }
    }
    if (isset($values['username']) && $values['username'] !== '') {
        $userobj = new User();
        $userobj = $userobj->find_by_id($user->id);
        if ($userobj->username != $values['username']) {
            // Only change the username if the auth instance allows for it
            if (method_exists($authobj, 'change_username')) {
                // check the existence of the chosen username
                try {
                    if ($authobj->user_exists($values['username'])) {
                        // set an error message if it is already in use
                        $SESSION->add_error_msg(get_string('usernameexists', 'account'));
                    }
                } catch (AuthUnknownUserException $e) {
                    // update the username otherwise
                    $user->username = $authobj->change_username($userobj, $values['username']);
                }
            } else {
                // inform the user that the chosen auth instance doesn't allow username changes
                $SESSION->add_error_msg(get_string('usernamechangenotallowed', 'admin'));
            }
        }
        unset($userobj);
    }
    // OVERWRITE 4: insert
    if (isset($values['email']) && !empty($values['email']) && $values['email'] != $user->email) {
        global $CFG;
        $user->email = $values['email'];
        $mhr_user = $CFG->current_app->getUserById($user->id);
        $mhr_user->setEmailAddress($values['email']);
    }
    // END OVERWRITE 4
    db_begin();
    update_record('usr', $user);
    delete_records('usr_tag', 'usr', $user->id);
    if (is_array($values['tags'])) {
        $values['tags'] = check_case_sensitive($values['tags'], 'usr_tag');
        foreach (array_unique($values['tags']) as $tag) {
            if (empty($tag)) {
                continue;
            }
            insert_record('usr_tag', (object) array('usr' => $user->id, 'tag' => strtolower($tag)));
        }
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('usersitesettingschanged', 'admin'));
    redirect('/admin/users/edit.php?id=' . $user->id);
}
Exemplo n.º 3
0
/**
 * Check for external links and images being posted by a probationary user
 * @param string $text
 * @return BOOLEAN true if the text is okay, false if not
 */
function probation_validate_content($text)
{
    if (!is_using_probation()) {
        return true;
    }
    if (!has_external_links_or_images($text)) {
        return true;
    }
    if (is_probationary_user()) {
        return false;
    }
    return true;
}
Exemplo n.º 4
0
 function create_registered_user($profilefields = array())
 {
     global $registration, $SESSION, $USER;
     require_once get_config('libroot') . 'user.php';
     db_begin();
     // Move the user record to the usr table from the registration table
     $registrationid = $registration->id;
     unset($registration->id);
     unset($registration->expiry);
     if ($expirytime = get_config('defaultregistrationexpirylifetime')) {
         $registration->expiry = db_format_timestamp(time() + $expirytime);
     }
     $registration->lastlogin = db_format_timestamp(time());
     $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', $registration->authtype ? $registration->authtype : 'internal');
     if (false == $authinstance) {
         throw new ConfigException('No ' . ($registration->authtype ? $registration->authtype : 'internal') . ' auth instance for institution');
     }
     if (!empty($registration->extra)) {
         // Additional user settings were added during confirmation
         $extrafields = unserialize($registration->extra);
     }
     $user = new User();
     $user->active = 1;
     $user->authinstance = $authinstance->id;
     $user->firstname = $registration->firstname;
     $user->lastname = $registration->lastname;
     $user->email = $registration->email;
     $user->username = get_new_username($user->firstname . $user->lastname);
     $user->passwordchange = 1;
     // Points that indicate the user is a "new user" who should be restricted from spammy activities.
     // We count these down when they do good things; when they have 0 they're no longer a "new user"
     if (is_using_probation()) {
         $user->probation = get_config('probationstartingpoints');
     } else {
         $user->probation = 0;
     }
     if ($registration->institution != 'mahara') {
         if (count_records_select('institution', "name != 'mahara'") == 1 || $registration->pending == 2) {
             if (get_config_plugin('artefact', 'file', 'institutionaloverride')) {
                 $user->quota = get_field('institution', 'defaultquota', 'name', $registration->institution);
             }
         }
     }
     create_user($user, $profilefields);
     // If the institution is 'mahara' then don't do anything
     if ($registration->institution != 'mahara') {
         $institutions = get_records_select_array('institution', "name != 'mahara'");
         // If there is only one available, join it without requiring approval
         if (count($institutions) == 1) {
             $user->join_institution($registration->institution);
         } else {
             if ($registration->pending == 2) {
                 if (get_config('requireregistrationconfirm') || get_field('institution', 'registerconfirm', 'name', $registration->institution)) {
                     $user->join_institution($registration->institution);
                 }
             } else {
                 if ($registration->authtype && $registration->authtype != 'internal') {
                     $auth = AuthFactory::create($authinstance->id);
                     if ($auth->weautocreateusers) {
                         $user->join_institution($registration->institution);
                     } else {
                         $user->add_institution_request($registration->institution);
                     }
                 } else {
                     $user->add_institution_request($registration->institution);
                 }
             }
         }
         if (!empty($extrafields->institutionstaff)) {
             // If the user isn't a member yet, this does nothing, but that's okay, it'll
             // only be set after successful confirmation.
             set_field('usr_institution', 'staff', 1, 'usr', $user->id, 'institution', $registration->institution);
         }
     }
     if (!empty($registration->lang) && $registration->lang != 'default') {
         set_account_preference($user->id, 'lang', $registration->lang);
     }
     // Delete the old registration record
     delete_records('usr_registration', 'id', $registrationid);
     db_commit();
     // Log the user in and send them to the homepage
     $USER = new LiveUser();
     $USER->reanimate($user->id, $authinstance->id);
     if (function_exists('local_post_register')) {
         local_post_register($registration);
     }
     $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename')));
     $SESSION->set('resetusername', true);
     redirect();
 }
Exemplo n.º 5
0
function addpost_submit(Pieform $form, $values)
{
    global $USER, $SESSION;
    require_once 'embeddedimage.php';
    $parentid = param_integer('parent');
    $post = (object) array('topic' => $values['topic'], 'poster' => $USER->get('id'), 'parent' => $parentid, 'subject' => $values['subject'], 'body' => $values['body'], 'ctime' => db_format_timestamp(time()));
    $sendnow = isset($values['sendnow']) && $values['sendnow'] ? 1 : 0;
    // See if the same content has been submitted in the last 5 seconds. If so, don't add this post.
    $oldpost = get_record_select('interaction_forum_post', 'topic = ? AND poster = ? AND parent = ? AND subject = ? AND body = ? AND ctime > ?', array($post->topic, $post->poster, $post->parent, $post->subject, $post->body, db_format_timestamp(time() - 5)), 'id');
    if ($oldpost) {
        redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $oldpost->id);
    }
    $postrec = new stdClass();
    $postid = $postrec->id = insert_record('interaction_forum_post', $post, 'id', true);
    $postrec->path = get_field('interaction_forum_post', 'path', 'id', $parentid) . '/' . sprintf('%010d', $postrec->id);
    update_record('interaction_forum_post', $postrec);
    // Rewrite the post id into links in the body
    $groupid = get_groupid_from_postid($postid);
    $newbody = EmbeddedImage::prepare_embedded_images($post->body, 'post', $postid, $groupid);
    $newbody = PluginInteractionForum::prepare_post_body($newbody, $postid);
    if (!empty($newbody) && $newbody != $post->body) {
        set_field('interaction_forum_post', 'body', $newbody, 'id', $postid);
    }
    if ($sendnow == 0) {
        $delay = get_config_plugin('interaction', 'forum', 'postdelay');
    } else {
        $delay = 0;
    }
    if (!is_null($delay) && $delay == 0) {
        PluginInteractionForum::interaction_forum_new_post(array($postid));
    }
    $SESSION->add_ok_msg(get_string('addpostsuccess', 'interaction.forum'));
    if (is_using_probation() && $post->parent) {
        $parentposter = get_field('interaction_forum_post', 'poster', 'id', $post->parent);
        vouch_for_probationary_user($parentposter);
    }
    redirect(get_config('wwwroot') . 'interaction/forum/topic.php?id=' . $values['topic'] . '&post=' . $postid);
}