mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 18:45:41 +00:00
api endpoints migrated to use auth middleware
This commit is contained in:
@@ -19,9 +19,9 @@ use actix_identity::Identity;
|
||||
use actix_web::{post, web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::is_authenticated;
|
||||
use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails;
|
||||
use crate::errors::*;
|
||||
use crate::CheckLogin;
|
||||
use crate::Data;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
@@ -30,13 +30,12 @@ pub struct UpdateDuration {
|
||||
pub duration: i32,
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/domain/token/duration/update")]
|
||||
#[post("/api/v1/mcaptcha/domain/token/duration/update", wrap = "CheckLogin")]
|
||||
pub async fn update_duration(
|
||||
payload: web::Json<UpdateDuration>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
if payload.duration > 0 {
|
||||
@@ -69,13 +68,12 @@ pub struct GetDuration {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/domain/token/duration/get")]
|
||||
#[post("/api/v1/mcaptcha/domain/token/duration/get", wrap = "CheckLogin")]
|
||||
pub async fn get_duration(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
let duration = sqlx::query_as!(
|
||||
|
||||
@@ -20,9 +20,9 @@ use actix_web::{post, web, HttpResponse, Responder};
|
||||
use m_captcha::{defense::Level, DefenseBuilder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::is_authenticated;
|
||||
use crate::api::v1::mcaptcha::mcaptcha::MCaptchaDetails;
|
||||
use crate::errors::*;
|
||||
use crate::CheckLogin;
|
||||
use crate::Data;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -34,13 +34,12 @@ pub struct AddLevels {
|
||||
|
||||
// TODO try for non-existent token names
|
||||
|
||||
#[post("/api/v1/mcaptcha/levels/add")]
|
||||
#[post("/api/v1/mcaptcha/levels/add", wrap = "CheckLogin")]
|
||||
pub async fn add_levels(
|
||||
payload: web::Json<AddLevels>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let mut defense = DefenseBuilder::default();
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
@@ -75,13 +74,12 @@ pub async fn add_levels(
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/levels/update")]
|
||||
#[post("/api/v1/mcaptcha/levels/update", wrap = "CheckLogin")]
|
||||
pub async fn update_levels(
|
||||
payload: web::Json<AddLevels>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
let mut defense = DefenseBuilder::default();
|
||||
|
||||
@@ -134,13 +132,12 @@ pub async fn update_levels(
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/levels/delete")]
|
||||
#[post("/api/v1/mcaptcha/levels/delete", wrap = "CheckLogin")]
|
||||
pub async fn delete_levels(
|
||||
payload: web::Json<AddLevels>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
for level in payload.levels.iter() {
|
||||
@@ -162,13 +159,12 @@ pub async fn delete_levels(
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/levels/get")]
|
||||
#[post("/api/v1/mcaptcha/levels/get", wrap = "CheckLogin")]
|
||||
pub async fn get_levels(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
let levels = get_levels_util(&payload.key, &username, &data).await?;
|
||||
|
||||
@@ -20,8 +20,9 @@ use actix_identity::Identity;
|
||||
use actix_web::{post, web, HttpResponse, Responder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::{get_random, is_authenticated};
|
||||
use super::get_random;
|
||||
use crate::errors::*;
|
||||
use crate::CheckLogin;
|
||||
use crate::Data;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -35,9 +36,8 @@ pub struct MCaptchaDetails {
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/add")]
|
||||
#[post("/api/v1/mcaptcha/add", wrap = "CheckLogin")]
|
||||
pub async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
let mut key;
|
||||
|
||||
@@ -78,7 +78,7 @@ pub async fn add_mcaptcha(data: web::Data<Data>, id: Identity) -> ServiceResult<
|
||||
Ok(HttpResponse::Ok().json(resp))
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/update/key")]
|
||||
#[post("/api/v1/mcaptcha/update/key", wrap = "CheckLogin")]
|
||||
pub async fn update_token(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
@@ -86,7 +86,6 @@ pub async fn update_token(
|
||||
) -> ServiceResult<impl Responder> {
|
||||
use std::borrow::Cow;
|
||||
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
let mut key;
|
||||
|
||||
@@ -132,13 +131,12 @@ async fn update_token_helper(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/get")]
|
||||
#[post("/api/v1/mcaptcha/get", wrap = "CheckLogin")]
|
||||
pub async fn get_token(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
let res = match sqlx::query_as!(
|
||||
MCaptchaDetails,
|
||||
@@ -161,13 +159,12 @@ pub async fn get_token(
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}
|
||||
|
||||
#[post("/api/v1/mcaptcha/delete")]
|
||||
#[post("/api/v1/mcaptcha/delete", wrap = "CheckLogin")]
|
||||
pub async fn delete_mcaptcha(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
id: Identity,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
is_authenticated(&id)?;
|
||||
let username = id.identity().unwrap();
|
||||
|
||||
sqlx::query!(
|
||||
|
||||
@@ -20,8 +20,6 @@ pub mod levels;
|
||||
pub mod mcaptcha;
|
||||
pub mod stats;
|
||||
|
||||
pub use super::auth::is_authenticated;
|
||||
|
||||
pub fn get_random(len: usize) -> String {
|
||||
use std::iter;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user