From 59cbe90fd36554a1d71b1c54570dcb583947a06b Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Wed, 23 Apr 2025 22:13:17 +0800 Subject: [PATCH] [API Node] Reset password (#3578) Co-authored-by: github-actions --- .../dialog/content/signin/SignInForm.vue | 25 ++++++++++++++++++- src/locales/en/main.json | 3 +++ src/locales/es/main.json | 3 +++ src/locales/fr/main.json | 3 +++ src/locales/ja/main.json | 3 +++ src/locales/ko/main.json | 3 +++ src/locales/ru/main.json | 3 +++ src/locales/zh/main.json | 3 +++ src/stores/firebaseAuthStore.ts | 9 ++++++- 9 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/components/dialog/content/signin/SignInForm.vue b/src/components/dialog/content/signin/SignInForm.vue index 1e78e1875..e1fa79652 100644 --- a/src/components/dialog/content/signin/SignInForm.vue +++ b/src/components/dialog/content/signin/SignInForm.vue @@ -36,7 +36,10 @@ > {{ t('auth.login.passwordLabel') }} - + {{ t('auth.login.forgotPassword') }} @@ -79,11 +82,13 @@ import { useI18n } from 'vue-i18n' import { type SignInData, signInSchema } from '@/schemas/signInSchema' import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' +import { useToastStore } from '@/stores/toastStore' const authStore = useFirebaseAuthStore() const loading = computed(() => authStore.loading) const { t } = useI18n() +const toast = useToastStore() const emit = defineEmits<{ submit: [values: SignInData] @@ -94,4 +99,22 @@ const onSubmit = (event: FormSubmitEvent) => { emit('submit', event.values as SignInData) } } + +const handleForgotPassword = async (email: string) => { + if (!email) return + await authStore.sendPasswordReset(email) + if (authStore.error) { + toast.add({ + severity: 'error', + summary: t('auth.login.forgotPasswordError'), + detail: authStore.error + }) + } else { + toast.add({ + severity: 'success', + summary: t('auth.login.passwordResetSent'), + detail: t('auth.login.passwordResetSentDetail') + }) + } +} diff --git a/src/locales/en/main.json b/src/locales/en/main.json index 298908e65..ccfbe10ef 100644 --- a/src/locales/en/main.json +++ b/src/locales/en/main.json @@ -1082,6 +1082,9 @@ "login": { "title": "Log in to your account", "signInOrSignUp": "Sign In / Sign Up", + "forgotPasswordError": "Failed to send password reset email", + "passwordResetSent": "Password reset email sent", + "passwordResetSentDetail": "Please check your email for a link to reset your password.", "newUser": "New here?", "signUp": "Sign up", "emailLabel": "Email", diff --git a/src/locales/es/main.json b/src/locales/es/main.json index adc251115..1447d2088 100644 --- a/src/locales/es/main.json +++ b/src/locales/es/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "Ingresa tu correo electrónico", "failed": "Inicio de sesión fallido", "forgotPassword": "¿Olvidaste tu contraseña?", + "forgotPasswordError": "No se pudo enviar el correo electrónico para restablecer la contraseña", "genericErrorMessage": "Lo sentimos, hemos encontrado un error. Por favor, contacta con {supportEmail}.", "loginButton": "Iniciar sesión", "loginWithGithub": "Iniciar sesión con Github", @@ -25,6 +26,8 @@ "orContinueWith": "O continuar con", "passwordLabel": "Contraseña", "passwordPlaceholder": "Ingresa tu contraseña", + "passwordResetSent": "Correo electrónico de restablecimiento de contraseña enviado", + "passwordResetSentDetail": "Por favor, revisa tu correo electrónico para encontrar un enlace para restablecer tu contraseña.", "privacyLink": "Política de privacidad", "signInOrSignUp": "Iniciar sesión / Registrarse", "signUp": "Regístrate", diff --git a/src/locales/fr/main.json b/src/locales/fr/main.json index ed4862ad3..bc89754c6 100644 --- a/src/locales/fr/main.json +++ b/src/locales/fr/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "Entrez votre email", "failed": "Échec de la connexion", "forgotPassword": "Mot de passe oublié?", + "forgotPasswordError": "Échec de l'envoi de l'e-mail de réinitialisation du mot de passe", "genericErrorMessage": "Désolé, une erreur s'est produite. Veuillez contacter {supportEmail}.", "loginButton": "Se connecter", "loginWithGithub": "Se connecter avec Github", @@ -25,6 +26,8 @@ "orContinueWith": "Ou continuer avec", "passwordLabel": "Mot de passe", "passwordPlaceholder": "Entrez votre mot de passe", + "passwordResetSent": "E-mail de réinitialisation du mot de passe envoyé", + "passwordResetSentDetail": "Veuillez vérifier votre e-mail pour un lien de réinitialisation de votre mot de passe.", "privacyLink": "Politique de confidentialité", "signInOrSignUp": "Se connecter / S’inscrire", "signUp": "S'inscrire", diff --git a/src/locales/ja/main.json b/src/locales/ja/main.json index 672c76b65..450bc5df1 100644 --- a/src/locales/ja/main.json +++ b/src/locales/ja/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "メールアドレスを入力してください", "failed": "ログイン失敗", "forgotPassword": "パスワードを忘れましたか?", + "forgotPasswordError": "パスワードリセット用メールの送信に失敗しました", "genericErrorMessage": "申し訳ありませんが、エラーが発生しました。{supportEmail} までご連絡ください。", "loginButton": "ログイン", "loginWithGithub": "Githubでログイン", @@ -25,6 +26,8 @@ "orContinueWith": "または以下で続ける", "passwordLabel": "パスワード", "passwordPlaceholder": "パスワードを入力してください", + "passwordResetSent": "パスワードリセット用メールを送信しました", + "passwordResetSentDetail": "パスワードをリセットするためのリンクが記載されたメールをご確認ください。", "privacyLink": "プライバシーポリシー", "signInOrSignUp": "サインイン / サインアップ", "signUp": "サインアップ", diff --git a/src/locales/ko/main.json b/src/locales/ko/main.json index ac6463b67..d00998c37 100644 --- a/src/locales/ko/main.json +++ b/src/locales/ko/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "이메일을 입력하세요", "failed": "로그인 실패", "forgotPassword": "비밀번호를 잊으셨나요?", + "forgotPasswordError": "비밀번호 재설정 이메일 전송에 실패했습니다", "genericErrorMessage": "죄송합니다. 오류가 발생했습니다. {supportEmail}로 문의해 주세요.", "loginButton": "로그인", "loginWithGithub": "Github로 로그인", @@ -25,6 +26,8 @@ "orContinueWith": "또는 다음으로 계속", "passwordLabel": "비밀번호", "passwordPlaceholder": "비밀번호를 입력하세요", + "passwordResetSent": "비밀번호 재설정 이메일이 전송되었습니다", + "passwordResetSentDetail": "비밀번호를 재설정할 수 있는 링크가 포함된 이메일을 확인해 주세요.", "privacyLink": "개인정보 보호정책", "signInOrSignUp": "로그인 / 회원가입", "signUp": "가입하기", diff --git a/src/locales/ru/main.json b/src/locales/ru/main.json index fa6a58d3d..e636717ae 100644 --- a/src/locales/ru/main.json +++ b/src/locales/ru/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "Введите вашу электронную почту", "failed": "Вход не удался", "forgotPassword": "Забыли пароль?", + "forgotPasswordError": "Не удалось отправить письмо для сброса пароля", "genericErrorMessage": "Извините, произошла ошибка. Пожалуйста, свяжитесь с {supportEmail}.", "loginButton": "Войти", "loginWithGithub": "Войти через Github", @@ -25,6 +26,8 @@ "orContinueWith": "Или продолжить с", "passwordLabel": "Пароль", "passwordPlaceholder": "Введите ваш пароль", + "passwordResetSent": "Письмо для сброса пароля отправлено", + "passwordResetSentDetail": "Пожалуйста, проверьте свою электронную почту для получения ссылки на сброс пароля.", "privacyLink": "Политикой конфиденциальности", "signInOrSignUp": "Войти / Зарегистрироваться", "signUp": "Зарегистрироваться", diff --git a/src/locales/zh/main.json b/src/locales/zh/main.json index e418580fa..09e2e995f 100644 --- a/src/locales/zh/main.json +++ b/src/locales/zh/main.json @@ -17,6 +17,7 @@ "emailPlaceholder": "输入您的电子邮件", "failed": "登录失败", "forgotPassword": "忘记密码?", + "forgotPasswordError": "发送重置密码邮件失败", "genericErrorMessage": "抱歉,我们遇到了一些错误。请联系 {supportEmail}。", "loginButton": "登录", "loginWithGithub": "使用Github登录", @@ -25,6 +26,8 @@ "orContinueWith": "或者继续使用", "passwordLabel": "密码", "passwordPlaceholder": "输入您的密码", + "passwordResetSent": "重置密码邮件已发送", + "passwordResetSentDetail": "请查收您的电子邮件,点击链接重置密码。", "privacyLink": "隐私政策", "signInOrSignUp": "登录 / 注册", "signUp": "注册", diff --git a/src/stores/firebaseAuthStore.ts b/src/stores/firebaseAuthStore.ts index 863497f1c..2c7e08f3e 100644 --- a/src/stores/firebaseAuthStore.ts +++ b/src/stores/firebaseAuthStore.ts @@ -7,6 +7,7 @@ import { browserLocalPersistence, createUserWithEmailAndPassword, onAuthStateChanged, + sendPasswordResetEmail, setPersistence, signInWithEmailAndPassword, signInWithPopup, @@ -226,6 +227,11 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => { const logout = async (): Promise => executeAuthAction((authInstance) => signOut(authInstance)) + const sendPasswordReset = async (email: string): Promise => + executeAuthAction((authInstance) => + sendPasswordResetEmail(authInstance, email) + ) + const addCredits = async ( requestBodyContent: CreditPurchasePayload ): Promise => { @@ -329,6 +335,7 @@ export const useFirebaseAuthStore = defineStore('firebaseAuth', () => { openSignInPanel, openCreditsPanel, fetchBalance, - accessBillingPortal + accessBillingPortal, + sendPasswordReset } })