@@ 6,6 6,7 @@
* See LICENSE for licensing information.
*/
+use actix_session::Session;
use actix_web::{post, web, HttpResponse, Responder};
use email_address::EmailAddress;
@@ 16,6 17,7 @@ use crate::{actions, models, PgPool};
#[post("/api/user")]
pub(crate) async fn create(
pool: web::Data<PgPool>,
+ session: Session,
user: web::Json<models::InsertableUser>,
) -> impl Responder {
if user.username.len() < 3 {
@@ 48,7 50,10 @@ pub(crate) async fn create(
Err(err) => {
return HttpResponse::InternalServerError().json(err);
}
- Ok(user) => HttpResponse::Ok().json(user),
+ Ok(user) => match session.insert("user_id", user.id) {
+ Err(err) => HttpResponse::InternalServerError().body(err.to_string()),
+ Ok(_) => HttpResponse::Ok().json(user),
+ },
},
}
}