fix: inappropriate use of public mode

This commit is contained in:
minoplhy 2024-11-01 15:11:25 +07:00
parent 7ff86b3e02
commit 146bafa773
Signed by: minoplhy
GPG Key ID: 41D406044E2434BF

View File

@ -123,13 +123,9 @@ pub async fn login(req: String, session: Session) -> HttpResponse {
HttpResponse::Ok().body("Correct password!") HttpResponse::Ok().body("Correct password!")
} }
// Create API Key, Will be disabled on public mode // Create API Key
#[post("/api/key")] #[post("/api/key")]
pub async fn gen_api_key(session: Session, httprequest: HttpRequest, data: web::Data<AppState>) -> HttpResponse { pub async fn gen_api_key(session: Session, httprequest: HttpRequest, data: web::Data<AppState>) -> HttpResponse {
if env::var("public_mode") == Ok(String::from("Enable")) {
return HttpResponse::Forbidden().body("Public mode is enabled!");
}
if auth::validate(session) || apikey_validate(httprequest, data.clone()) { if auth::validate(session) || apikey_validate(httprequest, data.clone()) {
let key = utils::gen_api_key(&data.db); let key = utils::gen_api_key(&data.db);
if key.0 { if key.0 {
@ -161,7 +157,7 @@ pub async fn edit_link(
session: Session, session: Session,
httprequest: HttpRequest, httprequest: HttpRequest,
) -> HttpResponse { ) -> HttpResponse {
if env::var("public_mode") == Ok(String::from("Enable")) || auth::validate(session) || apikey_validate(httprequest, data.clone()) { if auth::validate(session) || apikey_validate(httprequest, data.clone()) {
let out = utils::edit_link(req, shortlink.to_string(), &data.db); let out = utils::edit_link(req, shortlink.to_string(), &data.db);
if out.0 { if out.0 {
HttpResponse::Created().body(out.1) HttpResponse::Created().body(out.1)