#
mcaptcha/api/v1/mcaptcha/
get.rs

    1// Copyright (C) 2022  Aravinth Manivannan <realaravinth@batsense.net>
    2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
    3//
    4// SPDX-License-Identifier: AGPL-3.0-or-later
    5
    6use actix_identity::Identity;
    7use actix_web::{web, HttpResponse, Responder};
    8
    9use serde::{Deserialize, Serialize};
    10
    11use super::create::MCaptchaDetails;
    12use crate::errors::*;
    13use crate::AppData;
    14
    15#[my_codegen::post(
    16    path = "crate::V1_API_ROUTES.captcha.get",
    17    wrap = "crate::api::v1::get_middleware()"
    18)]
    19pub async fn get_captcha(
    20    payload: web::Json<MCaptchaDetails>,
    21    data: AppData,
    22    id: Identity,
    23) -> ServiceResult<impl Responder> {
    24    let username = id.identity().unwrap();
    25    let levels = data
    26        .db
    27        .get_captcha_levels(Some(&username), &payload.key)
    28        .await?;
    29    Ok(HttpResponse::Ok().json(levels))
    30}
    31
    32#[derive(Clone, Debug, Deserialize, Serialize)]
    33pub struct Levels {
    34    levels: I32Levels,
    35}
    36
    37#[derive(Clone, Debug, Deserialize, Serialize)]
    38pub struct I32Levels {
    39    pub difficulty_factor: i32,
    40    pub visitor_threshold: i32,
    41}