|
|
@@ -2,6 +2,7 @@ use actix_web::{HttpResponse, web, post};
|
|
|
use validator::ValidateEmail;
|
|
|
use uuid::Uuid;
|
|
|
use serde::Deserialize;
|
|
|
+use serde_json::json;
|
|
|
use std::sync::Mutex;
|
|
|
use crate::{
|
|
|
users::{User, UserAccess},
|
|
|
@@ -23,7 +24,7 @@ pub async fn route(
|
|
|
) -> HttpResponse {
|
|
|
let b = match validate_body(body) {
|
|
|
Ok(b) => b,
|
|
|
- Err(e) => { return HttpResponse::BadRequest().body(e.to_string())}
|
|
|
+ Err(e) => { return HttpResponse::BadRequest().json(json!({"msg": e.to_string()}))}
|
|
|
};
|
|
|
|
|
|
let new_user = User {
|
|
|
@@ -43,11 +44,11 @@ pub async fn route(
|
|
|
User::write(guard.to_vec());
|
|
|
}
|
|
|
|
|
|
- HttpResponse::Ok().body("success")
|
|
|
+ HttpResponse::Ok().json(json!({"msg": "success"}))
|
|
|
}
|
|
|
|
|
|
fn validate_body(body: Body) -> Result<Body, Box<dyn std::error::Error>> {
|
|
|
- if body.email.validate_email() {
|
|
|
+ if !body.email.validate_email() {
|
|
|
return Err("Invalid email".into());
|
|
|
}
|
|
|
|