Skip to content

Commit 10037d9

Browse files
author
Philipp Hehnle
committed
Merge remote-tracking branch 'origin/jonaw1/dont-require-pw' into develop
2 parents c46e387 + a254c51 commit 10037d9

2 files changed

Lines changed: 71 additions & 37 deletions

File tree

frontend/src/components/Authentication/formValidation.ts

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,71 @@ import i18n from "@/i18n";
33
const t = i18n.global.t;
44

55
export const baseEmailRules = [
6-
(email: string) => !!email || `${t('authentication.email')} ${t('validation.isRequired')}`,
7-
(email: string) => email.length <= 64 || `${t('authentication.email')} ${t('validation.max64Characters')}`
8-
]
6+
(email: string) =>
7+
!!email || `${t("authentication.email")} ${t("validation.isRequired")}`,
8+
(email: string) =>
9+
email.length <= 64 ||
10+
`${t("authentication.email")} ${t("validation.max64Characters")}`
11+
];
912

1013
export const emailRules = baseEmailRules.concat([
11-
(email: string) => /.+@.+\..+/.test(email) || `${t('authentication.email')} ${t('validation.mustBeValid')}`,
14+
(email: string) =>
15+
/.+@.+\..+/.test(email) ||
16+
`${t("authentication.email")} ${t("validation.mustBeValid")}`
1217
]);
1318

1419
export const emailRulesSignIn = baseEmailRules.concat([
15-
(email: string) => email === 'admin' || /.+@.+\..+/.test(email) || `${t('authentication.email')} ${t('validation.mustBeValid')}`,
20+
(email: string) =>
21+
email === "admin" ||
22+
/.+@.+\..+/.test(email) ||
23+
`${t("authentication.email")} ${t("validation.mustBeValid")}`
1624
]);
1725

1826
export const newPasswordRules = [
19-
(password: string) => !!password || `${t('authentication.password')} ${t('validation.isRequired')}`,
20-
(password: string) => password.length >= 8 || `${t('authentication.password')} ${t('validation.min8Characters')}`,
21-
(password: string) => password.length <= 64 || `${t('authentication.password')} ${t('validation.max64Characters')}`,
22-
(password: string) => /(?=.*[a-z])/.test(password) || `${t('authentication.password')} ${t('validation.atLeastOneLower')}`,
23-
(password: string) => /(?=.*[A-Z])/.test(password) || `${t('authentication.password')} ${t('validation.atLeastOneUpper')}`,
24-
(password: string) => /(?=.*\d)/.test(password) || `${t('authentication.password')} ${t('validation.atLeastOneDigit')}`,
25-
]
27+
(password: string) =>
28+
!!password ||
29+
`${t("authentication.password")} ${t("validation.isRequired")}`,
30+
(password: string) =>
31+
password.length >= 8 ||
32+
`${t("authentication.password")} ${t("validation.min8Characters")}`,
33+
(password: string) =>
34+
password.length <= 64 ||
35+
`${t("authentication.password")} ${t("validation.max64Characters")}`,
36+
(password: string) =>
37+
/(?=.*[a-z])/.test(password) ||
38+
`${t("authentication.password")} ${t("validation.atLeastOneLower")}`,
39+
(password: string) =>
40+
/(?=.*[A-Z])/.test(password) ||
41+
`${t("authentication.password")} ${t("validation.atLeastOneUpper")}`,
42+
(password: string) =>
43+
/(?=.*\d)/.test(password) ||
44+
`${t("authentication.password")} ${t("validation.atLeastOneDigit")}`
45+
];
46+
47+
export const updateUserPasswordRules = newPasswordRules.map(
48+
(rule) => (password: string) => (password === "" ? true : rule(password))
49+
);
2650

2751
export const currentPasswordRules = [
28-
(password: string) => !!password || `${t('authentication.password')} ${t('validation.isRequired')}`,
29-
]
52+
(password: string) =>
53+
!!password ||
54+
`${t("authentication.password")} ${t("validation.isRequired")}`
55+
];
3056

