Sfoglia il codice sorgente

Bouge anon_access dans config.php

L'accès anonyme n'est pas au niveau utilisateur mais au niveau global.
Bouge FreshRSS_Configuration::conf->anonAccess() qui était stocké dans
*_user.php vers Minz_Configuration::allowAnonymous() stocké dans
config.php
Contribue à https://github.com/marienfressinaud/FreshRSS/issues/126
+ autres optimisations
Contribue à https://github.com/marienfressinaud/FreshRSS/issues/260
Alexandre Alapetite 12 anni fa
parent
commit
9ac1496d63

+ 7 - 4
app/Controllers/configureController.php

@@ -398,15 +398,13 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 			$current_token = $this->view->conf->token();
 
 			$mail = Minz_Request::param('mail_login', false);
-			$anon = Minz_Request::param('anon_access', 'no');
 			$token = Minz_Request::param('token', $current_token);
+
 			$this->view->conf->_mailLogin($mail);
-			$this->view->conf->_anonAccess($anon);
 			$this->view->conf->_token($token);
 
 			$values = array(
 				'mail_login' => $this->view->conf->mailLogin(),
-				'anon_access' => $this->view->conf->anonAccess(),
 				'token' => $this->view->conf->token(),
 			);
 
@@ -415,7 +413,12 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 			Minz_Session::_param('conf', $this->view->conf);
 			Minz_Session::_param('mail', $this->view->conf->mailLogin());
 
