[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX][UX] (adminusers) : improve UX of 'user must change password' checkbox and password inputs

Benoit Grégoire (@benoitg) via TikiWiki-cvs <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6902288f6cfa2_2ce1c6c72895@gitlab-sidekiq-low-urgency-cpu-bound-v2-6b7cd465c4-jzmxf.mail>

Benoit Grégoire pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
2ea8995d by Landry Bitege at 2025-10-29T14:34:36+00:00
[FIX][UX] (adminusers) : improve UX of 'user must change password' checkbox and password inputs
---
* [FIX][UX] adminusers: improve UX of 'user must change password' checkbox and password inputs

See merge request tikiwiki/tiki!8438

- - - - -


3 changed files:

- lib/userslib.php
- templates/tiki-adminusers.tpl
- tiki-adminusers.php


Changes:

=====================================
lib/userslib.php
=====================================
@@ -7629,21 +7629,23 @@ class UsersLib extends TikiLib
     {
 
         $hash = password_hash($pass, PASSWORD_DEFAULT);
-        $new_pass_confirm = $this->now;
 
-        if ($pass_first_login) {                    // if true, set pass_confirm to force passord change upon next login
-            if (! empty($pass)) {
-                $query = 'update `users_users` set `hash`=? , `provpass`=?, `pass_confirm`=? where binary `login`=?';
-                $result = $this->query($query, [$hash, $pass, 0, $user]);
+        if (! empty($pass)) {
+            $query = 'update `users_users` set `hash`=?, `provpass`=?, `pass_confirm`=? where binary `login`=?';
+            // if true, set pass_confirm to force passord change upon next login
+            if ($pass_first_login) {
+                $params = [$hash, $pass, 0, $user];
             } else {
-                $query = 'update `users_users` set `pass_confirm`=? where binary `login`=?';
-                $result = $this->query($query, [0, $user]);
+                $params = [$hash, '', $this->now, $user];
             }
         } else {
-            $query = 'update `users_users` set `hash`=? ,`pass_confirm`=?, `provpass`=? where binary `login`=?';
-            $result = $this->query($query, [$hash, $new_pass_confirm, '', $user]);
+            // No password change, only update confirmation flag
+            $query = 'update `users_users` set `pass_confirm`=? where binary `login`=?';
+            $params = [$pass_first_login ? 0 : $this->now, $user];
         }
 
+        $result = $this->query($query, $params);
+
         if ($result && $result->numRows() === 1) {
             // invalidate the cache so that after a fresh install, the admin (who has no user details at the install) can log in
             $cachelib = TikiLib::lib('cache');


=====================================
templates/tiki-adminusers.tpl
=====================================
@@ -410,7 +410,7 @@
                 {remarksbox type="warning" title="{tr}Warning: User Encryption is Active{/tr}"}
                 {tr}The feature User Encryption stores encrypted user information, such as password used to connect to external systems.
                     If the password is changed, it will destroy the user's decryption key, and make the data unreadable.
-                    The user will be forced to re-enter the passwords and other data that may be encrypted.{/tr}</a>.
+                    The user will be forced to re-enter the passwords and other data that may be encrypted.{/tr}
                 {/remarksbox}
             {/if}
             {if isset($userinfo.userId) && $userinfo.userId}
@@ -429,7 +429,7 @@
             {/if}
             {if $prefs.feature_intertiki eq 'y' and not empty($prefs.feature_intertiki_mymaster)}
                 {remarksbox type="info" title="{tr}Intertiki Enabled{/tr}"}
-                {tr _0=$prefs.feature_intertiki_mymaster|escape}This Tiki is an Intertiki Client so user information must be edited on the Intertiki Master "%0"{/tr}</a>.
+                {tr _0=$prefs.feature_intertiki_mymaster|escape}This Tiki is an Intertiki Client so user information must be edited on the Intertiki Master "%0"{/tr}
                 {/remarksbox}
             {elseif $userinfo.editable}
                 <form action="tiki-adminusers.php" method="post" enctype="multipart/form-data" name="RegForm" autocomplete="off">
@@ -498,10 +498,10 @@
                                 <input type="password" class="form-control" name="passAgain" id="pass2" placeholder="{tr}Password{/tr}" autocomplete="new-password">
                                 <div id="mypassword2_text">
                                     <div id="match" style="display:none">
-                                        {icon name='ok' istyle='color:#0ca908'} {tr}Passwords match{/tr}
+                                        {icon name='ok' style='color:#0ca908'} {tr}Passwords match{/tr}
                                     </div>
                                     <div id="nomatch" style="display:none">
-                                        {icon name='error' istyle='color:#ff0000'} {tr}Passwords do not match{/tr}
+                                        {icon name='error' style='color:#ff0000'} {tr}Passwords do not match{/tr}
                                     </div>
                                 </div>
                             </div>
@@ -522,7 +522,7 @@
                                     <div class="form-check">
                                         <label class="form-check-label">
                                             <input class="form-check-input" type="checkbox" name="pass_first_login"
-                                                {if isset($userinfo.pass_confirm) && $userinfo.pass_confirm eq '0' or not empty($smarty.request.pass_first_login) or $prefs.user_must_change_password_set_default_on eq 'y'}
+                                                {if (isset($userinfo.pass_confirm) && $userinfo.pass_confirm eq '0') or (not empty($smarty.request.pass_first_login)) or ($prefs.user_must_change_password_set_default_on eq 'y')}
                                                     checked="checked"
                                                 {/if}>
                                             {tr}User must change password at next login{/tr}
@@ -566,7 +566,7 @@
                                 <div class="form-check">
                                     <label class="form-check-label">
                                         <input class="form-check-input" type="checkbox" name="insert_user_tracker_item"
-                                               {if not empty($smarty.request.insert_user_tracker_item or $prefs.user_add_tracker_item_set_default_on eq 'y')}checked="checked"{/if}>
+                                               {if (not empty($smarty.request.insert_user_tracker_item)) or $prefs.user_add_tracker_item_set_default_on eq 'y'}checked="checked"{/if}>
                                         {tr}Add a user tracker item for this user{/tr}
                                     </label>
                                 </div>


=====================================
tiki-adminusers.php
=====================================
@@ -291,10 +291,10 @@ if (isset($_REQUEST['batch']) && is_uploaded_file($_FILES['csvlist']['tmp_name']
         $errors[] = tra('Email validation requested but email address not set');
         $AddUser = false;
     }
-    if ($_REQUEST['pass'] != $_REQUEST['passAgain']) {
-        $errors[] = tra('The passwords do not match');
+    if ($_REQUEST['pass'] !== $_REQUEST['passAgain']) {
+        $errors[] = tra('Passwords do not match');
         $AddUser = false;
-    } elseif (empty($_REQUEST['pass']) && empty($_REQUEST['genepass'])) {
+    } elseif (empty($_REQUEST['pass']) && empty($_REQUEST['genepass']) && empty($_REQUEST['pass_first_login'])) {
         $errors[] = tra('Password not set');
         $AddUser = false;
     }
@@ -388,9 +388,7 @@ if (isset($_REQUEST['batch']) && is_uploaded_file($_FILES['csvlist']['tmp_name']
                 }
             } else {
                 $errors[] = sprintf(
-                    tra('Impossible to create new %s with %s %s.'),
-                    tra('user'),
-                    tra('username'),
+                    tra('Impossible to create new user with username %s.'),
                     $_REQUEST['login']
                 );
             }
@@ -486,8 +484,7 @@ if (isset($_REQUEST['user']) and $_REQUEST['user']) {
                         $errors[] = tra('User login contains invalid characters.');
                     } elseif ($userlib->change_login($userinfo['login'], $_POST['login'])) {
                         Feedback::success(sprintf(
-                            tra('%s changed from %s to %s'),
-                            tra('Username'),
+                            tra('Username changed from %s to %s'),
                             $userinfo['login'],
                             $_POST['login']
                         ));
@@ -498,10 +495,10 @@ if (isset($_REQUEST['user']) and $_REQUEST['user']) {
                         );
 
                         $userinfo['login'] = $_POST['login'];
+                        $cookietab = '1';
                     } else {
                         $errors[] = sprintf(
-                            tra("Unable to change %s from %s to %s"),
-                            tra('login'),
+                            tra("Unable to change login from %s to %s"),
                             $userinfo['login'],
                             $_POST['login']
                         );
@@ -511,22 +508,42 @@ if (isset($_REQUEST['user']) and $_REQUEST['user']) {
         }
 
         $pass_first_login = (isset($_REQUEST['pass_first_login']) && $_REQUEST['pass_first_login'] == 'on');
-        if ((isset($_POST['pass']) && $_POST["pass"]) || $pass_first_login || (isset($_POST['genepass']) && $_POST['genepass'])) {
-            if ($_POST['pass'] != $_POST['passAgain']) {
-                Feedback::error(tra('The passwords do not match'));
+
+        if (! empty($_POST['pass']) || ! empty($_POST['genepass'])) {
+            if ($_POST['pass'] !== $_POST['passAgain']) {
+                Feedback::error(tra('Passwords do not match'));
             }
 
             if ($tiki_p_admin == 'y' || $tiki_p_admin_users == 'y' || $userinfo['login'] == $user) {
-                $newPass = $_POST['pass'] ? trim($_POST['pass']) : trim($_POST['genepass']);
-                $polerr = $userlib->check_password_policy($newPass);
-                if (strlen($polerr) > 0 && ! $pass_first_login) {
-                    Feedback::error($polerr);
-                } else {
-                    if ($userlib->change_user_password($userinfo['login'], $newPass, $pass_first_login)) {
-                        Feedback::success(sprintf(tra('%s modified successfully.'), tra('password')));
-                        $logslib->add_log('adminusers', 'changed password for ' . $_POST['login'], $user);
+                $newPass = $_POST['pass'] ? trim($_POST['pass']) : ($_POST['genepass'] ? trim($_POST['genepass']) : null);
+                if (! empty($newPass)) {
+                    $polerr = $userlib->check_password_policy($newPass);
+                    if (strlen($polerr) > 0) {
+                        Feedback::error($polerr);
                     } else {
-                        $errors[] = sprintf(tra('%s modification failed.'), tra('password'));
+                        if ($userlib->change_user_password($userinfo['login'], $newPass, $pass_first_login)) {
+                            Feedback::success(sprintf(tra('Password modified successfully.')));
+                            $cookietab = '1';
+                            $logslib->add_log('adminusers', 'changed password for ' . $_POST['login'], $user);
+                        } else {
+                            $errors[] = sprintf(tra('Password modification failed.'));
+                        }
+                    }
+                }
+            }
+        } elseif (empty($_POST['pass']) || empty($_POST['genepass'])) {
+            if ($tiki_p_admin == 'y' || $tiki_p_admin_users == 'y' || $userinfo['login'] == $user) {
+                if ($pass_first_login && $userinfo['pass_confirm'] !== 0) {
+                    if ($userlib->change_user_password($userinfo['login'], '', $pass_first_login)) {
+                        Feedback::success(sprintf(tra('Password reset required at next login has been enabled for %s.'), $_POST['login']));
+                        $cookietab = '1';
+                        $logslib->add_log('adminusers', 'Password reset required at next login has been enabled for ' . $_POST['login'], $user);
+                    }
+                } else if (! $pass_first_login && $userinfo['pass_confirm'] === 0) {
+                    if ($userlib->change_user_password($userinfo['login'], '', $pass_first_login)) {
+                        Feedback::success(sprintf(tra('Password reset requirement has been disabled for %s'), $_POST['login']));
+                        $cookietab = '1';
+                        $logslib->add_log('adminusers', 'Password reset requirement has been disabled for ' . $_POST['login'], $user);
                     }
                 }
             }
@@ -536,16 +553,16 @@ if (isset($_REQUEST['user']) and $_REQUEST['user']) {
             if ($userlib->change_user_email($userinfo['login'], $_POST['email'], '')) {
                 if ($prefs['login_is_email'] != 'y') {
                     Feedback::success(sprintf(
-                        tra('%s changed from %s to %s'),
-                        tra('Email'),
+                        tra('Email changed from %s to %s'),
                         $userinfo['email'],
                         $_POST['email']
                     ));
+                    $cookietab = '1';
                     $logslib->add_log('adminusers', 'changed email for' . $_POST['login'] . ' from ' . $userinfo['email'] . ' to ' . $_POST['email'], $user);
                 }
                 $userinfo['email'] = $_POST['email'];
             } else {
-                $errors[] = sprintf(tra('Impossible to change %s from %s to %s'), tra('email'), $userinfo['email'], $_POST['email']);
+                $errors[] = sprintf(tra('Impossible to change email from %s to %s'), $userinfo['email'], $_POST['email']);
             }
         }
         // check need_email_validation



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2ea8995d59e37c7f8026c559dcd5b51a6aafb91f

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/2ea8995d59e37c7f8026c559dcd5b51a6aafb91f
You're receiving this email because of your account on gitlab.com.

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.