Explorar o código

Remove time from user creation

Lee Morgan hai 1 mes
pai
achega
754e258d5e
Modificáronse 2 ficheiros con 4 adicións e 22 borrados
  1. 0 5
      docs/paths/user/create.yaml
  2. 4 17
      src/controllers/user/create.rs

+ 0 - 5
docs/paths/user/create.yaml

@@ -36,11 +36,6 @@ requestBody:
             format: url
             description: User validation. Create hidden input, empty by default. Fails if it is anything other than an empty string.
             example: ""
-          time:
-            type: string
-            format: date
-            description: User validation. Create hidden input and autofill a date on page load. Server checks time from page load.
-            example: 2026-05-24T15:33:03.365Z
 
 responses:
   "200":

+ 4 - 17
src/controllers/user/create.rs

@@ -3,7 +3,6 @@ use serde::Deserialize;
 use serde_json::json;
 use validator::Validate;
 use sqlx::PgPool;
-use chrono::{DateTime, Utc, Duration};
 use crate::{
     http_error::HttpError,
     logic::{valid_password, hash_password},
@@ -17,8 +16,7 @@ struct Body {
     email: String,
     password: String,
     confirm_password: String,
-    url: Option<String>,
-    time: Option<String>
+    url: Option<String>
 }
 
 #[post("/user")]
@@ -26,7 +24,7 @@ pub async fn route(
     db: web::Data<PgPool>,
     web::Json(body): web::Json<Body>
 ) -> Result<HttpResponse, HttpError> {
-    if is_bot(&body.url, &body.time) {
+    if is_bot(&body.url) {
         return Ok(HttpResponse::Ok().json(json!({"success": true})));
     }
     valid_password(&body.password, &body.confirm_password)?;
@@ -36,7 +34,7 @@ pub async fn route(
     Ok(HttpResponse::Ok().json(json!({"success": true})))
 }
 
-fn is_bot(url: &Option<String>, time: &Option<String>) -> bool {
+fn is_bot(url: &Option<String>) -> bool {
     match url {
         Some(u) => {
             if u != "" {return true}
@@ -44,16 +42,5 @@ fn is_bot(url: &Option<String>, time: &Option<String>) -> bool {
         None => {return true}
     }
 
-    let body_time = match time {
-        Some(t) => match t.parse::<DateTime<Utc>>() {
-            Ok(u) => u,
-            Err(_) => {return true}
-        }
-        None => {return true}
-    };
-
-    let now = Utc::now();
-    let age = now.signed_duration_since(body_time);
-
-    age > Duration::minutes(10)
+    false
 }