From b6ecc91e02a2aff295ac11b045b5ce25d16c2bde Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:39:46 +0300 Subject: [PATCH 1/7] #884. Refactored `page` computed property for better readability and extensibility --- frontend/layouts/auth.vue | 68 +++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/frontend/layouts/auth.vue b/frontend/layouts/auth.vue index 6f2582e75..147d85e2b 100644 --- a/frontend/layouts/auth.vue +++ b/frontend/layouts/auth.vue @@ -46,27 +46,53 @@ const route = useRoute(); const page = computed(() => { - const isSignIn = route.fullPath?.includes("sign-in"); - const isSignUp = route.fullPath?.includes("sign-up"); - return { - route: isSignIn ? "sign-in" : isSignUp ? "sign-up" : "index", - btnAriaLabel: isSignIn - ? "_global.auth.sign-up-aria-label" - : isSignUp - ? "_global.auth.sign-in-aria-label" - : "", - btnLabel: isSignIn ? "_global.sign-up" : isSignUp ? "_global.sign-in" : "", - btnLink: isSignIn ? "/auth/sign-up" : isSignUp ? "/auth/sign-in" : "", - message: isSignIn - ? "layouts.auth.sign-in-welcome-back" - : isSignUp - ? "layouts.auth.sign-up-first-time-welcome" - : "layouts.auth.welcome", - title: isSignIn - ? "_global.sign-in" - : isSignUp - ? "_global.sign-up" - : "pages.auth.index.auth", + const authRoutes = [ + { + route: "sign-in", + btnAriaLabel: "_global.auth.sign-up-aria-label", + btnLabel: "_global.sign-up", + btnLink: "/auth/sign-up", + message: "layouts.auth.sign-in-welcome-back", + title: "_global.sign-in", + }, + { + route: "sign-up", + btnAriaLabel: "_global.auth.sign-in-aria-label", + btnLabel: "_global.sign-in", + btnLink: "/auth/sign-in", + message: "layouts.auth.sign-up-first-time-welcome", + title: "_global.sign-up", + }, + { + route: "reset-password", + btnAriaLabel: "_global.auth.sign-in-aria-label", + btnLabel: "_global.sign-in", + btnLink: "/auth/sign-in", + message: "layouts.auth.reset-password-forgot-password", + title: "_global.reset-password", + }, + { + route: "set-password", + btnAriaLabel: "_global.auth.sign-in-aria-label", + btnLabel: "_global.sign-in", + btnLink: "/auth/sign-in", + message: "layouts.auth.set-password-set-new-password", + title: "_global.set-new-password", + }, + ]; + + const defaultRoute = { + route: "index", + btnAriaLabel: "", + btnLabel: "", + btnLink: "", + message: "layouts.auth.welcome", + title: "pages.auth.index.auth", }; + + return ( + authRoutes.find((authRoute) => route.fullPath?.includes(authRoute.route)) || + defaultRoute + ); }); From c500b25ff2b49e93bb3e3d09f9794d4649368442 Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:41:05 +0300 Subject: [PATCH 2/7] #884. usePasswordRules composable has been made generic --- frontend/composables/usePasswordRules.ts | 30 +++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/frontend/composables/usePasswordRules.ts b/frontend/composables/usePasswordRules.ts index 5d2786e71..cda673803 100644 --- a/frontend/composables/usePasswordRules.ts +++ b/frontend/composables/usePasswordRules.ts @@ -1,4 +1,8 @@ +import type { PasswordRules } from "~/types/password-rules"; + export default function usePasswordRules() { + const rules = ref(passwordRules); + const ruleFunctions: { [key: string]: (value: string) => boolean } = { "number-of-chars": (value: string) => value.length >= 12, "capital-letters": (value: string) => /[A-Z]/.test(value), @@ -6,5 +10,29 @@ export default function usePasswordRules() { "contains-numbers": (value: string) => /[0-9]/.test(value), "contains-special-chars": (value: string) => /[^a-zA-Z0-9]/.test(value), }; - return { ruleFunctions }; + + const checkRules = (event: { target: { value: string } }): void => { + const actualValue = event.target.value; + rules.value.forEach((rule) => { + if (ruleFunctions[rule.message]) { + rule.isValid = ruleFunctions[rule.message](actualValue); + } + }); + }; + + const isPasswordMatch = ( + passwordValue: string, + confirmPasswordValue: string + ) => { + if (passwordValue === "" || confirmPasswordValue === "") { + return false; + } + return passwordValue === confirmPasswordValue; + }; + + const isAllRulesValid = computed(() => { + return rules.value.every((rule) => rule.isValid); + }); + + return { checkRules, isAllRulesValid, isPasswordMatch, rules }; } From bbe90881c56c67642f7b5906545b16754c7d0e48 Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:41:55 +0300 Subject: [PATCH 3/7] #884. Created routes: -reset-password -set-password --- frontend/pages/auth/reset-password.vue | 31 +++++++++++ frontend/pages/auth/set-password.vue | 72 ++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 frontend/pages/auth/reset-password.vue create mode 100644 frontend/pages/auth/set-password.vue diff --git a/frontend/pages/auth/reset-password.vue b/frontend/pages/auth/reset-password.vue new file mode 100644 index 000000000..b66114cb5 --- /dev/null +++ b/frontend/pages/auth/reset-password.vue @@ -0,0 +1,31 @@ + + diff --git a/frontend/pages/auth/set-password.vue b/frontend/pages/auth/set-password.vue new file mode 100644 index 000000000..1e199a723 --- /dev/null +++ b/frontend/pages/auth/set-password.vue @@ -0,0 +1,72 @@ + + From 20a66788ea704f5e219bb2d8c161e470f0230d90 Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:42:08 +0300 Subject: [PATCH 4/7] #884. Code refactor. --- frontend/pages/auth/sign-up.vue | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/frontend/pages/auth/sign-up.vue b/frontend/pages/auth/sign-up.vue index 56a61d26e..75c723fe4 100644 --- a/frontend/pages/auth/sign-up.vue +++ b/frontend/pages/auth/sign-up.vue @@ -45,7 +45,7 @@ input-type="password" :model-value="confirmPasswordValue" :icons=" - isPasswordMatch + isPasswordMatch(passwordValue, confirmPasswordValue) ? [IconMap.CHECK, IconMap.VISIBLE] : [IconMap.X_LG, IconMap.VISIBLE] " @@ -92,7 +92,6 @@ From 8ac4391bfc8b7f33c02ff43e42e00991d3a494cb Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:42:21 +0300 Subject: [PATCH 5/7] #884. Language definitions. --- frontend/i18n/en-US.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/frontend/i18n/en-US.json b/frontend/i18n/en-US.json index e182d85a4..ceedb68b2 100644 --- a/frontend/i18n/en-US.json +++ b/frontend/i18n/en-US.json @@ -35,6 +35,7 @@ "_global.privacy-policy": "Privacy policy", "_global.public-matrix-chat-rooms": "public Matrix chat rooms", "_global.repeat-password": "Repeat password", + "_global.enter-username-mail": "Enter your username or email", "_global.resources": "Resources", "_global.resources_lower": "resources", "_global.roadmap": "Roadmap", @@ -409,6 +410,8 @@ "components.view-selector.view-as-map-aria-label": "View as map", "layouts.auth.sign-in-welcome-back": "Welcome back!", "layouts.auth.sign-up-first-time-welcome": "Let's get to work!", + "layouts.auth.reset-password-forgot-password": "Forgot your password?", + "layouts.auth.set-password-set-new-password": "Set new password", "layouts.auth.welcome": "Welcome!", "pages._global.about-us": "About us", "pages._global.become-supporter": "Become a supporter", @@ -464,6 +467,8 @@ "pages.auth.sign-in.index.no-account": "Don't have an account?", "pages.auth.sign-up.index.enter-user-name": "Enter a username", "pages.auth.sign-up.index.have-account": "Already have an account?", + "pages.auth.reset-password.index.reset-password-info": "Enter your username or email address and we will send you instructions to reset your password.", + "pages.auth.reset-password.index.back-to-sign-in": "Back to sign in", "pages.docs.get-active.header": "Discover and get involved", "pages.docs.get-active.modal-image-alt-text": "Mockups that show mobile organization search and web event search on a map.", "pages.docs.get-active.section-1-paragraph-1": "activist has the goal of making finding political events and organizations near you as easy as possible. With each event we want people to have an opportunity to get involved in the organization that's putting it on, and once in an organization we want to make it easy to find what to do next to have the biggest impact.", From 95913f273ee5325b510200e58a12e45d172bc986 Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:45:17 +0300 Subject: [PATCH 6/7] #884. Added forgot-password link - Disabled(expected) when captcha check failed and show tooltip why disabled. --- frontend/pages/auth/sign-in.vue | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/pages/auth/sign-in.vue b/frontend/pages/auth/sign-in.vue index 6f96637c0..e1f8e15c6 100644 --- a/frontend/pages/auth/sign-in.vue +++ b/frontend/pages/auth/sign-in.vue @@ -21,6 +21,22 @@
+ + { const { data: responseData } = await $fetch( `http://localhost:8000/v1/auth/login/`, From d862e47fa1cb0d4d4fd1b042393b18178caeb925 Mon Sep 17 00:00:00 2001 From: ahmet Date: Fri, 24 May 2024 22:47:39 +0300 Subject: [PATCH 7/7] #884. Language definitions. --- frontend/i18n/en-US.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/frontend/i18n/en-US.json b/frontend/i18n/en-US.json index ceedb68b2..f8b9c82f4 100644 --- a/frontend/i18n/en-US.json +++ b/frontend/i18n/en-US.json @@ -45,6 +45,8 @@ "_global.settings_lower": "settings", "_global.sign-in": "Sign in", "_global.sign-up": "Sign up", + "_global.reset-password": "Reset password", + "_global.set-password": "Set password", "_global.status": "Status", "_global.supporters": "Supporters", "_global.tasks": "Tasks",