aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Auth.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-05 16:54:16 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-01-05 16:54:16 +0100
commit51a71ec4b9d62528054be8faee1576a8fd6d37f6 (patch)
treef92299dd5314aef43e9e69e8fde317b9b7790213 /app/Models/Auth.php
parent7584364a4c2b407e97909e94ba274da62620abea (diff)
New configuration system (not working yet)
- Use only Minz_Configuration - register() method to load a new configuration file - get() to get a configuration - new exceptions related to configuration - fix a list configuration calls to have FRSS working Current problems to resolve: - How to handle configuration param verifications (i.e. check auth_type is a value from none, http_auth, persona or form) - We must use $conf = Minz_Configuration::get('system'); $general_conf = $conf->general; to access global system configuration which is quite annoying. How to change that? See https://github.com/FreshRSS/FreshRSS/issues/730
Diffstat (limited to 'app/Models/Auth.php')
-rw-r--r--app/Models/Auth.php40
1 files changed, 26 insertions, 14 deletions
diff --git a/app/Models/Auth.php b/app/Models/Auth.php
index 2971d65c8..84b4e3721 100644
--- a/app/Models/Auth.php
+++ b/app/Models/Auth.php
@@ -16,7 +16,8 @@ class FreshRSS_Auth {
self::$login_ok = Minz_Session::param('loginOk', false);
$current_user = Minz_Session::param('currentUser', '');
if ($current_user === '') {
- $current_user = Minz_Configuration::defaultUser();
+ $conf = Minz_Configuration::get('system');
+ $current_user = $conf->general['default_user'];
Minz_Session::_param('currentUser', $current_user);
}
@@ -40,7 +41,9 @@ class FreshRSS_Auth {
* @return boolean true if user can be connected, false else.
*/
private static function accessControl() {
- switch (Minz_Configuration::authType()) {
+ $conf = Minz_Configuration::get('system');
+ $auth_type = $conf->general['auth_type'];
+ switch ($auth_type) {
case 'form':
$credentials = FreshRSS_FormAuth::getCredentialsFromCookie();
$current_user = '';
@@ -79,22 +82,19 @@ class FreshRSS_Auth {
* Gives access to the current user.
*/
public static function giveAccess() {
- $current_user = Minz_Session::param('currentUser');
- try {
- $conf = new FreshRSS_Configuration($current_user);
- } catch(Minz_Exception $e) {
- die($e->getMessage());
- }
+ $user_conf = Minz_Configuration::get('user');
+ $system_conf = Minz_Configuration::get('system');
+ $auth_type = $system_conf->general['auth_type'];
- switch (Minz_Configuration::authType()) {
+ switch ($auth_type) {
case 'form':
- self::$login_ok = Minz_Session::param('passwordHash') === $conf->passwordHash;
+ self::$login_ok = Minz_Session::param('passwordHash') === $user_conf->passwordHash;
break;
case 'http_auth':
self::$login_ok = strcasecmp($current_user, httpAuthUser()) === 0;
break;
case 'persona':
- self::$login_ok = strcasecmp(Minz_Session::param('mail'), $conf->mail_login) === 0;
+ self::$login_ok = strcasecmp(Minz_Session::param('mail'), $user_conf->mail_login) === 0;
break;
case 'none':
self::$login_ok = true;
@@ -114,12 +114,14 @@ class FreshRSS_Auth {
* @return boolean true if user has corresponding access, false else.
*/
public static function hasAccess($scope = 'general') {
+ $conf = Minz_Configuration::get('system');
+ $default_user = $conf->general['default_user'];
$ok = self::$login_ok;
switch ($scope) {
case 'general':
break;
case 'admin':
- $ok &= Minz_Session::param('currentUser') === Minz_Configuration::defaultUser();
+ $ok &= Minz_Session::param('currentUser') === $default_user;
break;
default:
$ok = false;
@@ -133,9 +135,10 @@ class FreshRSS_Auth {
public static function removeAccess() {
Minz_Session::_param('loginOk');
self::$login_ok = false;
- Minz_Session::_param('currentUser', Minz_Configuration::defaultUser());
+ $conf = Minz_Configuration::get('system');
+ Minz_Session::_param('currentUser', $conf->general['default_user']);
- switch (Minz_Configuration::authType()) {
+ switch ($conf->general['auth_type']) {
case 'form':
Minz_Session::_param('passwordHash');
FreshRSS_FormAuth::deleteCookie();
@@ -151,6 +154,15 @@ class FreshRSS_Auth {
// TODO: extensions
}
}
+
+ /**
+ * Return if authentication is enabled on this instance of FRSS.
+ */
+ public static function accessNeedLogin() {
+ $conf = Minz_Configuration::get('system');
+ $auth_type = $conf->general['auth_type'];
+ return $auth_type === 'form' || $auth_type === 'persona';
+ }
}