Few updates

This commit is contained in:
Antoine Nguyen
2023-01-11 10:55:06 +01:00
parent 391180090d
commit f91edc84b0
4 changed files with 23 additions and 32 deletions
+3 -8
View File
@@ -34,7 +34,9 @@
outlined
/>
</validation-provider>
<a @click="recoverPass" class="float-right primary--text"><translate>Forgot password?</translate></a>
<router-link :to="{ name: 'PasswordRecoveryForm' }" class="float-right primary--text">
<translate>Forgot password?</translate>
</router-link>
<v-checkbox
v-model="rememberMe"
:label="'Remember me'|translate"
@@ -70,9 +72,6 @@ export default {
}
},
methods: {
recoverPass () {
this.$router.push({ name: 'PasswordRecoveryForm' })
},
async authenticate () {
const isValid = await this.$refs.observer.validate()
if (!isValid) {
@@ -101,7 +100,3 @@ export default {
}
}
</script>
<style>
</style>
@@ -15,7 +15,7 @@
v-slot="{ errors }"
rules="required"
>
<p id="password_validation"></p>
<p id="password_validation">{{ password_validation_error }}</p>
<label class="m-label"><translate>Change password</translate></label>
<v-text-field
v-model="password"
@@ -49,7 +49,9 @@
</v-btn>
</div>
<div>
<a @click="returnLogin" class="float-right primary--text"><translate>Return to login?</translate></a>
<router-link :to="{ name: 'Login' }" class="float-right primary--text">
<translate>Return to login</translate>
</router-link>
</div>
</v-col>
</v-row>
@@ -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) + '<br>'
})
}
document.getElementById('password_validation').innerHTML = message
this.password_validation_error = message
})
}
},
@@ -39,7 +39,7 @@
</div>
<div>
<a @click="resendSms" class="float-left primary--text"><translate>Resend SMS.</translate></a>
<a @click="returnLogin" class="float-right primary--text"><translate>Return to login?</translate></a>
<router-link :to="{ name: 'Login' }" class="float-right primary--text"><translate>Return to login</translate></router-link>
</div>
</v-col>
</v-row>
@@ -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?'))
}
})
},
+11 -12
View File
@@ -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