3 require_once('openid_includes.php');
5 $passthru_url = optional_param('passthru_url');
8 $redirect_url = $passthru_url;
10 $redirect_url = $CFG->wwwroot
. "index.php";
14 // if we're already logged in, say so and do nothing
15 $messages[] = __gettext("You are already logged in.");
17 $username = trim(optional_param('username'));
18 $externalservice = optional_param('externalservice');
20 if (!empty($externalservice)) {
21 switch($externalservice) {
23 case "livejournal": $username = "http://" . $username . ".livejournal.com";
25 case "aim": $username = "http://openid.aol.com/" . $username;
27 case "explode": $username = "http://explode.elgg.org/" . $username;
29 case "vox": $username = "http://" . $username . ".vox.com";
31 case "wordpress": $username = "http://" . $username . ".wordpress.com";
33 case "pip": $username = "http://" . $username . ".pip.verisignlabs.com";
39 if (!empty($username)) {
43 if (strpos($username,'.') === false) {
44 // appears to be a bare account name, so try for a default server
45 if ($CFG->openid_client_default_server
) {
46 $l = sprintf($CFG->openid_client_default_server
,$username);
48 } elseif ((strpos($username,'http://') === false) && (strpos($username,'https://') === false)) {
49 // allow for OpenID URLs that are missing the "http://" prefix
50 $username = 'http://'.$username;
53 // add closing slash to normalise URL
54 //if (substr($username,-1,1) != "/") {
58 // Remove any malformed entries
59 delete_records('users', 'alias', $username, 'email', '');
62 $ok = openid_client_authenticate_user_login($username);
64 $messages[] = __gettext("You have been logged on.");
67 $messages[] = __gettext("The username was not specified. The system could not log you in.");
71 $_SESSION['messages'] = $messages;
72 header("Location: " . $redirect_url);
74 function openid_client_authenticate_user_login($username) {
79 // match username against green, yellow and red lists
83 if ($CFG->openid_client_greenlist ||
$CFG->openid_client_yellowlist
) {
85 $yesarray = array_merge(explode("\n",$CFG->openid_client_greenlist
),explode("\n",$CFG->openid_client_yellowlist
));
86 foreach ( $yesarray as $entry ) {
87 if (fnmatch($entry,$username)) {
95 if ($CFG->openid_client_redlist
) {
96 foreach (explode("\n",$CFG->openid_client_redlist
) as $entry ) {
97 if (fnmatch($entry,$username)) {
106 $messages[] = __gettext("This site does not allow the OpenID that you entered.");
107 $messages[] = __gettext("Please try another OpenID or contact the site administrator for more information.");
111 $query = array_merge( $_GET, $_POST );
113 $identity_url = $username;
115 $consumer = new Auth_OpenID_Consumer(new OpenID_ElggStore());
117 $auth_request = $consumer->begin($identity_url);
120 $trust_root = $CFG->wwwroot
;
122 // Add simple registration arguments.
124 $auth_request->addExtensionArg('sreg', 'optional', 'email,fullname');
126 $app_url = $CFG->wwwroot
.'mod/openid_client/return.php';
128 $redirect_url = $auth_request->redirectURL($trust_root, $app_url);
130 session_write_close();
131 if (headers_sent()) {
132 die("headers sent!");
134 header( "Location: " . $redirect_url );
138 $messages[] = 'OpenID authentication failed: '.$username. ' is not a valid OpenID URL.';