3157
export const firstNameRules = [
32-
(firstName: string) => !!firstName || `${t('authentication.firstName')} ${t('validation.isRequired')}`,
33-
(firstName: string) => firstName.length <= 64 || `${t('authentication.firstName')} ${t('validation.max64Characters')}`,
34-
]
58+
(firstName: string) =>
59+
!!firstName ||
60+
`${t("authentication.firstName")} ${t("validation.isRequired")}`,
61+
(firstName: string) =>
62+
firstName.length <= 64 ||
63+
`${t("authentication.firstName")} ${t("validation.max64Characters")}`
64+
];
3565

3666
export const lastNameRules = [
37-
(lastName: string) => !!lastName || `${t('authentication.lastName')} ${t('validation.isRequired')}`,
38-
(lastName: string) => lastName.length <= 64 || `${t('authentication.lastName')} ${t('validation.max64Characters')}`,
39-
]
67+
(lastName: string) =>
68+
!!lastName ||
69+
`${t("authentication.lastName")} ${t("validation.isRequired")}`,
70+
(lastName: string) =>
71+
lastName.length <= 64 ||
72+
`${t("authentication.lastName")} ${t("validation.max64Characters")}`
73+
];

frontend/src/components/ManageUsers/EditUserDialog.vue

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
type="password"
3636
:label="$t('authentication.newPassword')"
3737
variant="outlined"
38-
:rules="newPasswordRules"
38+
:rules="updateUserPasswordRules"
3939
/>
4040
</v-form>
4141
<div class="d-flex align-center justify-space-between">
@@ -71,7 +71,7 @@ import {
7171
emailRules,
7272
firstNameRules,
7373
lastNameRules,
74-
newPasswordRules,
74+
updateUserPasswordRules
7575
} from "@/components/Authentication/formValidation";
7676
import { VForm } from "vuetify/components";
7777
@@ -81,36 +81,36 @@ export default defineComponent({
8181
showDialog: {
8282
type: Boolean,
8383
required: true,
84-
default: false,
84+
default: false
8585
},
8686
userId: {
8787
type: Number,
88-
required: true,
88+
required: true
8989
},
9090
userEmail: {
9191
type: String,
92-
required: true,
92+
required: true
9393
},
9494
userFirstName: {
9595
type: String,
96-
required: true,
96+
required: true
9797
},
9898
userLastName: {
9999
type: String,
100-
required: true,
100+
required: true
101101
},
102102
userCreatedAt: {
103103
type: String,
104-
required: true,
104+
required: true
105105
},
106106
userModifiedAt: {
107107
type: String,
108-
required: true,
108+
required: true
109109
},
110110
ownUserId: {
111111
type: Number,
112-
required: true,
113-
},
112+
required: true
113+
}
114114
},
115115
116116
data() {
@@ -122,14 +122,14 @@ export default defineComponent({
122122
emailRules: emailRules,
123123
firstNameRules: firstNameRules,
124124
lastNameRules: lastNameRules,
125-
newPasswordRules: newPasswordRules,
125+
updateUserPasswordRules: updateUserPasswordRules
126126
};
127127
},
128128
129129
computed: {
130130
dialogModel() {
131131
return this.showDialog;
132-
},
132+
}
133133
},
134134
135135
methods: {
@@ -159,12 +159,12 @@ export default defineComponent({
159159
this.localUserLastName != this.userLastName
160160
? this.localUserLastName
161161
: null,
162-
password: this.newPassword != "" ? this.newPassword : null,
162+
password: this.newPassword != "" ? this.newPassword : null
163163
};
164164
await axios.patch(`/api/user/${id}`, data, { headers: authHeader() });
165165
this.$emit("fetchUsers");
166166
this.closeDialog();
167-
},
167+
}
168168
},
169169
170170
watch: {
@@ -175,7 +175,7 @@ export default defineComponent({
175175
this.localUserLastName = this.userLastName;
176176
this.newPassword = "";
177177
}
178-
},
179-
},
178+
}
179+
}
180180
});
181181
</script>

0 commit comments

Comments
 (0)