Skip to main content

ayb/server/ui_endpoints/
register.rs

1use crate::ayb_db::models::EntityType;
2use crate::server::config::AybConfig;
3use crate::server::ui_endpoints::auth::init_ayb_client;
4use crate::server::ui_endpoints::templates::ok_response;
5use actix_web::{get, post, web, HttpRequest, HttpResponse, Result};
6
7#[get("/register")]
8pub async fn register() -> Result<HttpResponse> {
9    ok_response("register.html", &tera::Context::new())
10}
11
12#[derive(serde::Deserialize)]
13pub struct RegisterForm {
14    username: String,
15    email: String,
16}
17
18#[post("/register")]
19pub async fn register_submit(
20    req: HttpRequest,
21    form: web::Form<RegisterForm>,
22    ayb_config: web::Data<AybConfig>,
23) -> Result<HttpResponse> {
24    let client = init_ayb_client(&ayb_config, &req);
25
26    match client
27        .register(&form.username, &form.email, &EntityType::User)
28        .await
29    {
30        Ok(_) => ok_response("register_check_email.html", &tera::Context::new()),
31        Err(_) => ok_response("register_error.html", &tera::Context::new()),
32    }
33}