Improved UI

This commit is contained in:
Spitap
2022-12-29 19:03:28 +01:00
parent cc89b23d2e
commit 391180090d
5 changed files with 21 additions and 31 deletions
@@ -102,29 +102,25 @@ export default {
id: this.id
}
this.loading = true
document.getElementById('password_validation').innerHTML = ''
auth.changePassword(payload).then(resp => {
document.getElementById('password_validation').innerHTML = ''
if (resp.status === 200) {
this.loading = false
this.returnLogin()
}
}).catch(err => {
let message = ''
this.loading = false
if (err.response.status === 403) {
this.$refs.observer.setErrors({
password_confirmed: this.$gettext('Invalid reset token.')
})
message = this.$gettext('Invalid reset token.')
} else if (err.response.status === 404) {
this.$refs.observer.setErrors({
password_confirmed: this.$gettext('User unknown.')
})
message = this.$gettext('User unknown.')
} else if (err.response.status === 400 && err.response.data.type === 'password_requirement') {
let message = ''
err.response.data.errors.forEach(element => {
message += this.$gettext(element) + '<br>'
})
document.getElementById('password_validation').innerHTML = message
}
document.getElementById('password_validation').innerHTML = message
})
}
},
@@ -57,9 +57,6 @@ export default {
return {
loading: false,
sms_totp: '',
password: '',
password_confirmed: '',
user_pk: -1,
errors: {}
}
},
@@ -67,12 +64,10 @@ export default {
returnLogin () {
this.$router.push({ name: 'Login' })
},
async userPkError () {
async showErrorDialog (body) {
const confirm = await this.$refs.confirm.open(
this.$gettext('Error'),
this.$gettext(
'User seems wrong, return to login or restart reset the process?'
),
this.$gettext(body),
{
color: 'error',
cancelLabel: this.$gettext('Return to login'),
@@ -96,7 +91,7 @@ export default {
}).catch(err => {
if (err.response.status === 400) {
this.loading = false
this.userPkError()
this.showErrorDialog('User seems wrong, return to login or restart reset the process?')
}
})
},
@@ -118,9 +113,11 @@ export default {
}
}).catch(err => {
this.loading = false
if (err.response.status === 500) {
if (err.response.status === 403 && 'reason' in err.response.data) {
this.showErrorDialog(err.response.data.reason)
} else if (err.response.status === 400 && 'reason' in err.response.data) {
this.$refs.observer.setErrors({
password_confirmed: this.$gettext('Invalid totp.')
sms_totp: this.$gettext(err.response.data.reason)
})
}
})
+2 -4
View File
@@ -375,9 +375,8 @@ class PasswordRecoverySmsConfirmSerializer(serializers.Serializer):
except KeyError:
raise CustomValidationError(
{"reason": "totp secret not set in session"}, 403)
if not oath.accept_totp(self.context["totp_secret"], data["sms_totp"])[0]:
raise CustomValidationError({"reason": "Wrong totp"}, 403)
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(
@@ -453,8 +452,7 @@ class PasswordRecoveryConfirmSerializer(serializers.Serializer):
try:
password_validation.validate_password(data["new_password1"], user)
except djangoValidationError as e:
raise PasswordRequirementsFailure(e.error_list)
raise PasswordRequirementsFailure(e.messages)
self.context["user"] = user
return super().validate(data)
+1 -1
View File
@@ -317,7 +317,7 @@ class PasswordResetTestCase(AccountViewSetTestCase):
# False totp code
data = {"sms_totp": "123456", "type": "confirm"}
response = self.client.post(url_sms_totp, data, format="json")
self.assertEqual(response.status_code, 403)
self.assertEqual(response.status_code, 400)
self.assertEqual(response.json()["reason"], "Wrong totp")
# Good totp code
+6 -7
View File
@@ -147,13 +147,12 @@ class PasswordResetConfirmView(APIView):
try:
serializer.is_valid(raise_exception=True)
except PasswordRequirementsFailure as e:
if type(e) == PasswordRequirementsFailure:
data = {"type": "password_requirement"}
errors = []
for element in e.message_list:
errors.append(element)
data.update({"errors": errors})
return response.Response(data, 400)
data = {"type": "password_requirement"}
errors = []
for element in e.message_list:
errors.append(element)
data.update({"errors": errors})
return response.Response(data, 400)
serializer.save()
return response.Response(status=200)