Benutzerverwaltung: Passwort-Wiederholung gegen Tippfehler
Gilt beim Anlegen (Pflicht) und beim optionalen Passwort-Reset im Bearbeiten-Formular.
This commit is contained in:
@@ -10,6 +10,7 @@ interface UserForm {
|
|||||||
full_name: string;
|
full_name: string;
|
||||||
role: Role;
|
role: Role;
|
||||||
password: string; // bei Bearbeitung optional (leer = unverändert)
|
password: string; // bei Bearbeitung optional (leer = unverändert)
|
||||||
|
passwordRepeat: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EMPTY_FORM: UserForm = {
|
const EMPTY_FORM: UserForm = {
|
||||||
@@ -18,6 +19,7 @@ const EMPTY_FORM: UserForm = {
|
|||||||
full_name: "",
|
full_name: "",
|
||||||
role: "staff",
|
role: "staff",
|
||||||
password: "",
|
password: "",
|
||||||
|
passwordRepeat: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const ROLE_LABELS: Record<Role, string> = {
|
const ROLE_LABELS: Record<Role, string> = {
|
||||||
@@ -74,6 +76,10 @@ export default function UserManager() {
|
|||||||
async function save(e: React.FormEvent) {
|
async function save(e: React.FormEvent) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!form) return;
|
if (!form) return;
|
||||||
|
if (form.password && form.password !== form.passwordRepeat) {
|
||||||
|
setError("Die Passwörter stimmen nicht überein.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const ok = form.id
|
const ok = form.id
|
||||||
? await callApi("PATCH", {
|
? await callApi("PATCH", {
|
||||||
id: form.id,
|
id: form.id,
|
||||||
@@ -186,6 +192,25 @@ export default function UserManager() {
|
|||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{(!form.id || form.password) && (
|
||||||
|
<div className="max-w-60">
|
||||||
|
<label className="label" htmlFor="user-password-repeat">
|
||||||
|
Passwort wiederholen
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
id="user-password-repeat"
|
||||||
|
type="password"
|
||||||
|
className="input"
|
||||||
|
value={form.passwordRepeat}
|
||||||
|
onChange={(e) =>
|
||||||
|
setForm({ ...form, passwordRepeat: e.target.value })
|
||||||
|
}
|
||||||
|
minLength={8}
|
||||||
|
required={!form.id || !!form.password}
|
||||||
|
autoComplete="new-password"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<button type="submit" className="btn btn-add" disabled={busy}>
|
<button type="submit" className="btn btn-add" disabled={busy}>
|
||||||
Speichern
|
Speichern
|
||||||
@@ -221,6 +246,7 @@ export default function UserManager() {
|
|||||||
full_name: p.full_name,
|
full_name: p.full_name,
|
||||||
role: p.role,
|
role: p.role,
|
||||||
password: "",
|
password: "",
|
||||||
|
passwordRepeat: "",
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user