|
@@ -1,11 +1,14 @@
|
|
|
<?
|
|
<?
|
|
|
|
|
|
|
|
|
|
+$AUTH_ERR = '';
|
|
|
|
|
+
|
|
|
# Always start a session, unless we're on the CLI
|
|
# Always start a session, unless we're on the CLI
|
|
|
if (php_sapi_name() != 'cli') {
|
|
if (php_sapi_name() != 'cli') {
|
|
|
session_start();
|
|
session_start();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function login($username, $password) {
|
|
function login($username, $password) {
|
|
|
|
|
+ global $AUTH_ERR;
|
|
|
$authenticated = false;
|
|
$authenticated = false;
|
|
|
$authorized = false;
|
|
$authorized = false;
|
|
|
|
|
|
|
@@ -13,11 +16,16 @@ function login($username, $password) {
|
|
|
$token = myplexToken($username, $password);
|
|
$token = myplexToken($username, $password);
|
|
|
if ($token !== false) {
|
|
if ($token !== false) {
|
|
|
$authenticated = true;
|
|
$authenticated = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $AUTH_ERR = 'Invalid Credentials';
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Authorize against MyPlex
|
|
# Authorize against MyPlex
|
|
|
if ($authenticated) {
|
|
if ($authenticated) {
|
|
|
$authorized = myplexAuthorize($token);
|
|
$authorized = myplexAuthorize($token);
|
|
|
|
|
+ if (!$authorized) {
|
|
|
|
|
+ $AUTH_ERR = 'Not Authorized';
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Login on dual success
|
|
# Login on dual success
|
|
@@ -25,11 +33,13 @@ function login($username, $password) {
|
|
|
$_SESSION['USER'] = $username;
|
|
$_SESSION['USER'] = $username;
|
|
|
session_regenerate_id(true);
|
|
session_regenerate_id(true);
|
|
|
} else {
|
|
} else {
|
|
|
- logout();
|
|
|
|
|
|
|
+ logout(false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
# Redirect, using the provided target if available
|
|
# Redirect, using the provided target if available
|
|
|
- login_redirect();
|
|
|
|
|
|
|
+ if (authenticated()) {
|
|
|
|
|
+ login_redirect();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function login_redirect() {
|
|
function login_redirect() {
|
|
@@ -41,12 +51,14 @@ function login_redirect() {
|
|
|
header('Location: ' . $url);
|
|
header('Location: ' . $url);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function logout() {
|
|
|
|
|
- global $MAIN_PAGE;
|
|
|
|
|
|
|
+function logout($redirect = true) {
|
|
|
unset($_SESSION['USER']);
|
|
unset($_SESSION['USER']);
|
|
|
session_regenerate_id(true);
|
|
session_regenerate_id(true);
|
|
|
- header('Location: ' . $MAIN_PAGE);
|
|
|
|
|
- exit();
|
|
|
|
|
|
|
+ if ($redirect) {
|
|
|
|
|
+ global $MAIN_PAGE;
|
|
|
|
|
+ header('Location: ' . $MAIN_PAGE);
|
|
|
|
|
+ exit();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function username() {
|
|
function username() {
|