Ejemplo n.º 1
0
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());
    }
}
Ejemplo n.º 2
0
     if (empty($user)) {
         ajax_error('You must <a href="javascript:showRegistrationForm()">request access</a> first.');
     }
     if ($user['requested'] == 1) {
         ajax_error('Your access request is pending approval.');
     }
     if (!$user['enabled']) {
         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'];