diff --git a/frontend/src/views/Login.vue b/frontend/src/views/Login.vue index 115f4a1e4..24fb2d5fe 100644 --- a/frontend/src/views/Login.vue +++ b/frontend/src/views/Login.vue @@ -34,7 +34,9 @@ outlined /> - Forgot password? + + Forgot password? + - - diff --git a/frontend/src/views/user/PasswordRecoveryChangeForm.vue b/frontend/src/views/user/PasswordRecoveryChangeForm.vue index c8e02f40f..3055b9d13 100644 --- a/frontend/src/views/user/PasswordRecoveryChangeForm.vue +++ b/frontend/src/views/user/PasswordRecoveryChangeForm.vue @@ -15,7 +15,7 @@ v-slot="{ errors }" rules="required" > -

+

{{ password_validation_error }}

- Return to login? + + Return to login +
@@ -64,6 +66,7 @@ export default { loading: false, password: '', password_confirmed: '', + password_validation_error: '', errors: {}, token: '', id: '' @@ -87,9 +90,6 @@ export default { } } }, - returnLogin () { - this.$router.push({ name: 'Login' }) - }, async changePassword () { const isValid = await this.$refs.observer.validate() if (!isValid) { @@ -102,7 +102,7 @@ export default { id: this.id } this.loading = true - document.getElementById('password_validation').innerHTML = '' + this.password_validation_error = '' auth.changePassword(payload).then(resp => { if (resp.status === 200) { this.loading = false @@ -120,7 +120,7 @@ export default { message += this.$gettext(element) + '
' }) } - document.getElementById('password_validation').innerHTML = message + this.password_validation_error = message }) } }, diff --git a/frontend/src/views/user/PasswordRecoverySmsTotpForm.vue b/frontend/src/views/user/PasswordRecoverySmsTotpForm.vue index f65ceaf0f..2bcc55089 100644 --- a/frontend/src/views/user/PasswordRecoverySmsTotpForm.vue +++ b/frontend/src/views/user/PasswordRecoverySmsTotpForm.vue @@ -39,7 +39,7 @@
Resend SMS. - Return to login? + Return to login
@@ -61,9 +61,6 @@ export default { } }, methods: { - returnLogin () { - this.$router.push({ name: 'Login' }) - }, async showErrorDialog (body) { const confirm = await this.$refs.confirm.open( this.$gettext('Error'), @@ -91,7 +88,7 @@ export default { }).catch(err => { if (err.response.status === 400) { this.loading = false - this.showErrorDialog('User seems wrong, return to login or restart reset the process?') + this.showErrorDialog(this.$t('User seems wrong, return to login or restart reset the process?')) } }) }, diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 1e847f0c9..635a4b859 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -339,12 +339,9 @@ class PasswordRecoverySmsSerializer(serializers.Serializer): request = self.context["request"] clean_email = data["email"] - user = User.objects.filter(email__iexact=clean_email, is_active=True).first() - if user is None: - raise CustomValidationError({"type": "sms", "reason": "No valid user found."}, 404) - - self.context["user"] = (User.objects.filter( - email__iexact=clean_email, is_active=True) + self.context["user"] = ( + User.objects.filter( + email__iexact=clean_email, is_active=True) .exclude(Q(phone_number__isnull=True) | Q(phone_number="")) ).first() if self.context["user"] is None: @@ -379,8 +376,10 @@ class PasswordRecoverySmsConfirmSerializer(serializers.Serializer): raise CustomValidationError({"reason": "Wrong totp"}, 400) # Attempt to get user, will raise an error if pk is not valid - self.context["user"] = User.objects.get( - pk=self.context["request"].session["user_pk"]) + self.context["user"] = User.objects.filter( + pk=self.context["request"].session["user_pk"]).first() + if self.context["user"] is None: + raise CustomValidationError({"reason": "Invalid user"}, 400) return data @@ -403,8 +402,10 @@ class PasswordRecoverySmsResendSerializer(serializers.Serializer): {"reason": "totp secret not set in session"}, status.HTTP_403_FORBIDDEN) # Attempt to get user, will raise an error if pk is not valid - self.context["user"] = User.objects.get( - pk=self.context["request"].session["user_pk"]) + self.context["user"] = User.objects.filter( + pk=self.context["request"].session["user_pk"]).first() + if self.context["user"] is None: + raise CustomValidationError({"reason": "Invalid user"}, 400) return data @@ -461,5 +462,3 @@ class PasswordRecoveryConfirmSerializer(serializers.Serializer): user.set_password(self.validated_data["new_password1"]) user.save() return True - -