aboutsummaryrefslogtreecommitdiff
path: root/app/Models
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
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')
-rw-r--r--app/Models/Auth.php40
-rw-r--r--app/Models/Context.php4
-rw-r--r--app/Models/Factory.php16
-rw-r--r--app/Models/Feed.php3
4 files changed, 38 insertions, 25 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';
+ }
}
diff --git a/app/Models/Context.php b/app/Models/Context.php
index c8a65063a..9bbad9857 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -41,10 +41,10 @@ class FreshRSS_Context {
*/
public static function init() {
// Init configuration.
- $current_user = Minz_Session::param('currentUser');
try {
- self::$conf = new FreshRSS_Configuration($current_user);
+ self::$conf = Minz_Configuration::get('user');
} catch(Minz_Exception $e) {
+ $current_user = Minz_Session::param('currentUser', '_');
Minz_Log::error('Cannot load configuration file of user `' . $current_user . '`');
die($e->getMessage());
}
diff --git a/app/Models/Factory.php b/app/Models/Factory.php
index 91cb84998..db09d155d 100644
--- a/app/Models/Factory.php
+++ b/app/Models/Factory.php
@@ -3,8 +3,8 @@
class FreshRSS_Factory {
public static function createFeedDao($username = null) {
- $db = Minz_Configuration::dataBase();
- if ($db['type'] === 'sqlite') {
+ $conf = Minz_Configuration::get('system');
+ if ($conf->db['type'] === 'sqlite') {
return new FreshRSS_FeedDAOSQLite($username);
} else {
return new FreshRSS_FeedDAO($username);
@@ -12,8 +12,8 @@ class FreshRSS_Factory {
}
public static function createEntryDao($username = null) {
- $db = Minz_Configuration::dataBase();
- if ($db['type'] === 'sqlite') {
+ $conf = Minz_Configuration::get('system');
+ if ($conf->db['type'] === 'sqlite') {
return new FreshRSS_EntryDAOSQLite($username);
} else {
return new FreshRSS_EntryDAO($username);
@@ -21,8 +21,8 @@ class FreshRSS_Factory {
}
public static function createStatsDAO($username = null) {
- $db = Minz_Configuration::dataBase();
- if ($db['type'] === 'sqlite') {
+ $conf = Minz_Configuration::get('system');
+ if ($conf->db['type'] === 'sqlite') {
return new FreshRSS_StatsDAOSQLite($username);
} else {
return new FreshRSS_StatsDAO($username);
@@ -30,8 +30,8 @@ class FreshRSS_Factory {
}
public static function createDatabaseDAO($username = null) {
- $db = Minz_Configuration::dataBase();
- if ($db['type'] === 'sqlite') {
+ $conf = Minz_Configuration::get('system');
+ if ($conf->db['type'] === 'sqlite') {
return new FreshRSS_DatabaseDAOSQLite($username);
} else {
return new FreshRSS_DatabaseDAO($username);
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 8f4b60097..071eafdf6 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -39,8 +39,9 @@ class FreshRSS_Feed extends Minz_Model {
}
public function hash() {
+ $conf = Minz_Configuration::get('system');
if ($this->hash === null) {
- $this->hash = hash('crc32b', Minz_Configuration::salt() . $this->url);
+ $this->hash = hash('crc32b', $conf->general['salt'] . $this->url);
}
return $this->hash;
}