| 12345678910111213141516171819202122232425262728293031 |
- use actix_web::{HttpResponse, web, patch};
- use sqlx::PgPool;
- use uuid::Uuid;
- use serde_json::json;
- use serde::Deserialize;
- use crate::{
- app_error::AppError,
- models::user::User,
- logic::{valid_password, hash_password}
- };
- #[derive(Deserialize)]
- struct Body {
- user_id: String,
- token: String,
- password: String,
- confirm_password: String
- }
- #[patch("/user/password/reset")]
- pub async fn route(
- db: web::Data<PgPool>,
- body: web::Json<Body>
- ) -> Result<HttpResponse, AppError> {
- let user_id = Uuid::parse_str(&body.user_id)?;
- let token = Uuid::parse_str(&body.token)?;
- valid_password(&body.password, &body.confirm_password)?;
- let pass_hash = hash_password(&body.password)?;
- User::reset_password(&db, user_id, token, pass_hash).await?;
- Ok(HttpResponse::Ok().json(json!({"success": true})))
- }
|