ソースを参照

Edit cookie_duration from GUI (#2137)

* Use cookie_duration correctly

* WIP allow cookie_duration to be modified from GUI

* Allow cookie_duration to actually be updated

* Update view to properly display cookie_duration

* Add new strings in Translation Files

* Fix typo

* Fix trailing whitespace

* I18n: French translation

* I18n fr: Forgot todo
Patrick Crandol 7 年 前
コミット
ebb9ee0873

+ 2 - 0
app/Controllers/configureController.php

@@ -308,6 +308,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 	 *   - user limit (default: 1)
 	 *   - user category limit (default: 16384)
 	 *   - user feed limit (default: 16384)
+	 *   - user login duration for form auth (default: 2592000)
 	 */
 	public function systemAction() {
 		if (!FreshRSS_Auth::hasAccess('admin')) {
@@ -318,6 +319,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController {
 			$limits['max_registrations'] = Minz_Request::param('max-registrations', 1);
 			$limits['max_feeds'] = Minz_Request::param('max-feeds', 16384);
 			$limits['max_categories'] = Minz_Request::param('max-categories', 16384);
+			$limits['cookie_duration'] = Minz_Request::param('cookie-duration', 2592000);
 			FreshRSS_Context::$system_conf->limits = $limits;
 			FreshRSS_Context::$system_conf->title = Minz_Request::param('instance-name', 'FreshRSS');
 			FreshRSS_Context::$system_conf->auto_update_url = Minz_Request::param('auto-update-url', false);

+ 6 - 5
app/Models/Auth.php

@@ -233,9 +233,10 @@ class FreshRSS_FormAuth {
 
 		$token_file = DATA_PATH . '/tokens/' . $token . '.txt';
 		$mtime = @filemtime($token_file);
-		if ($mtime + 2629744 < time()) {
-			// Token has expired (> 1 month) or does not exist.
-			// TODO: 1 month -> use a configuration instead
+		$limits = $conf->limits;
+		$cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration'];
+		if ($mtime + $cookie_duration < time()) {
+			// Token has expired (> cookie_duration) or does not exist.
 			@unlink($token_file);
 			return array();
 		}
@@ -256,7 +257,7 @@ class FreshRSS_FormAuth {
 		}
 
 		$limits = $conf->limits;
-		$cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration'];
+		$cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration'];
 		$expire = time() + $cookie_duration;
 		Minz_Session::setLongTermCookie('FreshRSS_login', $token, $expire);
 		return $token;
@@ -277,7 +278,7 @@ class FreshRSS_FormAuth {
 	public static function purgeTokens() {
 		$conf = Minz_Configuration::get('system');
 		$limits = $conf->limits;
-		$cookie_duration = empty($limits['cookie_duration']) ? 2629744 : $limits['cookie_duration'];
+		$cookie_duration = empty($limits['cookie_duration']) ? 2592000 : $limits['cookie_duration'];
 		$oldest = time() - $cookie_duration;
 		foreach (new DirectoryIterator(DATA_PATH . '/tokens/') as $file_info) {
 			// $extension = $file_info->getExtension(); doesn't work in PHP < 5.3.7

+ 3 - 0
app/Models/ConfigurationSetter.php

@@ -335,6 +335,9 @@ class FreshRSS_ConfigurationSetter {
 	private function _limits(&$data, $values) {
 		$max_small_int = 16384;
 		$limits_keys = array(
+			'cookie_duration' => array(
+				'min' => 0,
+			),
 			'cache_duration' => array(
 				'min' => 0,
 			),

+ 9 - 5
app/i18n/cz/admin.php

@@ -157,11 +157,15 @@ return array(
 		'top_feed' => 'Top ten kanálů',
 	),
 	'system' => array(
-		'_' => 'System configuration',	//TODO - Translation
-		'auto-update-url' => 'Auto-update server URL',	//TODO - Translation
-		'instance-name' => 'Instance name',	//TODO - Translation
-		'max-categories' => 'Categories per user limit',	//TODO - Translation
-		'max-feeds' => 'Feeds per user limit',	//TODO - Translation
+		'_' => 'System configuration', //TODO - Translation
+		'auto-update-url' => 'Auto-update server URL', //TODO - Translation
+		'cookie-duration' => array(
+			'help' => 'in seconds', //TODO - Translation
+			'number' => 'Duration to keep logged in', //TODO - Translation
+		),
+		'instance-name' => 'Instance name', //TODO - Translation
+		'max-categories' => 'Categories per user limit', //TODO - Translation
+		'max-feeds' => 'Feeds per user limit', //TODO - Translation
 		'registration' => array(
 			'help' => '0 znamená žádná omezení účtu',
 			'number' => 'Maximální počet účtů',

+ 4 - 0
app/i18n/de/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Dein Reader Name',
 		'max-categories' => 'Anzahl erlaubter Kategorien pro Benutzer',
 		'max-feeds' => 'Anzahl erlaubter Feeds pro Benutzer',
+		'cookie-duration' => array(
+			'help' => 'in Sekunden',
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 meint, dass es kein Account Limit gibt',
 			'number' => 'Maximale Anzahl von Accounts',

+ 4 - 0
app/i18n/en/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Instance name',
 		'max-categories' => 'Categories per user limit',
 		'max-feeds' => 'Feeds per user limit',
+		'cookie-duration' => array(
+			'help' => 'in seconds',
+			'number' => 'Duration to keep logged in',
+		),
 		'registration' => array(
 			'help' => '0 means that there is no account limit',
 			'number' => 'Max number of accounts',

+ 4 - 0
app/i18n/es/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Nombre de la fuente',
 		'max-categories' => 'Límite de categorías por usuario',
 		'max-feeds' => 'Límite de fuentes por usuario',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 significa que no hay límite en la cuenta',
 			'number' => 'Número máximo de cuentas',

+ 4 - 0
app/i18n/fr/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Nom de l’instance',
 		'max-categories' => 'Limite de catégories par utilisateur',
 		'max-feeds' => 'Limite de flux par utilisateur',
+		'cookie-duration' => array(
+			'help' => 'en secondes',
+			'number' => 'Durée avant expiration de la session',
+		),
 		'registration' => array(
 			'help' => 'Un chiffre de 0 signifie que l’on peut créer un nombre infini de comptes',
 			'number' => 'Nombre max de comptes',

+ 9 - 5
app/i18n/he/admin.php

@@ -157,11 +157,15 @@ return array(
 		'top_feed' => 'עשרת ההזנות המובילות',
 	),
 	'system' => array(
-		'_' => 'System configuration',	//TODO - Translation
-		'auto-update-url' => 'Auto-update server URL',	//TODO - Translation
-		'instance-name' => 'Instance name',	//TODO - Translation
-		'max-categories' => 'Categories per user limit',	//TODO - Translation
-		'max-feeds' => 'Feeds per user limit',	//TODO - Translation
+		'_' => 'System configuration', //TODO - Translation
+		'auto-update-url' => 'Auto-update server URL', //TODO - Translation
+		'cookie-duration' => array(
+			'help' => 'in seconds', //TODO - Translation
+			'number' => 'Duration to keep logged in', //TODO - Translation
+		),
+		'instance-name' => 'Instance name', //TODO - Translation
+		'max-categories' => 'Categories per user limit', //TODO - Translation
+		'max-feeds' => 'Feeds per user limit', //TODO - Translation
 		'registration' => array(
 			'help' => '0 means that there is no account limit',	//TODO - Translation
 			'number' => 'Max number of accounts',	//TODO - Translation

+ 4 - 0
app/i18n/it/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Nome istanza',
 		'max-categories' => 'Limite categorie per utente',
 		'max-feeds' => 'Limite feeds per utente',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 significa che non esiste limite sui profili',
 			'number' => 'Numero massimo di profili',

+ 4 - 0
app/i18n/kr/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => '인스턴스 이름',
 		'max-categories' => '사용자별 카테고리 개수 제한',
 		'max-feeds' => '사용자별 피드 개수 제한',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0: 제한 없음',
 			'number' => '계정 최대 개수',

+ 4 - 0
app/i18n/nl/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Voorbeeld naam',
 		'max-categories' => 'Categoriën limiet per gebruiker',
 		'max-feeds' => 'Feed limiet per gebruiker',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 betekent geen account limiet',
 			'number' => 'Maximum aantal accounts',

+ 4 - 0
app/i18n/oc/admin.php

@@ -159,6 +159,10 @@ return array(
 	'system' => array(
 		'_' => 'Configuracion sistèma',
 		'auto-update-url' => 'URL del servici de mesa a jorn',
+		'cookie-duration' => array(
+			'help' => 'in seconds', //TODO - Translation
+			'number' => 'Duration to keep logged in', //TODO - Translation
+		),
 		'instance-name' => 'Nom de l’instància',
 		'max-categories' => 'Limita de categoria per utilizaire',
 		'max-feeds' => 'Limita de fluxes per utilizaire',

+ 4 - 0
app/i18n/pt-br/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Nome da instância',
 		'max-categories' => 'Limite de categorias por usuário',
 		'max-feeds' => 'Limite de Feeds por usuário',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 significa que não há limite para a conta',
 			'number' => 'Máximo número de contas',

+ 4 - 0
app/i18n/ru/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Название этого сервера',
 		'max-categories' => 'Количество категорий на пользователя',
 		'max-feeds' => 'Количество статей на пользователя',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 означает неограниченное количество пользователей',
 			'number' => 'Максимальное количество пользователей',

+ 4 - 0
app/i18n/tr/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => 'Örnek isim',
 		'max-categories' => 'Kullanıcı başına kategori limiti',
 		'max-feeds' => 'Kullanıcı başına akış limiti',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 sınır yok anlamındadır',
 			'number' => 'En fazla hesap sayısı',

+ 4 - 0
app/i18n/zh-cn/admin.php

@@ -162,6 +162,10 @@ return array(
 		'instance-name' => '实例名称',
 		'max-categories' => '每用户分类限制',
 		'max-feeds' => '每用户 RSS 源限制',
+		'cookie-duration' => array(
+			'help' => 'in seconds', // @todo translate
+			'number' => 'Duration to keep logged in', // @todo translate
+		),
 		'registration' => array(
 			'help' => '0 表示无账户数限制',
 			'number' => '最大账户数',

+ 8 - 0
app/views/configure/system.phtml

@@ -51,6 +51,14 @@
 			    <input type="number" id="max-categories" name="max-categories" value="<?php echo FreshRSS_Context::$system_conf->limits['max_categories']; ?>" min="1" data-leave-validation="<?php echo FreshRSS_Context::$system_conf->limits['max_categories']; ?>"/>
 			</div>
 		</div>
+		
+		<div class="form-group">
+			<label class="group-name" for="cookie-duration"><?php echo _t('admin.system.cookie-duration.number'); ?></label>
+			<div class="group-controls">
+				<input type="number" id="cookie-duration" name="cookie-duration" value="<?php echo FreshRSS_Context::$system_conf->limits['cookie_duration']; ?>" min="0" data-leave-validation="<?php echo FreshRSS_Context::$system_conf->limits['cookie_duration']; ?>"/>
+				<?php echo _i('help'); ?> <?php echo _t('admin.system.cookie-duration.help'); ?>
+			</div>
+		</div>
 
 		<div class="form-group form-actions">
 			<div class="group-controls">