-			// notif
+			$anon = (bool)(Minz_Request::param('anon_access', false));
+			if ($anon != Minz_Configuration::allowAnonymous()) {
+				Minz_Configuration::_allowAnonymous($anon);
+				Minz_Configuration::writeFile();
+			}
+
 			$notif = array(
 				'type' => 'good',
 				'content' => Minz_Translate::t('configuration_updated')

+ 3 - 3
app/Controllers/indexController.php

@@ -24,7 +24,7 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 		// check if user is log in
 		if(login_is_conf ($this->view->conf) &&
 				!is_logged() &&
-				$this->view->conf->anonAccess() === 'no' &&
+				!Minz_Configuration::allowAnonymous() &&
 				!($output === 'rss' && $token_is_ok)) {
 			return;
 		}
@@ -36,8 +36,8 @@ class FreshRSS_index_Controller extends Minz_ActionController {
 			$params['search'] = urlencode ($params['search']);
 		}
 		if (login_is_conf($this->view->conf) &&
-				$this->view->conf->anonAccess() === 'no' &&
-				$token != '') {
+				!Minz_Configuration::allowAnonymous() &&
+				$token !== '') {
 			$params['token'] = $token;
 		}
 		$this->view->rss_url = array (

+ 0 - 12
app/Models/Configuration.php

@@ -20,7 +20,6 @@ class FreshRSS_Configuration extends Minz_Model {
 	private $mark_when = array ();
 	private $sharing = array ();
 	private $theme;
-	private $anon_access;
 	private $token;
 	private $auto_load_more;
 	private $topline_read;
@@ -52,7 +51,6 @@ class FreshRSS_Configuration extends Minz_Model {
 		$this->_sharing ($confDAO->sharing);
 		$this->_theme ($confDAO->theme);
 		FreshRSS_Themes::setThemeId ($confDAO->theme);
-		$this->_anonAccess ($confDAO->anon_access);
 		$this->_token ($confDAO->token);
 		$this->_autoLoadMore ($confDAO->auto_load_more);
 		$this->_topline_read ($confDAO->topline_read);
@@ -132,9 +130,6 @@ class FreshRSS_Configuration extends Minz_Model {
 	public function theme () {
 		return $this->theme;
 	}
-	public function anonAccess () {
-		return $this->anon_access;
-	}
 	public function token () {
 		return $this->token;
 	}
@@ -283,13 +278,6 @@ class FreshRSS_Configuration extends Minz_Model {
 	public function _theme ($value) {
 		$this->theme = $value;
 	}
-	public function _anonAccess ($value) {
-		if ($value == 'yes') {
-			$this->anon_access = 'yes';
-		} else {
-			$this->anon_access = 'no';
-		}
-	}
 	public function _token ($value) {
 		$this->token = $value;
 	}

+ 0 - 4
app/Models/ConfigurationDAO.php

@@ -38,7 +38,6 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray {
 		'print' => true
 	);
 	public $theme = 'default';
-	public $anon_access = 'no';
 	public $token = '';
 	public $auto_load_more = 'yes';
 	public $topline_read = 'yes';
@@ -108,9 +107,6 @@ class FreshRSS_ConfigurationDAO extends Minz_ModelArray {
 		if (isset ($this->array['theme'])) {
 			$this->theme = $this->array['theme'];
 		}
-		if (isset ($this->array['anon_access'])) {
-			$this->anon_access = $this->array['anon_access'];
-		}
 		if (isset ($this->array['token'])) {
 			$this->token = $this->array['token'];
 		}

+ 1 - 1
app/layout/header.phtml

@@ -21,7 +21,7 @@
 	<div class="item search">
 		<?php if(!login_is_conf ($this->conf) ||
 		         is_logged() ||
-		         $this->conf->anonAccess() == 'yes') { ?>
+		         Minz_Configuration::allowAnonymous()) { ?>
 		<form action="<?php echo _url ('index', 'index'); ?>" method="get">
 			<div class="stick">
 				<?php $search = Minz_Request::param ('search', ''); ?>

+ 1 - 1
app/views/configure/users.phtml

@@ -50,7 +50,7 @@
 		<div class="form-group">
 			<div class="group-controls">
 				<label class="checkbox" for="anon_access">
-					<input type="checkbox" name="anon_access" id="anon_access" value="yes"<?php echo $this->conf->anonAccess() == 'yes' ? ' checked="checked"' : ''; ?> />
+					<input type="checkbox" name="anon_access" id="anon_access" value="1"<?php echo Minz_Configuration::allowAnonymous() ? ' checked="checked"' : ''; ?> />
 					<?php echo Minz_Translate::t('allow_anonymous'); ?>
 				</label>
 			</div>

+ 1 - 1
app/views/index/index.phtml

@@ -7,7 +7,7 @@ $token_is_ok = ($token != '' && $token == $token_param);
 
 if(!login_is_conf ($this->conf) ||
    is_logged() ||
-   $this->conf->anonAccess() == 'yes' ||
+   Minz_Configuration::allowAnonymous() ||
    ($output == 'rss' && $token_is_ok)) {
 	if($output == 'rss') {
 		$this->renderHelper ('view/rss_view');

+ 2 - 1
data/.gitignore

@@ -3,4 +3,5 @@ config.php
 *_user.php
 *.sqlite
 touch.txt
-no-cache.txt
+no-cache.txt
+*.bak

+ 46 - 12
lib/Minz/Configuration.php

@@ -52,6 +52,7 @@ class Minz_Configuration {
 	private static $delay_cache = 3600;
 	private static $default_user = '';
 	private static $current_user = '';
+	private static $allow_anonymous = false;
 
 	private static $db = array (
 		'host' => false,
@@ -99,6 +100,12 @@ class Minz_Configuration {
 	public static function isAdmin () {
 		return self::$current_user === self::$default_user;
 	}
+	public static function allowAnonymous() {
+		return self::$allow_anonymous;
+	}
+	public static function _allowAnonymous($allow = false) {
+		self::$allow_anonymous = (bool)$allow;
+	}
 
 	/**
 	 * Initialise les variables de configuration
@@ -116,8 +123,25 @@ class Minz_Configuration {
 		}
 	}
 
+	public static function writeFile() {
+		$ini_array = array(
+			'general' => array(
+				'environment' => self::$environment,
+				'use_url_rewriting' => self::$use_url_rewriting,
+				'sel_application' => self::$sel_application,
+				'base_url' => self::$base_url,
+				'title' => self::$title,
+				'default_user' => self::$default_user,
+				'allow_anonymous' => self::$allow_anonymous,
+			),
+			'db' => self::$db,
+		);
+		@rename(DATA_PATH . self::CONF_PATH_NAME, DATA_PATH . self::CONF_PATH_NAME . '.bak');
+		return file_put_contents(DATA_PATH . self::CONF_PATH_NAME, "<?php\n return " . var_export($ini_array, true) . ';');
+	}
+
 	/**
-	 * Parse un fichier de configuration de type ".ini"
+	 * Parse un fichier de configuration
 	 * @exception Minz_FileNotExistException si le CONF_PATH_NAME n'existe pas
 	 * @exception Minz_BadConfigurationException si CONF_PATH_NAME mal formaté
 	 */
@@ -158,12 +182,15 @@ class Minz_Configuration {
 
 		if (isset ($general['environment'])) {
 			switch ($general['environment']) {
+			case Minz_Configuration::SILENT:
 			case 'silent':
 				self::$environment = Minz_Configuration::SILENT;
 				break;
+			case Minz_Configuration::DEVELOPMENT:
 			case 'development':
 				self::$environment = Minz_Configuration::DEVELOPMENT;
 				break;
+			case Minz_Configuration::PRODUCTION:
 			case 'production':
 				self::$environment = Minz_Configuration::PRODUCTION;
 				break;
@@ -204,6 +231,9 @@ class Minz_Configuration {
 			self::$default_user = $general['default_user'];
 			self::$current_user = self::$default_user;
 		}
+		if (isset ($general['allow_anonymous'])) {
+			self::$allow_anonymous = (bool)($general['allow_anonymous']);
+		}
 
 		// Base de données
 		$db = false;
@@ -245,17 +275,21 @@ class Minz_Configuration {
 		}
 	}
 
-	private static function setReporting () {
-		if (self::environment () == self::DEVELOPMENT) {
-			error_reporting (E_ALL);
-			ini_set ('display_errors','On');
-			ini_set('log_errors', 'On');
-		} elseif (self::environment () == self::PRODUCTION) {
-			error_reporting(E_ALL);
-			ini_set('display_errors','Off');
-			ini_set('log_errors', 'On');
-		} else {
-			error_reporting(0);
+	private static function setReporting() {
+		switch (self::$environment) {
+			case self::PRODUCTION:
+				error_reporting(E_ALL);
+				ini_set('display_errors','Off');
+				ini_set('log_errors', 'On');
+				break;
+			case self::DEVELOPMENT:
+				error_reporting(E_ALL);
+				ini_set('display_errors','On');
+				ini_set('log_errors', 'On');
+				break;
+			case self::SILENT:
+				error_reporting(0);
+				break;
 		}
 	}
 }