@@ -27,54 +27,54 @@ |
||
| 27 | 27 | |
| 28 | 28 | class Plugin_HTTPAuth_HTTPAuth { |
| 29 | 29 | |
| 30 | - //http://php.net/manual/de/features.http-auth.php |
|
| 31 | - |
|
| 32 | - public static function headerEvent () { |
|
| 33 | - //get preferences first |
|
| 34 | - $prefs = new Preferences("plugin_httpauth"); |
|
| 35 | - |
|
| 36 | - $activated = $prefs->get("activated", true); |
|
| 37 | - |
|
| 38 | - if (!$activated) { |
|
| 39 | - return; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - //check, if user is logged in |
|
| 43 | - if (User::current()->isLoggedIn()) { |
|
| 44 | - //http auth is not required, because user is already logged in |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - //check, if credentials was already send |
|
| 49 | - if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 50 | - self::sendHeader($prefs); |
|
| 51 | - } else { |
|
| 52 | - $username = $_SERVER['PHP_AUTH_USER']; |
|
| 53 | - $password = $_SERVER['PHP_AUTH_PW']; |
|
| 54 | - |
|
| 55 | - //try to login |
|
| 56 | - $res = User::current()->loginByUsername($username, $password); |
|
| 57 | - |
|
| 58 | - if ($res['success'] !== true) { |
|
| 59 | - //send http header again |
|
| 60 | - self::sendHeader($prefs); |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - protected static function sendHeader (Preferences $prefs) { |
|
| 66 | - $realm_name = $prefs->get("realm_name", "Website"); |
|
| 67 | - |
|
| 68 | - //send http header, so browser will show a login form |
|
| 69 | - header('WWW-Authenticate: Basic realm="' . $realm_name . '"'); |
|
| 70 | - header('HTTP/1.0 401 Unauthorized'); |
|
| 71 | - |
|
| 72 | - //text which will be sended, if user clicks on abort |
|
| 73 | - echo $prefs->get("abort_text", "<h1>401 Authorization Required</h1>"); |
|
| 74 | - |
|
| 75 | - ob_end_flush(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 30 | + //http://php.net/manual/de/features.http-auth.php |
|
| 31 | + |
|
| 32 | + public static function headerEvent () { |
|
| 33 | + //get preferences first |
|
| 34 | + $prefs = new Preferences("plugin_httpauth"); |
|
| 35 | + |
|
| 36 | + $activated = $prefs->get("activated", true); |
|
| 37 | + |
|
| 38 | + if (!$activated) { |
|
| 39 | + return; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + //check, if user is logged in |
|
| 43 | + if (User::current()->isLoggedIn()) { |
|
| 44 | + //http auth is not required, because user is already logged in |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + //check, if credentials was already send |
|
| 49 | + if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 50 | + self::sendHeader($prefs); |
|
| 51 | + } else { |
|
| 52 | + $username = $_SERVER['PHP_AUTH_USER']; |
|
| 53 | + $password = $_SERVER['PHP_AUTH_PW']; |
|
| 54 | + |
|
| 55 | + //try to login |
|
| 56 | + $res = User::current()->loginByUsername($username, $password); |
|
| 57 | + |
|
| 58 | + if ($res['success'] !== true) { |
|
| 59 | + //send http header again |
|
| 60 | + self::sendHeader($prefs); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + protected static function sendHeader (Preferences $prefs) { |
|
| 66 | + $realm_name = $prefs->get("realm_name", "Website"); |
|
| 67 | + |
|
| 68 | + //send http header, so browser will show a login form |
|
| 69 | + header('WWW-Authenticate: Basic realm="' . $realm_name . '"'); |
|
| 70 | + header('HTTP/1.0 401 Unauthorized'); |
|
| 71 | + |
|
| 72 | + //text which will be sended, if user clicks on abort |
|
| 73 | + echo $prefs->get("abort_text", "<h1>401 Authorization Required</h1>"); |
|
| 74 | + |
|
| 75 | + ob_end_flush(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | 79 | } |
| 80 | 80 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | //http://php.net/manual/de/features.http-auth.php |
| 31 | 31 | |
| 32 | - public static function headerEvent () { |
|
| 32 | + public static function headerEvent() { |
|
| 33 | 33 | //get preferences first |
| 34 | 34 | $prefs = new Preferences("plugin_httpauth"); |
| 35 | 35 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - protected static function sendHeader (Preferences $prefs) { |
|
| 65 | + protected static function sendHeader(Preferences $prefs) { |
|
| 66 | 66 | $realm_name = $prefs->get("realm_name", "Website"); |
| 67 | 67 | |
| 68 | 68 | //send http header, so browser will show a login form |