This commit is contained in:
@ -39,25 +39,9 @@ function ensurePasswordModal() {
|
||||
<h2 id="passwordModalTitle">Password</h2>
|
||||
<p class="modal-subtitle" id="passwordModalSubtitle"></p>
|
||||
<p class="modal-hint" id="passwordModalHint"></p>
|
||||
<fieldset class="password-mode-fieldset" id="passwordModalModeFieldset">
|
||||
<legend>Password type</legend>
|
||||
<div class="password-mode-options">
|
||||
<label class="password-mode-option">
|
||||
<input type="radio" name="pw_mode" value="temporary" checked>
|
||||
<span class="password-mode-option-title">Temporary password</span>
|
||||
<span class="password-mode-option-desc">
|
||||
They sign in with the password below, then must choose their own password before they can continue. Use this when you share the password by message or in person.
|
||||
</span>
|
||||
</label>
|
||||
<label class="password-mode-option">
|
||||
<input type="radio" name="pw_mode" value="permanent">
|
||||
<span class="password-mode-option-title">Permanent password</span>
|
||||
<span class="password-mode-option-desc">
|
||||
This becomes their regular password. They are not asked to change it when signing in, until you reset it again.
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
<p class="modal-hint" id="passwordModalTempHint" style="display:none">
|
||||
They sign in with the password below, then must choose their own password before they can continue.
|
||||
</p>
|
||||
<div class="form-group" id="passwordModalOldGroup" style="display:none">
|
||||
<label for="pw_old_password">Current password</label>
|
||||
<input type="password" id="pw_old_password" autocomplete="current-password" placeholder="Your current password">
|
||||
@ -115,13 +99,9 @@ function openPasswordModal(options) {
|
||||
? 'You will stay signed in after saving. Use this password on your next login.'
|
||||
: signInHintForRole(role);
|
||||
|
||||
modal.querySelector('#passwordModalModeFieldset').style.display = isSelf ? 'none' : '';
|
||||
modal.querySelector('#passwordModalTempHint').style.display = isSelf ? 'none' : '';
|
||||
modal.querySelector('#passwordModalOldGroup').style.display = isSelf ? '' : 'none';
|
||||
|
||||
if (!isSelf) {
|
||||
modal.querySelector('input[name="pw_mode"][value="temporary"]').checked = true;
|
||||
}
|
||||
|
||||
modal.querySelector('#pw_old_password').value = '';
|
||||
modal.querySelector('#pw_new_password').value = '';
|
||||
modal.querySelector('#pw_new_password_confirm').value = '';
|
||||
@ -201,27 +181,23 @@ async function submitPasswordModal() {
|
||||
return;
|
||||
}
|
||||
|
||||
const mode = modal.querySelector('input[name="pw_mode"]:checked')?.value || 'temporary';
|
||||
const temporary = mode === 'temporary';
|
||||
const { userID, username } = modalContext;
|
||||
|
||||
const data = await apiPatch('users.php', {
|
||||
userID,
|
||||
password: newPassword,
|
||||
mustChangePassword: temporary ? 1 : 0,
|
||||
mustChangePassword: 1,
|
||||
});
|
||||
if (!data.success) throw new Error(data.error || 'Failed to reset password');
|
||||
|
||||
closePasswordModal();
|
||||
showToast(
|
||||
temporary
|
||||
? `Temporary password set for "${username}" — they must change it on next sign-in`
|
||||
: `Permanent password set for "${username}"`,
|
||||
`Temporary password set for "${username}" — they must change it on next sign-in`,
|
||||
'success'
|
||||
);
|
||||
|
||||
document.dispatchEvent(new CustomEvent('qdb:password-reset', {
|
||||
detail: { userID, mustChangePassword: data.mustChangePassword ?? (temporary ? 1 : 0) },
|
||||
detail: { userID, mustChangePassword: data.mustChangePassword ?? 1 },
|
||||
}));
|
||||
} catch (e) {
|
||||
showModalError(errEl, e.message);
|
||||
|
||||
Reference in New Issue
Block a user