mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-13 19:15:39 +00:00
cleanup
This commit is contained in:
@@ -22,8 +22,7 @@ use super::auth::Password;
|
|||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
|
||||||
//#[post("/api/v1/account/delete", wrap = "CheckLogin")]
|
async fn delete_account(
|
||||||
pub async fn delete_account(
|
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Json<Password>,
|
payload: web::Json<Password>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -58,3 +57,15 @@ pub async fn delete_account(
|
|||||||
Err(_) => return Err(ServiceError::InternalServerError)?,
|
Err(_) => return Err(ServiceError::InternalServerError)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
use crate::define_resource;
|
||||||
|
use crate::V1_API_ROUTES;
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.delete,
|
||||||
|
Methods::ProtectPost,
|
||||||
|
delete_account
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ pub struct Email {
|
|||||||
pub email: String,
|
pub email: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/account/email/exists")]
|
|
||||||
pub async fn email_exists(
|
pub async fn email_exists(
|
||||||
payload: web::Json<AccountCheckPayload>,
|
payload: web::Json<AccountCheckPayload>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -53,9 +52,7 @@ pub async fn email_exists(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// update email
|
/// update email
|
||||||
//#[post("/api/v1/account/email/", wrap = "CheckLogin")]
|
async fn set_email(
|
||||||
//#[post("/api/v1/", wrap = "CheckLogin")]
|
|
||||||
pub async fn set_email(
|
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Json<Email>,
|
payload: web::Json<Email>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -85,3 +82,22 @@ pub async fn set_email(
|
|||||||
}
|
}
|
||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
use crate::define_resource;
|
||||||
|
use crate::V1_API_ROUTES;
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.email_exists,
|
||||||
|
Methods::Post,
|
||||||
|
email_exists
|
||||||
|
);
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.update_email,
|
||||||
|
Methods::Post,
|
||||||
|
set_email
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -69,48 +69,8 @@ pub struct AccountCheckResp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
use crate::define_resource;
|
delete::services(cfg);
|
||||||
use crate::V1_API_ROUTES;
|
email::services(cfg);
|
||||||
|
username::services(cfg);
|
||||||
define_resource!(
|
secret::services(cfg);
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.delete,
|
|
||||||
Methods::ProtectPost,
|
|
||||||
delete::delete_account
|
|
||||||
);
|
|
||||||
|
|
||||||
define_resource!(
|
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.username_exists,
|
|
||||||
Methods::Post,
|
|
||||||
username::username_exists
|
|
||||||
);
|
|
||||||
|
|
||||||
define_resource!(
|
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.email_exists,
|
|
||||||
Methods::Post,
|
|
||||||
email::email_exists
|
|
||||||
);
|
|
||||||
|
|
||||||
define_resource!(
|
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.update_email,
|
|
||||||
Methods::Post,
|
|
||||||
email::set_email
|
|
||||||
);
|
|
||||||
|
|
||||||
define_resource!(
|
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.get_secret,
|
|
||||||
Methods::ProtectGet,
|
|
||||||
secret::get_secret
|
|
||||||
);
|
|
||||||
|
|
||||||
define_resource!(
|
|
||||||
cfg,
|
|
||||||
V1_API_ROUTES.account.update_secret,
|
|
||||||
Methods::ProtectPost,
|
|
||||||
secret::update_user_secret
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ pub struct Secret {
|
|||||||
pub secret: String,
|
pub secret: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[get("/api/v1/account/secret/", wrap = "CheckLogin")]
|
async fn get_secret(id: Identity, data: web::Data<Data>) -> ServiceResult<impl Responder> {
|
||||||
pub async fn get_secret(id: Identity, data: web::Data<Data>) -> ServiceResult<impl Responder> {
|
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
|
|
||||||
let secret = sqlx::query_as!(
|
let secret = sqlx::query_as!(
|
||||||
@@ -44,11 +43,7 @@ pub async fn get_secret(id: Identity, data: web::Data<Data>) -> ServiceResult<im
|
|||||||
Ok(HttpResponse::Ok().json(secret))
|
Ok(HttpResponse::Ok().json(secret))
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/account/secret/", wrap = "CheckLogin")]
|
async fn update_user_secret(id: Identity, data: web::Data<Data>) -> ServiceResult<impl Responder> {
|
||||||
pub async fn update_user_secret(
|
|
||||||
id: Identity,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
|
|
||||||
let mut secret;
|
let mut secret;
|
||||||
@@ -79,3 +74,22 @@ pub async fn update_user_secret(
|
|||||||
}
|
}
|
||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
use crate::define_resource;
|
||||||
|
use crate::V1_API_ROUTES;
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.get_secret,
|
||||||
|
Methods::ProtectGet,
|
||||||
|
get_secret
|
||||||
|
);
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.update_secret,
|
||||||
|
Methods::ProtectPost,
|
||||||
|
update_user_secret
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ use super::{AccountCheckPayload, AccountCheckResp};
|
|||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
use crate::Data;
|
use crate::Data;
|
||||||
|
|
||||||
//#[post("/api/v1/account/username/exists")]
|
async fn username_exists(
|
||||||
pub async fn username_exists(
|
|
||||||
payload: web::Json<AccountCheckPayload>,
|
payload: web::Json<AccountCheckPayload>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
) -> ServiceResult<impl Responder> {
|
) -> ServiceResult<impl Responder> {
|
||||||
@@ -42,3 +41,15 @@ pub async fn username_exists(
|
|||||||
|
|
||||||
Ok(HttpResponse::Ok().json(resp))
|
Ok(HttpResponse::Ok().json(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
|
use crate::define_resource;
|
||||||
|
use crate::V1_API_ROUTES;
|
||||||
|
|
||||||
|
define_resource!(
|
||||||
|
cfg,
|
||||||
|
V1_API_ROUTES.account.username_exists,
|
||||||
|
Methods::Post,
|
||||||
|
username_exists
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,246 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Affero General Public License as
|
|
||||||
* published by the Free Software Foundation, either version 3 of the
|
|
||||||
* License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Affero General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Affero General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use actix_identity::Identity;
|
|
||||||
use actix_web::{get, post, web, HttpResponse, Responder};
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use super::auth::Password;
|
|
||||||
use super::mcaptcha::get_random;
|
|
||||||
use crate::errors::*;
|
|
||||||
use crate::CheckLogin;
|
|
||||||
use crate::Data;
|
|
||||||
|
|
||||||
pub mod routes {
|
|
||||||
|
|
||||||
pub struct Account {
|
|
||||||
pub delete: &'static str,
|
|
||||||
pub email_exists: &'static str,
|
|
||||||
pub update_email: &'static str,
|
|
||||||
pub get_secret: &'static str,
|
|
||||||
pub update_secret: &'static str,
|
|
||||||
pub username_exists: &'static str,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Account {
|
|
||||||
pub const fn new() -> Account {
|
|
||||||
let get_secret = "/api/v1/account/secret/";
|
|
||||||
let update_secret = "/api/v1/account/secret";
|
|
||||||
let delete = "/api/v1/account/delete";
|
|
||||||
let email_exists = "/api/v1/account/email/exists";
|
|
||||||
let username_exists = "/api/v1/account/username/exists";
|
|
||||||
let update_email = "/api/v1/account/email/";
|
|
||||||
Account {
|
|
||||||
get_secret,
|
|
||||||
update_secret,
|
|
||||||
username_exists,
|
|
||||||
update_email,
|
|
||||||
delete,
|
|
||||||
email_exists,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/api/v1/account/delete", wrap = "CheckLogin")]
|
|
||||||
pub async fn delete_account(
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Json<Password>,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
use argon2_creds::Config;
|
|
||||||
use sqlx::Error::RowNotFound;
|
|
||||||
|
|
||||||
let username = id.identity().unwrap();
|
|
||||||
|
|
||||||
let rec = sqlx::query_as!(
|
|
||||||
Password,
|
|
||||||
r#"SELECT password FROM mcaptcha_users WHERE name = ($1)"#,
|
|
||||||
&username,
|
|
||||||
)
|
|
||||||
.fetch_one(&data.db)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
id.forget();
|
|
||||||
|
|
||||||
match rec {
|
|
||||||
Ok(s) => {
|
|
||||||
if Config::verify(&s.password, &payload.password)? {
|
|
||||||
sqlx::query!("DELETE FROM mcaptcha_users WHERE name = ($1)", &username)
|
|
||||||
.execute(&data.db)
|
|
||||||
.await?;
|
|
||||||
Ok(HttpResponse::Ok())
|
|
||||||
} else {
|
|
||||||
Err(ServiceError::WrongPassword)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(RowNotFound) => return Err(ServiceError::UsernameNotFound),
|
|
||||||
Err(_) => return Err(ServiceError::InternalServerError)?,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct AccountCheckPayload {
|
|
||||||
pub val: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct AccountCheckResp {
|
|
||||||
pub exists: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/api/v1/account/username/exists")]
|
|
||||||
pub async fn username_exists(
|
|
||||||
payload: web::Json<AccountCheckPayload>,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (SELECT 1 from mcaptcha_users WHERE name = $1)",
|
|
||||||
&payload.val,
|
|
||||||
)
|
|
||||||
.fetch_one(&data.db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut resp = AccountCheckResp { exists: false };
|
|
||||||
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
if x {
|
|
||||||
resp.exists = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(resp))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/api/v1/account/email/exists")]
|
|
||||||
pub async fn email_exists(
|
|
||||||
payload: web::Json<AccountCheckPayload>,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"SELECT EXISTS (SELECT 1 from mcaptcha_users WHERE email = $1)",
|
|
||||||
&payload.val,
|
|
||||||
)
|
|
||||||
.fetch_one(&data.db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
let mut resp = AccountCheckResp { exists: false };
|
|
||||||
|
|
||||||
if let Some(x) = res.exists {
|
|
||||||
if x {
|
|
||||||
resp.exists = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(resp))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Secret {
|
|
||||||
pub secret: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[get("/api/v1/account/secret/", wrap = "CheckLogin")]
|
|
||||||
pub async fn get_secret(id: Identity, data: web::Data<Data>) -> ServiceResult<impl Responder> {
|
|
||||||
let username = id.identity().unwrap();
|
|
||||||
|
|
||||||
let secret = sqlx::query_as!(
|
|
||||||
Secret,
|
|
||||||
r#"SELECT secret FROM mcaptcha_users WHERE name = ($1)"#,
|
|
||||||
&username,
|
|
||||||
)
|
|
||||||
.fetch_one(&data.db)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().json(secret))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[post("/api/v1/account/secret/", wrap = "CheckLogin")]
|
|
||||||
pub async fn update_user_secret(
|
|
||||||
id: Identity,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
let username = id.identity().unwrap();
|
|
||||||
|
|
||||||
let mut secret;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
secret = get_random(32);
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"UPDATE mcaptcha_users set secret = $1
|
|
||||||
WHERE name = $2",
|
|
||||||
&secret,
|
|
||||||
&username,
|
|
||||||
)
|
|
||||||
.execute(&data.db)
|
|
||||||
.await;
|
|
||||||
if res.is_ok() {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
if let Err(sqlx::Error::Database(err)) = res {
|
|
||||||
if err.code() == Some(Cow::from("23505"))
|
|
||||||
&& err.message().contains("mcaptcha_users_secret_key")
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
Err(sqlx::Error::Database(err))?;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(HttpResponse::Ok())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
||||||
pub struct Email {
|
|
||||||
pub email: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// update email
|
|
||||||
//#[post("/api/v1/account/email/", wrap = "CheckLogin")]
|
|
||||||
#[post("/api/v1/", wrap = "CheckLogin")]
|
|
||||||
pub async fn set_email(
|
|
||||||
id: Identity,
|
|
||||||
payload: web::Json<Email>,
|
|
||||||
data: web::Data<Data>,
|
|
||||||
) -> ServiceResult<impl Responder> {
|
|
||||||
let username = id.identity().unwrap();
|
|
||||||
|
|
||||||
data.creds.email(&payload.email)?;
|
|
||||||
|
|
||||||
let res = sqlx::query!(
|
|
||||||
"UPDATE mcaptcha_users set email = $1
|
|
||||||
WHERE name = $2",
|
|
||||||
&payload.email,
|
|
||||||
&username,
|
|
||||||
)
|
|
||||||
.execute(&data.db)
|
|
||||||
.await;
|
|
||||||
if !res.is_ok() {
|
|
||||||
if let Err(sqlx::Error::Database(err)) = res {
|
|
||||||
if err.code() == Some(Cow::from("23505"))
|
|
||||||
&& err.message().contains("mcaptcha_users_email_key")
|
|
||||||
{
|
|
||||||
Err(ServiceError::EmailTaken)?
|
|
||||||
} else {
|
|
||||||
Err(sqlx::Error::Database(err))?
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Ok(HttpResponse::Ok())
|
|
||||||
}
|
|
||||||
@@ -75,7 +75,6 @@ pub struct Password {
|
|||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/signup")]
|
|
||||||
async fn signup(
|
async fn signup(
|
||||||
payload: web::Json<Register>,
|
payload: web::Json<Register>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -143,7 +142,6 @@ async fn signup(
|
|||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/signin")]
|
|
||||||
async fn signin(
|
async fn signin(
|
||||||
id: Identity,
|
id: Identity,
|
||||||
payload: web::Json<Login>,
|
payload: web::Json<Login>,
|
||||||
@@ -175,7 +173,6 @@ async fn signin(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[get("/logout", wrap = "CheckLogin")]
|
|
||||||
async fn signout(id: Identity) -> impl Responder {
|
async fn signout(id: Identity) -> impl Responder {
|
||||||
if let Some(_) = id.identity() {
|
if let Some(_) = id.identity() {
|
||||||
id.forget();
|
id.forget();
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ pub struct UpdateDuration {
|
|||||||
pub duration: i32,
|
pub duration: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")]
|
|
||||||
async fn update_duration(
|
async fn update_duration(
|
||||||
payload: web::Json<UpdateDuration>,
|
payload: web::Json<UpdateDuration>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -82,7 +81,6 @@ pub struct GetDuration {
|
|||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")]
|
|
||||||
async fn get_duration(
|
async fn get_duration(
|
||||||
payload: web::Json<MCaptchaDetails>,
|
payload: web::Json<MCaptchaDetails>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ pub mod routes {
|
|||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct AddLevels {
|
pub struct AddLevels {
|
||||||
pub levels: Vec<Level>,
|
pub levels: Vec<Level>,
|
||||||
// name is config_name
|
/// name is config_name
|
||||||
pub key: String,
|
pub key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,6 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
|||||||
|
|
||||||
// TODO try for non-existent token names
|
// TODO try for non-existent token names
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/levels/add", wrap = "CheckLogin")]
|
|
||||||
async fn add_levels(
|
async fn add_levels(
|
||||||
payload: web::Json<AddLevels>,
|
payload: web::Json<AddLevels>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -130,7 +129,6 @@ async fn add_levels(
|
|||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/levels/update", wrap = "CheckLogin")]
|
|
||||||
async fn update_levels(
|
async fn update_levels(
|
||||||
payload: web::Json<AddLevels>,
|
payload: web::Json<AddLevels>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -188,7 +186,6 @@ async fn update_levels(
|
|||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/levels/delete", wrap = "CheckLogin")]
|
|
||||||
async fn delete_levels(
|
async fn delete_levels(
|
||||||
payload: web::Json<AddLevels>,
|
payload: web::Json<AddLevels>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -215,7 +212,6 @@ async fn delete_levels(
|
|||||||
Ok(HttpResponse::Ok())
|
Ok(HttpResponse::Ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/levels/get", wrap = "CheckLogin")]
|
|
||||||
async fn get_levels(
|
async fn get_levels(
|
||||||
payload: web::Json<MCaptchaDetails>,
|
payload: web::Json<MCaptchaDetails>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -281,23 +277,6 @@ mod tests {
|
|||||||
let (data, _, signin_resp, key) = add_levels_util(NAME, PASSWORD).await;
|
let (data, _, signin_resp, key) = add_levels_util(NAME, PASSWORD).await;
|
||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let mut app = get_app!(data).await;
|
let mut app = get_app!(data).await;
|
||||||
/*
|
|
||||||
|
|
||||||
let add_level = AddLevels {
|
|
||||||
levels: levels.clone(),
|
|
||||||
key: key.key.clone(),
|
|
||||||
};
|
|
||||||
|
|
||||||
// 1. add level
|
|
||||||
let add_token_resp = test::call_service(
|
|
||||||
&mut app,
|
|
||||||
post_request!(&add_level, ADD_URL)
|
|
||||||
.cookie(cookies.clone())
|
|
||||||
.to_request(),
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
assert_eq!(add_token_resp.status(), StatusCode::OK);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// 2. get level
|
// 2. get level
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ pub struct MCaptchaDetails {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this should be called from within add levels
|
// this should be called from within add levels
|
||||||
//#[post("/api/v1/mcaptcha/add", wrap = "CheckLogin")]
|
|
||||||
async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
|
async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
|
||||||
let username = id.identity().unwrap();
|
let username = id.identity().unwrap();
|
||||||
let mut key;
|
let mut key;
|
||||||
@@ -130,7 +129,6 @@ async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl
|
|||||||
Ok(HttpResponse::Ok().json(resp))
|
Ok(HttpResponse::Ok().json(resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/update/key", wrap = "CheckLogin")]
|
|
||||||
async fn update_token(
|
async fn update_token(
|
||||||
payload: web::Json<MCaptchaDetails>,
|
payload: web::Json<MCaptchaDetails>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -181,7 +179,6 @@ async fn update_token_helper(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/get", wrap = "CheckLogin")]
|
|
||||||
async fn get_token(
|
async fn get_token(
|
||||||
payload: web::Json<MCaptchaDetails>,
|
payload: web::Json<MCaptchaDetails>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -209,7 +206,6 @@ async fn get_token(
|
|||||||
Ok(HttpResponse::Ok().json(res))
|
Ok(HttpResponse::Ok().json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[post("/api/v1/mcaptcha/delete", wrap = "CheckLogin")]
|
|
||||||
async fn delete_mcaptcha(
|
async fn delete_mcaptcha(
|
||||||
payload: web::Json<MCaptchaDetails>,
|
payload: web::Json<MCaptchaDetails>,
|
||||||
data: web::Data<Data>,
|
data: web::Data<Data>,
|
||||||
@@ -264,10 +260,6 @@ mod tests {
|
|||||||
let cookies = get_cookie!(signin_resp);
|
let cookies = get_cookie!(signin_resp);
|
||||||
let mut app = get_app!(data).await;
|
let mut app = get_app!(data).await;
|
||||||
|
|
||||||
// let mut domain = MCaptchaID {
|
|
||||||
// name: TOKEN_NAME.into(),
|
|
||||||
// };
|
|
||||||
|
|
||||||
// 4. delete token
|
// 4. delete token
|
||||||
let del_token = test::call_service(
|
let del_token = test::call_service(
|
||||||
&mut app,
|
&mut app,
|
||||||
|
|||||||
@@ -92,13 +92,12 @@ mod tests {
|
|||||||
use actix_web::{http::StatusCode, test, App};
|
use actix_web::{http::StatusCode, test, App};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::api::v1::new_services;
|
use crate::api::v1::services;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn build_details_works() {
|
async fn build_details_works() {
|
||||||
// const GET_URI: &str = "/api/v1/meta/build";
|
let mut app = test::init_service(App::new().configure(services)).await;
|
||||||
let mut app = test::init_service(App::new().configure(new_services)).await;
|
|
||||||
|
|
||||||
let resp = test::call_service(
|
let resp = test::call_service(
|
||||||
&mut app,
|
&mut app,
|
||||||
@@ -112,8 +111,6 @@ mod tests {
|
|||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn health_works() {
|
async fn health_works() {
|
||||||
// const GET_URI: &str = "/api/v1/meta/health";
|
|
||||||
|
|
||||||
println!("{}", V1_API_ROUTES.meta.health);
|
println!("{}", V1_API_ROUTES.meta.health);
|
||||||
let data = Data::new().await;
|
let data = Data::new().await;
|
||||||
let mut app = get_app!(data).await;
|
let mut app = get_app!(data).await;
|
||||||
|
|||||||
@@ -26,87 +26,11 @@ mod routes;
|
|||||||
|
|
||||||
pub use routes::ROUTES;
|
pub use routes::ROUTES;
|
||||||
|
|
||||||
pub fn services(_cfg: &mut ServiceConfig) {
|
pub fn services(cfg: &mut ServiceConfig) {
|
||||||
// mcaptcha
|
|
||||||
//cfg.service(mcaptcha::mcaptcha::add_mcaptcha);
|
|
||||||
//cfg.service(mcaptcha::mcaptcha::delete_mcaptcha);
|
|
||||||
//cfg.service(mcaptcha::mcaptcha::update_token);
|
|
||||||
//cfg.service(mcaptcha::mcaptcha::get_token);
|
|
||||||
|
|
||||||
// levels
|
|
||||||
//cfg.service(mcaptcha::levels::add_levels);
|
|
||||||
//cfg.service(mcaptcha::levels::update_levels);
|
|
||||||
//cfg.service(mcaptcha::levels::delete_levels);
|
|
||||||
//cfg.service(mcaptcha::levels::get_levels);
|
|
||||||
|
|
||||||
// // duration
|
|
||||||
// cfg.service(mcaptcha::duration::update_duration);
|
|
||||||
// cfg.service(mcaptcha::duration::get_duration);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_services(cfg: &mut ServiceConfig) {
|
|
||||||
meta::services(cfg);
|
meta::services(cfg);
|
||||||
auth::services(cfg);
|
auth::services(cfg);
|
||||||
account::services(cfg);
|
account::services(cfg);
|
||||||
mcaptcha::services(cfg);
|
mcaptcha::services(cfg);
|
||||||
|
|
||||||
//define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.meta.build_details,
|
|
||||||
// Methods::Get,
|
|
||||||
// meta::build_details
|
|
||||||
//);
|
|
||||||
//define_resource!(cfg, ROUTES.meta.health, Methods::Get, meta::health);
|
|
||||||
|
|
||||||
// auth
|
|
||||||
|
|
||||||
//define_resource!(cfg, ROUTES.auth.register, Methods::Post, auth::signup);
|
|
||||||
//define_resource!(cfg, ROUTES.auth.logout, Methods::ProtectGet, auth::signout);
|
|
||||||
//define_resource!(cfg, ROUTES.auth.login, Methods::Post, auth::signin);
|
|
||||||
|
|
||||||
// account
|
|
||||||
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.delete,
|
|
||||||
// Methods::ProtectPost,
|
|
||||||
// account::delete::delete_account
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.username_exists,
|
|
||||||
// Methods::Post,
|
|
||||||
// account::username::username_exists
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.email_exists,
|
|
||||||
// Methods::Post,
|
|
||||||
// account::email::email_exists
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.update_email,
|
|
||||||
// Methods::Post,
|
|
||||||
// account::email::set_email
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.get_secret,
|
|
||||||
// Methods::ProtectGet,
|
|
||||||
// account::secret::get_secret
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// define_resource!(
|
|
||||||
// cfg,
|
|
||||||
// ROUTES.account.update_secret,
|
|
||||||
// Methods::ProtectPost,
|
|
||||||
// account::secret::update_user_secret
|
|
||||||
// );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ use actix_web::{
|
|||||||
use argon2_creds::errors::CredsError;
|
use argon2_creds::errors::CredsError;
|
||||||
//use awc::error::SendRequestError;
|
//use awc::error::SendRequestError;
|
||||||
use derive_more::{Display, Error};
|
use derive_more::{Display, Error};
|
||||||
use log::debug;
|
|
||||||
use m_captcha::errors::CaptchaError;
|
use m_captcha::errors::CaptchaError;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use url::ParseError;
|
use url::ParseError;
|
||||||
@@ -140,7 +139,6 @@ impl ResponseError for ServiceError {
|
|||||||
impl From<CredsError> for ServiceError {
|
impl From<CredsError> for ServiceError {
|
||||||
#[cfg(not(tarpaulin_include))]
|
#[cfg(not(tarpaulin_include))]
|
||||||
fn from(e: CredsError) -> ServiceError {
|
fn from(e: CredsError) -> ServiceError {
|
||||||
debug!("{:?}", &e);
|
|
||||||
match e {
|
match e {
|
||||||
CredsError::UsernameCaseMappedError => ServiceError::UsernameCaseMappedError,
|
CredsError::UsernameCaseMappedError => ServiceError::UsernameCaseMappedError,
|
||||||
CredsError::ProfainityError => ServiceError::ProfainityError,
|
CredsError::ProfainityError => ServiceError::ProfainityError,
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ async fn main() -> std::io::Result<()> {
|
|||||||
))
|
))
|
||||||
.configure(v1::pow::services)
|
.configure(v1::pow::services)
|
||||||
.configure(v1::services)
|
.configure(v1::services)
|
||||||
.configure(v1::new_services)
|
|
||||||
.configure(docs::services)
|
.configure(docs::services)
|
||||||
.configure(static_assets::services)
|
.configure(static_assets::services)
|
||||||
.configure(templates::services)
|
.configure(templates::services)
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ macro_rules! get_app {
|
|||||||
))
|
))
|
||||||
.configure(crate::api::v1::pow::services)
|
.configure(crate::api::v1::pow::services)
|
||||||
.configure(crate::api::v1::services)
|
.configure(crate::api::v1::services)
|
||||||
.configure(crate::api::v1::new_services)
|
|
||||||
.data($data.clone()),
|
.data($data.clone()),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user