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