예제 #1
0
             } else {
                 $url = $resp->identity_url;
                 if (empty($config->auth_openid_confirm_switch) && $openid_tmp_login) {
                     openid_if_unique_change_account($USER, $url);
                 } else {
                     $file = 'confirm_change.html';
                 }
             }
         } else {
             logout_tmpuser_error(get_string('auth_openid_login_error', 'auth_openid'));
         }
     } elseif ($confirm) {
         if (!confirm_sesskey()) {
             logout_tmpuser_error(get_string('auth_openid_bad_session_key', 'auth_openid'), true);
         } else {
             openid_if_unique_change_account($USER, $url);
         }
     } elseif ($cancel) {
         logout_tmpuser_error(get_string('action_cancelled', 'auth_openid'));
     } elseif ($url != null) {
         if (openid_already_exists($url)) {
             logout_tmpuser_error(get_string('auth_openid_url_exists', 'auth_openid', $url));
         } else {
             //error_log("/auth/openid/actions.php:: url={$url} openid_tmp_login={$openid_tmp_login} referer=". $_SERVER['HTTP_REFERER']);
             $params['openid_action'] = 'change';
             $authplugin->do_request($reqinfo, $CFG->wwwroot . '/auth/openid/actions.php', $params);
         }
     }
     break;
     // Append an OpenID url to an account
 // Append an OpenID url to an account
예제 #2
0
 /**
  * Open user account using SREG & AX data if available
  * If no matching user found and create flag is true, creates new user account
  *
  * @access private
  * @param object &$resp An OpenID consumer response object
  * @param boolean $create_flag - set if account creation permitted, default: true
  * @uses $CFG
  * @uses $USER
  * @uses $openid_tmp_login
  * @return object The new user
  */
 function _open_account(&$resp, $create_flag = true)
 {
     global $CFG, $USER, $openid_tmp_login;
     $url = $resp->identity_url;
     $password = hash_internal_user_password('openid');
     $server = $resp->endpoint->server_url;
     $user = openid_resp_to_user($resp);
     if ($user == false) {
         // multiple matches to users! Don't know which user to pick.
         print_error('auth_openid_multiple_matches', 'auth_openid');
         return false;
         // won't get here.
     }
     if (isset($user->id)) {
         $openid_tmp_login = true;
         $openid_action = 'change';
         if ($user->auth == 'openid') {
             if (empty($this->config->auth_openid_allow_muliple)) {
                 print_error('auth_openid_no_multiple', 'auth_openid');
                 return false;
             }
             $openid_action = 'append';
         } else {
             if (empty($this->config->auth_openid_confirm_switch)) {
                 openid_if_unique_change_account($user, $url);
                 return $USER;
             }
         }
         $USER = clone $user;
         // To clone or not to clone
         //$mode = optional_param('openid_mode', null);
         //error_log("auth/openid/auth.php::_open_account() setting openid_mode={$mode} (openid_process_url={$openid_process_url})");
         redirect("{$CFG->wwwroot}/auth/openid/actions.php?openid_tmp_login=1&openid_action={$openid_action}&openid_url={$url}");
         // Try to get it not to make second request to be accepted, double confirm - TBD: openid_mode=???
     }
     if (!$create_flag) {
         // Error: This site is configured to disallow new users via OpenID
         print_error('auth_openid_require_account', 'auth_openid');
         return false;
         // won't get here.
     }
     $usertmp = create_user_record($user->username, $password, 'openid');
     $user->id = $usertmp->id;
     openid_append_url($user, $url);
     if (!isset($user->city) || $user->city == '') {
         //use "*" as the default city name
         $user->city = '*';
     }
     if (empty($user->country) && !empty($CFG->country)) {
         //use the configured default country code
         $user->country = $CFG->country;
     }
     if (empty($user->country)) {
         //out of other options, to try to copy the admin's country
         if ($admin = get_admin()) {
             $user->country = $admin->country;
         }
     }
     update_record('user', $user);
     $user = get_complete_user_data('id', $user->id);
     events_trigger('user_created', $user);
     // BJB120125 - moved from below redirect for alfresco, etc...
     if (function_exists('on_openid_create_account')) {
         on_openid_create_account($resp, $user);
     }
     // Redirect the user to their profile page if not set up properly
     if (!empty($user) && user_not_fully_set_up($user)) {
         $USER = clone $user;
         $urltogo = $CFG->wwwroot . '/user/edit.php';
         redirect($urltogo);
     }
     if (openid_server_requires_confirm($server, $this->config)) {
         $secret = random_string(15);
         set_field('user', 'secret', $secret, 'id', $user->id);
         $user->secret = $secret;
         set_field('user', 'confirmed', 0, 'id', $user->id);
         $user->confirmed = 0;
         openid_send_confirmation_email($user);
     }
     return $user;
 }