Begining of a RON API to edit profile

This commit is contained in:
Greg Burri 2024-11-14 01:59:40 +01:00
parent 37f6de7a89
commit 405aa68526
11 changed files with 229 additions and 68 deletions

View file

@ -4,7 +4,7 @@ use askama::Template;
use axum::{
body::Body,
debug_handler,
extract::{connect_info, ConnectInfo, Extension, Host, Path, Query, Request, State},
extract::{ConnectInfo, Extension, Host, Path, Query, Request, State},
http::{HeaderMap, StatusCode},
response::{IntoResponse, Redirect, Response, Result},
Form,
@ -14,14 +14,9 @@ use chrono::Duration;
use serde::Deserialize;
use tracing::{event, Level};
use crate::{
config::Config,
consts::{self, VALIDATION_PASSWORD_RESET_TOKEN_DURATION},
data::db,
email, model, utils, AppState,
};
use crate::{config::Config, consts, data::db, email, model, utils, AppState};
pub mod webapi;
pub mod ron_api;
impl axum::response::IntoResponse for db::DBError {
fn into_response(self) -> Response {
@ -623,8 +618,6 @@ pub async fn ask_reset_password_post(
struct ResetPasswordTemplate {
user: Option<model::User>,
reset_token: String,
password_1: String,
password_2: String,
message: String,
message_password: String,
}
@ -638,8 +631,6 @@ pub async fn reset_password_get(
Ok(ResetPasswordTemplate {
user,
reset_token: reset_token.to_string(),
password_1: String::new(),
password_2: String::new(),
message: String::new(),
message_password: String::new(),
}
@ -681,8 +672,6 @@ pub async fn reset_password_post(
Ok(ResetPasswordTemplate {
user,
reset_token: form_data.reset_token.clone(),
password_1: String::new(),
password_2: String::new(),
message_password: match error {
ResetPasswordError::PasswordsNotEqual => "Passwords don't match",
ResetPasswordError::InvalidPassword => {
@ -731,6 +720,16 @@ pub async fn reset_password_post(
}
}
///// EDIT PROFILE /////
#[debug_handler]
pub async fn edit_user(
State(connection): State<db::Connection>,
Extension(user): Extension<Option<model::User>>,
) -> Result<impl IntoResponse> {
Ok("todo")
}
///// 404 /////
#[debug_handler]
pub async fn not_found() -> Result<impl IntoResponse> {