-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#884 Add forget password route and link to auth pages #888
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b6ecc91
#884. Refactored `page` computed property for better readability and …
ahmedy00 c500b25
#884. usePasswordRules composable has been made generic
ahmedy00 bbe9088
#884. Created routes:
ahmedy00 20a6678
#884. Code refactor.
ahmedy00 8ac4391
#884. Language definitions.
ahmedy00 95913f2
#884. Added forgot-password link
ahmedy00 d862e47
#884. Language definitions.
ahmedy00 efcd9ee
Merge branch 'main' into main
andrewtavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
import type { PasswordRules } from "~/types/password-rules"; | ||
|
||
export default function usePasswordRules() { | ||
const rules = ref<PasswordRules[]>(passwordRules); | ||
|
||
const ruleFunctions: { [key: string]: (value: string) => boolean } = { | ||
"number-of-chars": (value: string) => value.length >= 12, | ||
"capital-letters": (value: string) => /[A-Z]/.test(value), | ||
"lower-case-letters": (value: string) => /[a-z]/.test(value), | ||
"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 }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<template> | ||
<div class="px-4 sm:px-6 md:px-8 xl:px-24 2xl:px-36"> | ||
<form class="space-y-4"> | ||
<p>{{ $t("pages.auth.reset-password.index.reset-password-info") }}</p> | ||
<FormTextField | ||
@update:model-value="input = $event" | ||
:placeholder="$t('_global.enter-username-mail')" | ||
:model-value="input" | ||
/> | ||
<div class="pt-4"> | ||
<BtnAction | ||
class="flex max-h-[48px] items-center justify-center truncate md:max-h-[40px]" | ||
:label="$t('_global.reset-password')" | ||
:cta="true" | ||
fontSize="lg" | ||
:ariaLabel="$t('_global.reset-password')" | ||
/> | ||
</div> | ||
<div class="link-text pt-16 text-center text-xl font-extrabold"> | ||
<NuxtLink :to="localePath('/auth/sign-in')" | ||
>{{ $t("pages.auth.reset-password.index.back-to-sign-in") }} | ||
</NuxtLink> | ||
</div> | ||
</form> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
const localePath = useLocalePath(); | ||
|
||
const input = ref(""); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<div class="px-4 sm:px-6 md:px-8 xl:px-24 2xl:px-36"> | ||
<form class="space-y-4"> | ||
<FormTextField | ||
@update:model-value="userNameValue = $event" | ||
:placeholder="$t('pages.auth.sign-in.index.enter-user-name')" | ||
:model-value="userNameValue" | ||
/> | ||
<FormTextField | ||
@update:model-value="passwordValue = $event" | ||
@input="checkRules" | ||
@blurred=" | ||
isBlurred = true; | ||
isFocused = false; | ||
" | ||
@focused=" | ||
isFocused = true; | ||
isBlurred = false; | ||
" | ||
:placeholder="$t('components._global.enter-password')" | ||
:is-icon-visible="true" | ||
input-type="password" | ||
:model-value="passwordValue" | ||
:icons="[IconMap.VISIBLE]" | ||
:error="!isAllRulesValid && isBlurred" | ||
/> | ||
<IndicatorPasswordStrength :password-value="passwordValue" /> | ||
<TooltipPasswordRequirements | ||
v-if=" | ||
!!passwordValue?.length && | ||
!isAllRulesValid && | ||
(!isBlurred || isFocused) | ||
" | ||
:rules="rules" | ||
/> | ||
<FormTextField | ||
@update:model-value="confirmPasswordValue = $event" | ||
:placeholder="$t('_global.repeat-password')" | ||
:is-icon-visible="true" | ||
input-type="password" | ||
:model-value="confirmPasswordValue" | ||
:icons=" | ||
isPasswordMatch(passwordValue, confirmPasswordValue) | ||
? [IconMap.CHECK, IconMap.VISIBLE] | ||
: [IconMap.X_LG, IconMap.VISIBLE] | ||
" | ||
/> | ||
<div class="pt-4"> | ||
<BtnAction | ||
class="flex max-h-[48px] items-center justify-center truncate md:max-h-[40px]" | ||
:label="$t('_global.set-password')" | ||
:cta="true" | ||
fontSize="lg" | ||
:ariaLabel="$t('_global.set-password')" | ||
/> | ||
</div> | ||
</form> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { IconMap } from "~/types/icon-map"; | ||
|
||
const userNameValue = ref(""); | ||
const passwordValue = ref(""); | ||
const confirmPasswordValue = ref(""); | ||
|
||
const isBlurred = ref(false); | ||
const isFocused = ref(false); | ||
|
||
const { rules, isAllRulesValid, checkRules, isPasswordMatch } = | ||
usePasswordRules(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 @@ | |
|
||
<script setup lang="ts"> | ||
import { IconMap } from "~/types/icon-map"; | ||
import type { PasswordRules } from "~/types/password-rules"; | ||
|
||
const localePath = useLocalePath(); | ||
|
||
|
@@ -103,29 +102,8 @@ const hasRed = ref(false); | |
const isBlurred = ref(false); | ||
const isFocused = ref(false); | ||
|
||
const isPasswordMatch = computed(() => { | ||
if (passwordValue.value === "" || confirmPasswordValue.value === "") { | ||
return false; | ||
} | ||
return passwordValue.value === confirmPasswordValue.value; | ||
}); | ||
|
||
const rules = ref<PasswordRules[]>(passwordRules); | ||
const { ruleFunctions } = usePasswordRules(); | ||
|
||
const checkRules = (value: { target: { value: string } }): void => { | ||
const actualValue = value.target.value; | ||
rules.value.forEach((rule) => { | ||
if (ruleFunctions[rule.message]) { | ||
rule.isValid = ruleFunctions[rule.message](actualValue); | ||
} | ||
}); | ||
}; | ||
|
||
// Checks the rules to make the tooltip invisible when all rules are valid. | ||
const isAllRulesValid = computed(() => { | ||
return rules.value.every((rule) => rule.isValid); | ||
}); | ||
const { rules, isAllRulesValid, checkRules, isPasswordMatch } = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great to have this extracted and reusable, @ahmedy00! 😊 |
||
usePasswordRules(); | ||
|
||
const signUp = () => {}; | ||
</script> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrewtavis I'm not familiar with captcha check, so I added a TODO and it would be nice if you can handle this for me.