You've already forked authentication-service
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:
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user