Translation support + french.
This commit is contained in:
parent
e9873c1943
commit
f059d3c61f
16 changed files with 380 additions and 169 deletions
|
|
@ -1,13 +1,15 @@
|
|||
use axum::{
|
||||
debug_handler,
|
||||
extract::{Extension, Query, State},
|
||||
http::StatusCode,
|
||||
http::{HeaderMap, StatusCode},
|
||||
response::{ErrorResponse, IntoResponse, Result},
|
||||
};
|
||||
use axum_extra::extract::cookie::{Cookie, CookieJar};
|
||||
use serde::Deserialize;
|
||||
// use tracing::{event, Level};
|
||||
|
||||
use crate::{
|
||||
consts,
|
||||
data::db,
|
||||
model,
|
||||
ron_extractor::ExtractRon,
|
||||
|
|
@ -22,29 +24,46 @@ pub struct RecipeId {
|
|||
id: i64,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
// #[allow(dead_code)]
|
||||
// #[debug_handler]
|
||||
// pub async fn update_user(
|
||||
// State(connection): State<db::Connection>,
|
||||
// Extension(user): Extension<Option<model::User>>,
|
||||
// ExtractRon(ron): ExtractRon<common::ron_api::UpdateProfile>,
|
||||
// ) -> Result<StatusCode> {
|
||||
// if let Some(user) = user {
|
||||
// connection
|
||||
// .update_user(
|
||||
// user.id,
|
||||
// ron.email.as_deref().map(str::trim),
|
||||
// ron.name.as_deref(),
|
||||
// ron.password.as_deref(),
|
||||
// )
|
||||
// .await?;
|
||||
// } else {
|
||||
// return Err(ErrorResponse::from(ron_error(
|
||||
// StatusCode::UNAUTHORIZED,
|
||||
// NOT_AUTHORIZED_MESSAGE,
|
||||
// )));
|
||||
// }
|
||||
// Ok(StatusCode::OK)
|
||||
// }
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn update_user(
|
||||
pub async fn set_lang(
|
||||
State(connection): State<db::Connection>,
|
||||
Extension(user): Extension<Option<model::User>>,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::UpdateProfile>,
|
||||
) -> Result<StatusCode> {
|
||||
headers: HeaderMap,
|
||||
ExtractRon(ron): ExtractRon<common::ron_api::SetLang>,
|
||||
) -> Result<(CookieJar, StatusCode)> {
|
||||
let mut jar = CookieJar::from_headers(&headers);
|
||||
if let Some(user) = user {
|
||||
connection
|
||||
.update_user(
|
||||
user.id,
|
||||
ron.email.as_deref().map(str::trim),
|
||||
ron.name.as_deref(),
|
||||
ron.password.as_deref(),
|
||||
)
|
||||
.await?;
|
||||
connection.set_user_lang(user.id, &ron.lang).await?;
|
||||
} else {
|
||||
return Err(ErrorResponse::from(ron_error(
|
||||
StatusCode::UNAUTHORIZED,
|
||||
NOT_AUTHORIZED_MESSAGE,
|
||||
)));
|
||||
let cookie = Cookie::build((consts::COOKIE_LANG_NAME, ron.lang)).path("/");
|
||||
jar = jar.add(cookie);
|
||||
}
|
||||
Ok(StatusCode::OK)
|
||||
Ok((jar, StatusCode::OK))
|
||||
}
|
||||
|
||||
async fn check_user_rights_recipe(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue