function basic_auth(array $setupconfig) { try { $user = $_SERVER['PHP_AUTH_USER']; $pass = $_SERVER['PHP_AUTH_PW']; //try to use the export user if (isset($setupconfig['export_user']) && isset($setupconfig['export_key'])) { $export_user = strtolower($setupconfig['export_user']); $export_key = $setupconfig['export_key']; if (strtolower($user) == $export_user && $pass == $export_key) { $logged_in = true; } } //if not, try to authenticate against Google Apps if (!$logged_in) { try { $auth = new \NRG\Login\Google\ClientLogin($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); //Attempt to authenticate the user $auth->login(); if ($auth->isSuccessful()) { $logged_in = true; } } catch (\NRG\Login\Google\ClientLoginException $e) { $logged_in = false; ajax_http_auth_error("Invalid username or password"); } } //if none of the options above worked, return an error if (!$logged_in) { ajax_http_auth_error("Invalid username or password"); } } catch (Exception $e) { ajax_http_auth_error($e->getMessage()); } }
ajax_error('Your account has been disabled.'); } if (!isset($user['roleID']) || $user['roleID'] == NULL) { ajax_error('Sorry, your account hasn\'t been assigned any privileges yet. Please try again later.'); } if (in_array(strtolower($username), array("*****@*****.**", "guest")) && $setupconf['guest_login'] == 1) { $logged_in = true; } else { $auth = new NRG\Login\Google\ClientLogin($username, $txtPassword); if (!empty($captchatext) && !empty($captchatoken)) { $auth->setCaptchaText($captchatext); $auth->setCaptchaToken($captchatoken); } //Attempt to authenticate the user $auth->login(); if ($auth->isSuccessful()) { $logged_in = true; } } } //If authentication was successful, log the user in if ($logged_in === true) { $_SESSION['auth'] = true; $_SESSION['username'] = $user['username']; $_SESSION['role'] = $user['name']; $_SESSION['aclID'] = $user['aclID']; $_SESSION['roleID'] = $user['roleID']; $_SESSION['clearance'] = $user['clearance']; } else { ajax_error("Invalid username or password."); }