Browse Source

Mode anonyme pour connexion avec formulaire

Contribue à https://github.com/marienfressinaud/FreshRSS/issues/361
Alexandre Alapetite 12 years ago
parent
commit
41033768c3
3 changed files with 10 additions and 19 deletions
  1. 1 1
      app/Controllers/usersController.php
  2. 4 14
      app/views/configure/users.phtml
  3. 5 4
      lib/Minz/Configuration.php

+ 1 - 1
app/Controllers/usersController.php

@@ -57,8 +57,8 @@ class FreshRSS_users_Controller extends Minz_ActionController {
 				$auth_type = Minz_Request::param('auth_type', 'none');
 				if ($anon != Minz_Configuration::allowAnonymous() ||
 					$auth_type != Minz_Configuration::authType()) {
-					Minz_Configuration::_allowAnonymous($anon);
 					Minz_Configuration::_authType($auth_type);
+					Minz_Configuration::_allowAnonymous($anon);
 					$ok &= Minz_Configuration::writeFile();
 				}
 			}

+ 4 - 14
app/views/configure/users.phtml

@@ -58,20 +58,11 @@
 			</div>
 		</div>
 
-		<div class="form-group form-actions">
-			<div class="group-controls">
-				<button type="submit" class="btn btn-important"><?php echo Minz_Translate::t('save'); ?></button>
-				<button type="reset" class="btn"><?php echo Minz_Translate::t('cancel'); ?></button>
-			</div>
-		</div>
-
-		<?php if (Minz_Configuration::authType() === 'persona') { ?>
-
-		<legend>Mozilla Persona</legend>
 		<div class="form-group">
 			<div class="group-controls">
 				<label class="checkbox" for="anon_access">
-					<input type="checkbox" name="anon_access" id="anon_access" value="1"<?php echo Minz_Configuration::allowAnonymous() ? ' checked="checked"' : ''; ?> />
+					<input type="checkbox" name="anon_access" id="anon_access" value="1"<?php echo Minz_Configuration::allowAnonymous() ? ' checked="checked"' : '',
+						Minz_Configuration::canLogIn() ? '' : ' disabled="disabled"'; ?> />
 					<?php echo Minz_Translate::t('allow_anonymous', Minz_Configuration::defaultUser()); ?>
 				</label>
 			</div>
@@ -81,7 +72,8 @@
 			<label class="group-name" for="token"><?php echo Minz_Translate::t('auth_token'); ?></label>
 			<?php $token = $this->conf->token; ?>
 			<div class="group-controls">
-				<input type="text" id="token" name="token" value="<?php echo $token; ?>"  placeholder="<?php echo Minz_Translate::t('blank_to_disable'); ?>"/>
+				<input type="text" id="token" name="token" value="<?php echo $token; ?>"  placeholder="<?php echo Minz_Translate::t('blank_to_disable'); ?>"<?php
+					echo Minz_Configuration::canLogIn() ? '' : ' disabled="disabled"'; ?> />
 				<?php echo FreshRSS_Themes::icon('help'); ?> <?php echo Minz_Translate::t('explain_token', Minz_Url::display(null, 'html', true), $token); ?>
 			</div>
 		</div>
@@ -92,8 +84,6 @@
 				<button type="reset" class="btn"><?php echo Minz_Translate::t('cancel'); ?></button>
 			</div>
 		</div>
-
-		<?php } ?>
 	</form>
 
 	<form method="post" action="<?php echo _url('users', 'delete'); ?>">

+ 5 - 4
lib/Minz/Configuration.php

@@ -113,7 +113,7 @@ class Minz_Configuration {
 	}
 
 	public static function _allowAnonymous($allow = false) {
-		self::$allow_anonymous = (bool)$allow;
+		self::$allow_anonymous = ((bool)$allow) && self::canLogIn();
 	}
 	public static function _authType($value) {
 		$value = strtolower($value);
@@ -125,6 +125,7 @@ class Minz_Configuration {
 				self::$auth_type = $value;
 				break;
 		}
+		self::_allowAnonymous(self::$allow_anonymous);
 	}
 
 	/**
@@ -252,12 +253,12 @@ class Minz_Configuration {
 		if (isset ($general['default_user'])) {
 			self::$default_user = $general['default_user'];
 		}
-		if (isset ($general['allow_anonymous'])) {
-			self::$allow_anonymous = ((bool)($general['allow_anonymous'])) && ($general['allow_anonymous'] !== 'no');
-		}
 		if (isset ($general['auth_type'])) {
 			self::_authType($general['auth_type']);
 		}
+		if (isset ($general['allow_anonymous'])) {
+			self::$allow_anonymous = ((bool)($general['allow_anonymous'])) && ($general['allow_anonymous'] !== 'no');
+		}
 
 		// Base de données
 		if (isset ($ini_array['db'])) {