|
|
@@ -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
|
|
|
}
|