Ejemplo n.º 1
0
 /**
  * Hook for overriding behavior of login page.
  * This method is called from login/index.php page for all enabled auth
  * plugins.
  *
  * We're overriding the default login behaviour.
  */
 function loginpage_hook()
 {
     global $CFG;
     global $frm, $user;
     // Login page variables
     // If the OpenID server isn't defined, don't do anything
     if (empty($this->config->openid_sso_url) || $this->manual_override()) {
         return;
     }
     $mode = optional_param('openid_mode', null);
     $allow_append = $this->config->auth_openid_allow_muliple == 'true';
     if ($mode == null) {
         // If openid.mode isn't defined, initiate a request
         $this->do_request();
     } else {
         // Otherwise, we'll assume this is a response
         $resp = $this->process_response();
         if ($resp !== false) {
             $url = $resp->identity_url;
             if (record_exists('openid_urls', 'url', $url)) {
                 // Get the user associated with the OpenID
                 $userid = get_field('openid_urls', 'userid', 'url', $url);
                 $user = get_complete_user_data('id', $userid);
                 // If the user isn't found then there's a database
                 // discrepancy.  We delete this entry and create a new user
                 if (!$user) {
                     delete_records('openid_urls', 'url', $url);
                     $user = $this->_create_account($resp);
                 } elseif (function_exists('on_openid_login')) {
                     on_openid_login($resp, $user);
                 }
             } else {
                 // Otherwise, create a new account
                 $user = $this->_create_account($resp);
             }
             $frm->username = $user->username;
             $frm->password = $user->password;
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Hook for overriding behavior of login page.
  * This method is called from login/index.php page for all enabled auth
  * plugins.
  *
  * We're overriding the default login behaviour when login is attempted or
  * an OpenID response is received.  We also provide our own login form if
  * an alternate login url hasn't already been defined.  This doesn't alter
  * the site's configuration value.
  */
 function loginpage_hook()
 {
     global $CFG;
     global $frm, $user;
     // Login page variables
     $admin = optional_param('admin', null);
     $openid_url = optional_param('openid_url', null);
     $mode = optional_param('openid_mode', null);
     $allow_append = $this->config->auth_openid_allow_muliple == 'true';
     // Check for OpenID login override 'admin=true'
     if (!empty($admin) && $admin == 'true') {
         return;
     }
     // We need to use our OpenID login form
     if (empty($CFG->alternateloginurl)) {
         $CFG->alternateloginurl = $CFG->wwwroot . '/auth/openid/login.php';
     }
     if ($mode == null && $openid_url != null) {
         // If we haven't received a response, then initiate a request
         $this->do_request();
     } elseif ($mode != null) {
         // If openid.mode is set then we'll assume this is a response
         $resp = $this->process_response();
         if ($resp !== false) {
             global $SESSION;
             if (!empty($this->config->auth_openid_clear_wantsurl) && !empty($SESSION->wantsurl)) {
                 //error_log("/auth/openid/auth.php::loginpage_hook() - clearing wantsurl {$SESSION->wantsurl}");
                 unset($SESSION->wantsurl);
             }
             $url = $resp->identity_url;
             $server = $resp->endpoint->server_url;
             if (!openid_server_allowed($server, $this->config)) {
                 print_error('auth_openid_server_blacklisted', 'auth_openid', '', $server);
             }
             logout_guestuser();
             if (record_exists('openid_urls', 'url', $url)) {
                 // Get the user associated with the OpenID
                 $userid = get_field('openid_urls', 'userid', 'url', $url);
                 $user = get_complete_user_data('id', $userid);
                 // If the user isn't found then there's a database
                 // discrepancy.  We delete this entry and create a new user
                 if (!$user) {
                     delete_records('openid_urls', 'url', $url);
                     $user = $this->_open_account($resp);
                 } elseif (function_exists('on_openid_login')) {
                     on_openid_login($resp, $user);
                 }
             } else {
                 // Otherwise, create a new account
                 $user = $this->_open_account($resp, !isset($this->config->auth_openid_create_account) || $this->config->auth_openid_create_account == 'true');
             }
             if (!empty($user)) {
                 $frm->username = $user->username;
                 $frm->password = $user->password;
             }
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Hook for overriding behavior of login page.
  * This method is called from login/index.php page for all enabled auth
  * plugins.
  *
  * We're overriding the default login behaviour when login is attempted or
  * an OpenID response is received.  We also provide our own login form if
  * an alternate login url hasn't already been defined.  This doesn't alter
  * the site's configuration value.
  */
 function loginpage_hook()
 {
     // allow regular login form to be displayed if admin=true is appended to login URL
     if (optional_param('admin', null) != null) {
         return;
     }
     global $CFG;
     global $frm, $user;
     // Login page variables
     $openid_url = optional_param('openid_url', null);
     //if( $openid_url ) { $openid_url = "http://hotdog.ccnmtl.columbia.edu:4444/" . $openid_url . "/"; };
     $mode = optional_param('openid_mode', null);
     $allow_append = $this->config->auth_openid_allow_muliple == 'true';
     // We need to use our OpenID login form
     if (empty($CFG->alternateloginurl)) {
         $CFG->alternateloginurl = $CFG->wwwroot . '/auth/openid/login.php';
     }
     if ($mode == null && $openid_url != null) {
         // If we haven't received a response, then initiate a request
         $this->do_request();
     } elseif ($mode != null) {
         // If openid.mode is set then we'll assume this is a response
         $resp = $this->process_response();
         if ($resp !== false) {
             $url = $resp->identity_url;
             $server = $resp->endpoint->server_url;
             if (openid_server_is_blacklisted($server)) {
                 error(get_string('auth_openid_server_blacklisted', 'auth_openid', $server));
             } elseif (record_exists('openid_urls', 'url', $url)) {
                 // Get the user associated with the OpenID
                 echo "User found for " . $url;
                 $userid = get_field('openid_urls', 'userid', 'url', $url);
                 $user = get_complete_user_data('id', $userid);
                 // If the user isn't found then there's a database
                 // discrepancy.  We delete this entry and create a new user
                 if (!$user) {
                     echo "User was missing";
                     delete_records('openid_urls', 'url', $url);
                     $user = $this->_create_account($resp);
                 } elseif (function_exists('on_openid_login')) {
                     on_openid_login($resp, $user);
                 }
             } else {
                 // Otherwise, create a new account
                 $user = $this->_create_account($resp);
             }
             $frm->username = $user->username;
             $frm->password = $user->password;
         }
     }
 }