Extract language
This commit is contained in:
parent
daf472fd3e
commit
76090d4266
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -2341,6 +2341,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"oswilno-contract",
|
||||
"tera",
|
||||
"tracing",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
@ -2413,7 +2414,9 @@ dependencies = [
|
||||
name = "oswilno-view"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"actix-web",
|
||||
"askama",
|
||||
"futures-core",
|
||||
"garde",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -14,3 +14,4 @@ chrono = "0.4.26"
|
||||
oswilno-contract = { path = "../oswilno-contract" }
|
||||
tera = "1.17.1"
|
||||
uuid = { version = "1.4.1", features = ["v4"] }
|
||||
tracing = "0.1.37"
|
||||
|
@ -36,7 +36,7 @@ fn create_actix_admin_builder() -> ActixAdminBuilder {
|
||||
admin_builder.add_entity_to_category::<ParkingSpaceRents>(&view, "Parking spaces");
|
||||
}
|
||||
for scope in admin_builder.scopes.keys() {
|
||||
eprintln!("Scope {scope:?}");
|
||||
tracing::trace!("Scope {scope:?}");
|
||||
}
|
||||
|
||||
admin_builder
|
||||
|
@ -29,12 +29,12 @@ pub type UserSession = Authenticated<Claims>;
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct JWTTtl(time::Duration);
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
enum Audience {
|
||||
Web,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
|
||||
pub struct Claims {
|
||||
#[serde(rename = "exp")]
|
||||
expires_at: usize,
|
||||
@ -193,19 +193,14 @@ async fn login(
|
||||
db: Data<DatabaseConnection>,
|
||||
payload: Form<SignInPayload>,
|
||||
t: Data<oswilno_view::TranslationStorage>,
|
||||
lang: Lang,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let t = t.into_inner();
|
||||
match login_inner(jwt_encoding_key, jwt_ttl, db, payload).await {
|
||||
Ok(res) => Ok(HttpResponse::Ok().json(res)),
|
||||
Err(form) => Ok(HttpResponse::Ok().body(
|
||||
SignInPartialTemplate {
|
||||
form,
|
||||
lang: Lang::Pl,
|
||||
t,
|
||||
Err(form) => {
|
||||
Ok(HttpResponse::Ok().body(SignInPartialTemplate { form, lang, t }.render().unwrap()))
|
||||
}
|
||||
.render()
|
||||
.unwrap(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,6 +332,7 @@ async fn register(
|
||||
db: Data<DatabaseConnection>,
|
||||
payload: Form<AccountInfo>,
|
||||
t: Data<oswilno_view::TranslationStorage>,
|
||||
lang: Lang,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let t = t.into_inner();
|
||||
let mut errors = oswilno_view::Errors::default();
|
||||
@ -347,7 +343,7 @@ async fn register(
|
||||
RegisterPartialTemplate {
|
||||
form: p,
|
||||
t,
|
||||
lang: Lang::Pl,
|
||||
lang,
|
||||
errors,
|
||||
}
|
||||
.render()
|
||||
@ -433,6 +429,7 @@ async fn register_internal(
|
||||
email_taken,
|
||||
}) {
|
||||
errors.consume_garde(e);
|
||||
return Err(p);
|
||||
}
|
||||
tracing::warn!("{errors:#?}");
|
||||
|
||||
@ -443,7 +440,7 @@ async fn register_internal(
|
||||
return Ok(HttpResponse::InternalServerError().body(""));
|
||||
}
|
||||
};
|
||||
let model = match (ActiveModel {
|
||||
let model = (ActiveModel {
|
||||
id: NotSet,
|
||||
login: Set(p.input_login.to_string()),
|
||||
email: Set(p.email.to_string()),
|
||||
@ -452,14 +449,11 @@ async fn register_internal(
|
||||
})
|
||||
.save(&*db)
|
||||
.await
|
||||
{
|
||||
Ok(model) => model,
|
||||
Err(e) => {
|
||||
.map_err(|e| {
|
||||
tracing::warn!("{e}");
|
||||
errors.push_global("Login or email already taken");
|
||||
return Err(p);
|
||||
}
|
||||
};
|
||||
p
|
||||
})?;
|
||||
|
||||
tracing::info!("{model:?}");
|
||||
|
||||
|
@ -4,6 +4,8 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
actix-web = "4.3.1"
|
||||
askama = { version = "0.12.0", features = ["serde", "with-actix-web", "comrak", "mime"] }
|
||||
futures-core = "0.3.28"
|
||||
garde = { version = "0.14.0", features = ["derive"] }
|
||||
tracing = "0.1.37"
|
||||
|
@ -1,7 +1,10 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
pub use lang::*;
|
||||
|
||||
pub mod filters;
|
||||
pub mod lang;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct Errors {
|
||||
@ -50,12 +53,6 @@ impl From<garde::Errors> for Errors {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)]
|
||||
pub enum Lang {
|
||||
Pl,
|
||||
En,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct TranslationStorage {
|
||||
storage: Arc<RwLock<HashMap<Lang, HashMap<String, Translation>>>>,
|
||||
|
Loading…
Reference in New Issue
Block a user