1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Switch the policies to a violation list based approach

This allows policies to give proper feedback on form fields
This commit is contained in:
Quentin Gliech
2022-06-03 11:59:56 +02:00
parent 88c2625dc0
commit 7c8893e596
9 changed files with 185 additions and 64 deletions

View File

@ -119,8 +119,8 @@ pub(crate) async fn post(
}
let mut policy = policy_factory.instantiate().await?;
let allowed = policy.evaluate_client_registration(&body).await?;
if !allowed {
let res = policy.evaluate_client_registration(&body).await?;
if !res.valid() {
return Err(RouteError::PolicyDenied);
}

View File

@ -136,8 +136,24 @@ pub(crate) async fn post(
.evaluate_register(&form.username, &form.email)
.await?;
if !res {
state.add_error_on_form(FormError::Policy);
for violation in res.violations {
match violation.field.as_deref() {
Some("email") => state.add_error_on_field(
RegisterFormField::Email,
FieldError::Policy {
message: violation.msg,
},
),
Some("username") => state.add_error_on_field(
RegisterFormField::Username,
FieldError::Policy {
message: violation.msg,
},
),
_ => state.add_error_on_form(FormError::Policy {
message: violation.msg,
}),
}
}
state