using custom version of actix-codegen and cors for pow routes

This commit is contained in:
realaravinth
2021-05-25 14:34:24 +05:30
parent 0421cb681c
commit 72667bd2e1
26 changed files with 334 additions and 363 deletions

View File

@@ -25,9 +25,6 @@ use serde::{Deserialize, Serialize};
use super::mcaptcha::get_random;
use crate::errors::*;
use crate::Data;
use crate::*;
pub const AUTH: routes::Auth = routes::Auth::new();
pub mod routes {
pub struct Auth {
@@ -50,16 +47,17 @@ pub mod routes {
}
}
//post!(V1_API_ROUTES.auth.register, signup);
pub fn services(cfg: &mut web::ServiceConfig) {
// protect_get!(cfg, V1_API_ROUTES.auth.logout, signout);
//cfg.service(signup);
cfg.service(signup);
cfg.service(signin);
cfg.service(signout);
define_resource!(cfg, V1_API_ROUTES.auth.register, Methods::Post, signup);
define_resource!(cfg, V1_API_ROUTES.auth.logout, Methods::ProtectGet, signout);
define_resource!(cfg, V1_API_ROUTES.auth.login, Methods::Post, signin);
// define_resource!(cfg, V1_API_ROUTES.auth.register, Methods::Post, signup);
// define_resource!(cfg, V1_API_ROUTES.auth.logout, Methods::ProtectGet, signout);
// define_resource!(cfg, V1_API_ROUTES.auth.login, Methods::Post, signin);
//post!(cfg, V1_API_ROUTES.auth.login, signin);
}
@@ -82,6 +80,7 @@ pub struct Password {
pub password: String,
}
#[my_codegen::post(path="crate::V1_API_ROUTES.auth.register")]
async fn signup(
payload: web::Json<Register>,
data: web::Data<Data>,
@@ -127,8 +126,7 @@ async fn signup(
.execute(&data.db)
.await;
}
if res.is_ok() {
break;
if res.is_ok() { break;
} else {
if let Err(sqlx::Error::Database(err)) = res {
if err.code() == Some(Cow::from("23505")) {
@@ -149,6 +147,7 @@ async fn signup(
Ok(HttpResponse::Ok())
}
#[my_codegen::post(path="crate::V1_API_ROUTES.auth.login")]
async fn signin(
id: Identity,
payload: web::Json<Login>,
@@ -180,6 +179,7 @@ async fn signin(
}
}
#[my_codegen::get(path="crate::V1_API_ROUTES.auth.logout", wrap="crate::CheckLogin")]
async fn signout(id: Identity) -> impl Responder {
if let Some(_) = id.identity() {
id.forget();