// check if user already logged in //if(isset($USER->userid) || $CFG->signupstatus == $CFG->SIGNUP_CLOSED){ // header('Location: '.$CFG->homeAddress.'index.php'); // return; //} $id = trim(required_param("id", PARAM_TEXT)); $key = trim(required_param("key", PARAM_TEXT)); $referrer = optional_param("referrer", $CFG->homeAddress . "index.php", PARAM_URL); if ($referrer == "") { $referrer = $CFG->homeAddress . "index.php"; } if (empty($id) || empty($key)) { header('Location: ' . $CFG->homeAddress . 'index.php'); return; } $auth = new UserAuthentication($id); $userauth = $auth->load(); $errors = array(); if ($userauth instanceof UserAuthentication && $userauth->validateRegistrationKey($key)) { if ($userauth->completeVerification($key)) { $user = new User($userauth->getUserID()); if ($user instanceof User) { $status = $user->getStatus(); if ($status == $CFG->USER_STATUS_ACTIVE || $status == $CFG->USER_STATUS_REPORTED) { createSession($user); header('Location: ' . $referrer); die; } else { if ($status == $CFG->USER_STATUS_UNVALIDATED) { array_push($errors, $LNG->LOGIN_EXTERNAL_ERROR_ACCOUNT_UNVALIDATED); } else {
} else { if ($CFG->signupstatus == $CFG->SIGNUP_OPEN) { $name = $firstname; if ($name != "") { if ($lastname != "") { $name .= " " . $lastname; } } else { $name = $displayname; } // If it is an open SIGNUP system, automatically create them a user account. $u = new User(); $user = $u->add($email, $name, "", $websiteurl, 'N', $provider); if ($user instanceof USER) { $registrationKey = $user->getRegistrationKey(); $authentication = new UserAuthentication(); $authentication->add($user->userid, $provider, $provideruid, $email, $registrationKey); // Check to see if the external provider has verified the email address. // If we are happy that they have, we trust that they are who they say. // So complete the registration process automatically and set the email addresses as validated. if ($email == $emailVerified) { $user->completeRegistration($registrationKey); $authentication->completeVerification($registrationKey); // send completion email to user $paramArray = array($user->name, $CFG->SITE_TITLE, $LNG->WELCOME_REGISTER_OPEN_BODY); sendMail("welcome", $LNG->WELCOME_REGISTER_OPEN_SUBJECT, $user->getEmail(), $paramArray); createSession($user); header('Location: ' . $CFG->homeAddress . '/ui/pages/welcomeexternal.php?provider=' . $provider . "&referer=" . $referrer); } else { // send email for validate ownership of email given, Validate email as External. $paramArray = array($user->name, $CFG->SITE_TITLE, $CFG->homeAddress, $user->userid, $authentication->authid, $registrationKey, urlencode($referrer));
/** * Try and load a UserAuthentication account from the gicen provider and provder user id. * @param $provider the provider * @param $userproviderid the user provider id * returns an UserAuthentication instance else return Error; */ function loadByProvider($provider, $userproviderid) { global $DB, $HUB_SQL; $params = array(); $params[0] = $provider; $params[1] = $userproviderid; $resArray = $DB->select($HUB_SQL->DATAMODEL_USER_AUTH_LOAD_BY_PROVIDER, $params); if ($resArray !== false) { $count = count($resArray); if ($count == 0) { $ERROR = new error(); $ERROR->createUserNotFoundError($this->authid); return $ERROR; } else { //Should only every be one $authentication = new UserAuthentication($resArray[0]['AuthID']); $authentication->load(); return $authentication; } } else { return database_error(); } }
public function __construct() { parent::__construct(); // Your own constructor code }