From 2abc773022d02185048173fd5e99b81ca73540ec Mon Sep 17 00:00:00 2001 From: hay-kot Date: Wed, 24 Feb 2021 19:25:18 -0900 Subject: [PATCH] basic password validation --- frontend/src/mixins/validators.js | 15 +++++ frontend/src/pages/Admin/Profile/index.vue | 68 ++++++++++++++++------ frontend/src/utils/index.js | 1 + frontend/src/utils/validators.js | 8 --- mealie/routes/users/crud.py | 6 +- 5 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 frontend/src/mixins/validators.js delete mode 100644 frontend/src/utils/validators.js diff --git a/frontend/src/mixins/validators.js b/frontend/src/mixins/validators.js new file mode 100644 index 000000000..dc7bb314b --- /dev/null +++ b/frontend/src/mixins/validators.js @@ -0,0 +1,15 @@ +export const validators = { + data() { + return { + emailRule: v => + !v || + /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || + "E-mail must be valid", + + existsRule: value => !!value || "Field Required", + + minRule: v => + v.length >= 8 || "Use 8 characters or more for your password", + }; + }, +}; diff --git a/frontend/src/pages/Admin/Profile/index.vue b/frontend/src/pages/Admin/Profile/index.vue index 69b4309ed..f075d247b 100644 --- a/frontend/src/pages/Admin/Profile/index.vue +++ b/frontend/src/pages/Admin/Profile/index.vue @@ -19,7 +19,7 @@ - + - + - + - + + + mdi-eye-off + mdi-eye + - + mdi-lock {{ $t("settings.change-password") }} @@ -109,22 +134,21 @@ // import AvatarPicker from '@/components/AvatarPicker' import UploadBtn from "@/components/UI/UploadBtn"; import api from "@/api"; +import { validators } from "@/mixins/validators"; export default { components: { UploadBtn, }, + mixins: [validators], data() { return { + passwordLoading: false, password: { current: "", newOne: "", newTwo: "", }, - showPassword: { - current: false, - newOne: false, - newTwo: false, - }, + showPassword: false, loading: false, user: { fullName: "Change Me", @@ -133,7 +157,6 @@ export default { admin: true, id: 1, }, - showAvatarPicker: false, }; }, @@ -159,13 +182,20 @@ export default { this.loading = false; }, async changePassword() { + this.paswordLoading = true; let data = { currentPassword: this.password.current, newPassword: this.password.newOne, }; - await api.users.changePassword(this.user.id, data); + if (this.$refs.passChange.validate()) { + await api.users.changePassword(this.user.id, data); + } + this.paswordLoading = false; }, }, }; - \ No newline at end of file + + + \ No newline at end of file diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index b1d9460cd..37b105c35 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -3,6 +3,7 @@ // import Vuetify from "./plugins/vuetify"; import { vueApp } from "../main"; + const notifyHelpers = { baseCSS: "notify-base", error: "notify-error-color", diff --git a/frontend/src/utils/validators.js b/frontend/src/utils/validators.js deleted file mode 100644 index 96dab710e..000000000 --- a/frontend/src/utils/validators.js +++ /dev/null @@ -1,8 +0,0 @@ -const validators = { - emailRules: v => - !v || - /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/.test(v) || - "E-mail must be valid", -}; - -export { validators }; diff --git a/mealie/routes/users/crud.py b/mealie/routes/users/crud.py index 513fe66e7..5eadbc713 100644 --- a/mealie/routes/users/crud.py +++ b/mealie/routes/users/crud.py @@ -86,13 +86,15 @@ async def update_password( match_passwords = verify_password( password_change.current_password, current_user.password ) + print(match_passwords) match_id = current_user.id == id if match_passwords and match_id: new_password = get_password_hash(password_change.new_password) db.users.update_password(session, id, new_password) - - return SnackResponse.success("Password Updated") + return SnackResponse.success("Password Updated") + else: + return SnackResponse.error("Existing password does not match") @router.delete("/{id}")