From 8044c80f9dad0968104e058051f9a70060442027 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Thu, 12 Mar 2026 16:35:41 -0400 Subject: [PATCH] feat: make Remember Me a tri-state option (None/Yes/No) Change ZM_OPT_USE_REMEMBER_ME from a boolean to a tri-state string: - None: checkbox hidden, sessions persist for ZM_COOKIE_LIFETIME (old disabled) - Yes: checkbox shown and pre-checked by default - No: checkbox shown and unchecked by default (old enabled behavior) Update ConfigData.pm.in with new type definition, login.php to honor the checked state, and session/action handlers to recognize the new values. Migration in zm_update-1.39.4.sql maps old '1' to 'No' and '0' to 'None'. Co-Authored-By: Claude Opus 4.6 --- db/zm_update-1.39.4.sql | 19 +++++++++++++++++++ .../lib/ZoneMinder/ConfigData.pm.in | 19 +++++++++++-------- web/includes/actions/login.php | 2 +- web/includes/session.php | 2 +- web/skins/classic/views/login.php | 5 +++-- 5 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 db/zm_update-1.39.4.sql diff --git a/db/zm_update-1.39.4.sql b/db/zm_update-1.39.4.sql new file mode 100644 index 000000000..d871f17e4 --- /dev/null +++ b/db/zm_update-1.39.4.sql @@ -0,0 +1,19 @@ +-- +-- Convert ZM_OPT_USE_REMEMBER_ME from boolean to tri-state (None/Yes/No) +-- + +UPDATE Config SET + Value = CASE WHEN Value = '1' THEN 'No' ELSE 'None' END, + Type = 'string', + DefaultValue = 'None', + Hint = 'None|Yes|No', + Pattern = '(?^i:^([YyNn]))', + Format = ' $1 ', + Prompt = 'Show a "Remember Me" option on the login page', + Help = ' + Controls whether a "Remember Me" checkbox appears on the login page. + None: No checkbox is shown. Sessions always persist for ZM_COOKIE_LIFETIME. + Yes: Checkbox is shown and checked by default. Users may uncheck it for a session-only cookie. + No: Checkbox is shown and unchecked by default. Users may check it to persist the session. + ' +WHERE Name = 'ZM_OPT_USE_REMEMBER_ME'; diff --git a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in index cf4110875..2dd5bbcf9 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in +++ b/scripts/ZoneMinder/lib/ZoneMinder/ConfigData.pm.in @@ -537,18 +537,21 @@ our @options = ( }, { name => 'ZM_OPT_USE_REMEMBER_ME', - default => 'no', + default => 'None', description => 'Show a "Remember Me" option on the login page', help => q` - When enabled, a "Remember Me" checkbox will appear on the login - page. If the user does not check "Remember Me", the session - cookie will expire when the browser is closed. If checked, the - session will persist for the duration configured by - ZM_COOKIE_LIFETIME. When this option is disabled, sessions - always persist for ZM_COOKIE_LIFETIME as before. + Controls whether a "Remember Me" checkbox appears on the login page. + None: No checkbox is shown. Sessions always persist for ZM_COOKIE_LIFETIME. + Yes: Checkbox is shown and checked by default. Users may uncheck it for a session-only cookie. + No: Checkbox is shown and unchecked by default. Users may check it to persist the session. `, requires => [ { name=>'ZM_OPT_USE_AUTH', value=>'yes' } ], - type => $types{boolean}, + type => { + db_type => 'string', + hint => 'None|Yes|No', + pattern => qr|^([YyNn])|i, + format => q( $1 ) + }, category => 'auth', }, # Google reCaptcha settings diff --git a/web/includes/actions/login.php b/web/includes/actions/login.php index b03c7b33d..87e374df9 100644 --- a/web/includes/actions/login.php +++ b/web/includes/actions/login.php @@ -26,7 +26,7 @@ if ( ('login' == $action) && isset($_REQUEST['username']) && ( ZM_AUTH_TYPE == ' // if captcha existed, it was passed - if (defined('ZM_OPT_USE_REMEMBER_ME') && ZM_OPT_USE_REMEMBER_ME) { + if (defined('ZM_OPT_USE_REMEMBER_ME') && ZM_OPT_USE_REMEMBER_ME != 'None' && ZM_OPT_USE_REMEMBER_ME != '' && ZM_OPT_USE_REMEMBER_ME != '0') { if (!empty($_REQUEST['remember_me'])) { zm_setcookie('ZM_REMEMBER_ME', '1', array('expires' => time() + ZM_COOKIE_LIFETIME)); $_COOKIE['ZM_REMEMBER_ME'] = '1'; diff --git a/web/includes/session.php b/web/includes/session.php index 2258e02d0..936f0ce27 100644 --- a/web/includes/session.php +++ b/web/includes/session.php @@ -27,7 +27,7 @@ function zm_session_start() { ini_set('session.use_strict_mode', 1); $currentCookieParams = session_get_cookie_params(); - if (defined('ZM_OPT_USE_REMEMBER_ME') && ZM_OPT_USE_REMEMBER_ME && empty($_COOKIE['ZM_REMEMBER_ME'])) { + if (defined('ZM_OPT_USE_REMEMBER_ME') && ZM_OPT_USE_REMEMBER_ME != 'None' && ZM_OPT_USE_REMEMBER_ME != '' && ZM_OPT_USE_REMEMBER_ME != '0' && empty($_COOKIE['ZM_REMEMBER_ME'])) { $currentCookieParams['lifetime'] = 0; } else { $currentCookieParams['lifetime'] = ZM_COOKIE_LIFETIME; diff --git a/web/skins/classic/views/login.php b/web/skins/classic/views/login.php index c46eaae2f..32c6b1c1f 100644 --- a/web/skins/classic/views/login.php +++ b/web/skins/classic/views/login.php @@ -33,10 +33,11 @@ if ( defined('ZM_OPT_USE_AUTH') and ZM_OPT_USE_AUTH ) {
- + />