$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();
    }
    create_registered_user();
}
// Default page - show the registration form
list($form, $registerconfirm) = auth_generate_registration_form('register', 'internal', '/register.php');
if (!$form) {
    die_info(get_string('registeringdisallowed'));
}
list($formhtml, $js) = auth_generate_registration_form_js($form, $registerconfirm);
$registerdescription = get_string('registerwelcome');
if ($registerterms = get_config('registerterms')) {
    $registerdescription .= ' ' . get_string('registeragreeterms');
}
$registerdescription .= ' ' . get_string('registerprivacy');
$smarty = smarty();
$smarty->assign('register_form', $formhtml);
$smarty->assign('registerdescription', $registerdescription);
if ($registerterms) {
    $smarty->assign('termsandconditions', '<a name="user_acceptterms"></a>' . get_site_page_content('termsandconditions'));
}
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('register.tpl');
Example #2
0
 public function login($email)
 {
     // This will do one of 3 things
     // 1 - If a user has an account, log them in
     // 2 - If a user doesn't have an account, and there is an auth method (which also has weautocreate), create acc and login
     // 3 - If a user doesn't have an account, and there is more than one auth method, show a registration page
     $sql = "SELECT\n                    a.id, i.name AS institutionname\n                FROM\n                    {auth_instance} a\n                JOIN\n                    {institution} i ON a.institution = i.name\n                WHERE\n                    a.authname = 'browserid' AND\n                    i.suspended = 0";
     $authinstances = get_records_sql_array($sql, array());
     if (!$authinstances) {
         throw new ConfigException(get_string('browseridnotenabled', 'auth.browserid'));
     }
     $autocreate = array();
     // Remember the authinstances that are happy to create users
     foreach ($authinstances as $authinstance) {
         $auth = AuthFactory::create($authinstance->id);
         $institutionjoin = '';
         $institutionwhere = '';
         $sqlvalues = array($email);
         if ($authinstance->institutionname != 'mahara') {
             // Make sure that user is in the right institution
             $institutionjoin = 'JOIN {usr_institution} ui ON ui.usr = u.id';
             $institutionwhere = 'AND ui.institution = ?';
             $sqlvalues[] = $authinstance->institutionname;
         }
         $sql = "SELECT\n                        u.*,\n                        " . db_format_tsfield('u.expiry', 'expiry') . ",\n                        " . db_format_tsfield('u.lastlogin', 'lastlogin') . ",\n                        " . db_format_tsfield('u.lastlastlogin', 'lastlastlogin') . ",\n                        " . db_format_tsfield('u.lastaccess', 'lastaccess') . ",\n                        " . db_format_tsfield('u.suspendedctime', 'suspendedctime') . ",\n                        " . db_format_tsfield('u.ctime', 'ctime') . "\n                    FROM\n                        {usr} u\n                    JOIN\n                        {artefact_internal_profile_email} a ON a.owner = u.id\n                    {$institutionjoin}\n                    WHERE\n                        a.verified = 1 AND\n                        a.email = ?\n                    {$institutionwhere}";
         $user = get_record_sql($sql, $sqlvalues);
         if (!$user) {
             if ($auth->weautocreateusers) {
                 if ($authinstance->institutionname == 'mahara') {
                     array_unshift($autocreate, $auth);
                     // Try "No Instititution" first when creating users below
                 } else {
                     $autocreate[] = $auth;
                 }
             }
             continue;
             // skip to the next auth_instance
         }
         if (is_site_closed($user->admin)) {
             return false;
         }
         ensure_user_account_is_active($user);
         $this->authenticate($user, $auth->instanceid);
         return true;
     }
     foreach ($autocreate as $auth) {
         if (!($user = $auth->create_new_user($email))) {
             continue;
         }
         $this->authenticate($user, $auth->instanceid);
         return;
     }
     // Autocreation failed; try registration.
     list($form, $registerconfirm) = auth_generate_registration_form('register', 'browserid', '/register.php');
     if (!$form) {
         throw new AuthUnknownUserException(get_string('emailnotfound', 'auth.browserid', $email));
     }
     if (record_exists('usr', 'email', $email) || record_exists('artefact_internal_profile_email', 'email', $email)) {
         throw new AuthUnknownUserException(get_string('emailalreadytaken', 'auth.internal', $email));
     }
     $form['elements']['email'] = array('type' => 'hidden', 'value' => $email);
     $form['elements']['authtype'] = array('type' => 'hidden', 'value' => 'browserid');
     list($formhtml, $js) = auth_generate_registration_form_js($form, $registerconfirm);
     $registerdescription = get_string('registerwelcome');
     if ($registerterms = get_config('registerterms')) {
         $registerdescription .= ' ' . get_string('registeragreeterms');
     }
     $registerdescription .= ' ' . get_string('registerprivacy');
     $smarty = smarty();
     $smarty->assign('register_form', $formhtml);
     $smarty->assign('registerdescription', $registerdescription);
     if ($registerterms) {
         $smarty->assign('termsandconditions', get_site_page_content('termsandconditions'));
     }
     $smarty->assign('PAGEHEADING', get_string('register', 'auth.browserid'));
     $smarty->assign('INLINEJAVASCRIPT', $js);
     $smarty->display('register.tpl');
     die;
 }