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('defaultaccountlifetime')) { $registration->expiry = db_format_timestamp(time() + $expirytime); } $registration->lastlogin = db_format_timestamp(time()); $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', 'internal'); if (false == $authinstance) { // TODO: Specify exception throw new Exception('No internal auth instance for institution'); } $user = new User(); $user->username = $registration->username; $user->password = $registration->password; $user->salt = $registration->salt; $user->passwordchange = 0; $user->active = 1; $user->authinstance = $authinstance->id; $user->firstname = $registration->firstname; $user->lastname = $registration->lastname; $user->email = $registration->email; create_user($user, $profilefields); $user->add_institution_request($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); // A special greeting for special people if (in_array($user->username, array('waawaamilk', 'Mjollnir`', 'Ned', 'richardm', 'fmarier'))) { $SESSION->add_ok_msg('MAMA!!! Maharababy happy to see you :D :D!'); } else { if ($user->username == 'htaccess') { $SESSION->add_ok_msg('Welcome B-Quack, htaccess!'); } else { $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename'))); } } redirect(); }
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(); }
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('defaultaccountlifetime')) { $registration->expiry = db_format_timestamp(time() + $expirytime); } $registration->lastlogin = db_format_timestamp(time()); $authinstance = get_record('auth_instance', 'institution', $registration->institution, 'authname', 'internal'); if (false == $authinstance) { throw new ConfigException('No internal auth instance for institution'); } $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; $user->salt = substr(md5(rand(1000000, 9999999)), 2, 8); 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 { $user->add_institution_request($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); // A special greeting for special people if (in_array($user->username, array('waawaamilk', 'Mjollnir`', 'Ned', 'richardm', 'fmarier', 'naveg'))) { $SESSION->add_ok_msg('MAMA!!! Maharababy happy to see you :D :D!'); } else { if ($user->username == 'htaccess') { $SESSION->add_ok_msg('Welcome B-Quack, htaccess!'); } else { $SESSION->add_ok_msg(get_string('registrationcomplete', 'mahara', get_config('sitename'))); } } $SESSION->set('resetusername', true); redirect(); }