-
Notifications
You must be signed in to change notification settings - Fork 1
/
register_request.rs
30 lines (28 loc) · 1.15 KB
/
register_request.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use crate::generated::components::{request_bodies, responses};
use crate::generated::paths::register_request;
use actix_swagger::Answer;
use actix_web::web;
pub async fn route(
body: web::Json<request_bodies::Register>,
app: web::Data<crate::App>,
) -> Answer<'static, register_request::Response> {
use authmenow_public_app::registrator::{
CreateRegisterRequest,
RegisterRequestError::{EmailAlreadyRegistered, InvalidForm, Unexpected},
Registrator,
};
use register_request::Response;
match app.create_register_request(CreateRegisterRequest::from_email(&body.email)) {
Err(EmailAlreadyRegistered) => Response::BadRequest(responses::RegisterFailed {
error: responses::RegisterFailedError::EmailAlreadyRegistered,
}),
Err(InvalidForm) => Response::BadRequest(responses::RegisterFailed {
error: responses::RegisterFailedError::InvalidForm,
}),
Err(Unexpected) => Response::Unexpected,
Ok(request) => Response::Created(responses::RegistrationRequestCreated {
expires_at: request.expires_at.timestamp_millis(),
}),
}
.answer()
}