Fix more clippy issues, implement forgot password
All checks were successful
Build Crate / build (push) Successful in 1m48s
All checks were successful
Build Crate / build (push) Successful in 1m48s
This commit is contained in:
@@ -1,12 +1,33 @@
|
||||
use crate::{models::auth::ForgotPasswordRequest, server::server_state::ServerState};
|
||||
use crate::{
|
||||
entity::{prelude::*, user},
|
||||
models::{auth::ForgotPasswordRequest, generic::GenericResponse},
|
||||
server::server_state::ServerState,
|
||||
};
|
||||
use axum::{
|
||||
extract::{Json, State},
|
||||
http::StatusCode,
|
||||
};
|
||||
use sea_orm::{ColumnTrait, EntityTrait, IntoActiveModel, QueryFilter, Set};
|
||||
|
||||
pub async fn post_forgot_password(
|
||||
State(state): State<ServerState>,
|
||||
Json(password_request): Json<ForgotPasswordRequest>,
|
||||
) -> StatusCode {
|
||||
StatusCode::OK
|
||||
) -> (StatusCode, Json<GenericResponse>) {
|
||||
// Get user
|
||||
let existing_user: Option<user::Model> = User::find()
|
||||
.filter(user::Column::Username.eq(password_request.username))
|
||||
.one(&state.db_conn)
|
||||
.await
|
||||
.unwrap();
|
||||
match existing_user {
|
||||
Some(user) => {
|
||||
let mut user = user.into_active_model();
|
||||
user.forgot_password_request = Set(Some(password_request.contact_info));
|
||||
(StatusCode::OK, Json(GenericResponse::ok()))
|
||||
}
|
||||
None => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(GenericResponse::err("Username doesn't exist")),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ pub async fn post_login_user(
|
||||
}
|
||||
|
||||
pub async fn post_test_login(
|
||||
State(state): State<ServerState>,
|
||||
State(_): State<ServerState>,
|
||||
header_map: HeaderMap,
|
||||
) -> Result<Json<String>, StatusCode> {
|
||||
if let Some(auth_header) = header_map.get("Authorization") {
|
||||
|
||||
@@ -71,11 +71,16 @@ pub async fn post_register_user(
|
||||
forgot_password_request: Set(None),
|
||||
..Default::default()
|
||||
};
|
||||
// TODO -> error handling
|
||||
let db_resp = user::Entity::insert(new_user)
|
||||
.exec(&state.db_conn)
|
||||
.await
|
||||
.unwrap();
|
||||
let db_resp = user::Entity::insert(new_user).exec(&state.db_conn).await;
|
||||
match db_resp {
|
||||
Ok(_) => {}
|
||||
Err(err) => {
|
||||
return (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(GenericResponse::err(err.to_string().as_str())),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (StatusCode::OK, Json(GenericResponse::ok()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user