even more strings externalized
This commit is contained in:
parent
cb6f8a258a
commit
eceabda0c3
@ -6,7 +6,13 @@ logout: "Ausloggen"
|
|||||||
save: "Speichern"
|
save: "Speichern"
|
||||||
change_that_below: "Das kannst du hier ändern ⤵️"
|
change_that_below: "Das kannst du hier ändern ⤵️"
|
||||||
add: "Hinzufügen"
|
add: "Hinzufügen"
|
||||||
|
login: "Login"
|
||||||
|
name: "Name"
|
||||||
|
pw: "Passwort"
|
||||||
|
do_login: "Einloggen"
|
||||||
|
invalid_credentials: "Falscher Benutzername/Passwort"
|
||||||
|
login_succ: "Erfolgreich eingeloggt als %{name}"
|
||||||
|
user_id_nonexisting: "User mit ID %{id} gibts ned"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -47,6 +53,8 @@ station_move_up: "%{name} nach vor reihen" # should be short -> tooltip
|
|||||||
team: "Team"
|
team: "Team"
|
||||||
teams: "Teams"
|
teams: "Teams"
|
||||||
go_to_teams: "Zu den Teams"
|
go_to_teams: "Zu den Teams"
|
||||||
|
not_yet_started: "nocht nicht gestartet"
|
||||||
|
not_yet_done: "nocht nicht fertig"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -71,6 +79,11 @@ highscore: "Highscore"
|
|||||||
# # # ##### # # # # #
|
# # # ##### # # # # #
|
||||||
#
|
#
|
||||||
admins: "Admins"
|
admins: "Admins"
|
||||||
|
cant_update_pw_if_already_existing: "Kann kein neues Passwort setzen, weil es bereits eins gibt..."
|
||||||
|
cant_update_pw_if_already_existing_for_user: "Kann kein neues Passwort für %{user} setzen, weil es bereits eins gibt..."
|
||||||
|
cant_update_pw_with_wrong_code: "Falscher Code zum Setzen eines neuen Passworts für %{user}"
|
||||||
|
new_pw_for_user: "Neues Passwort für %{user} setzen"
|
||||||
|
pw_set: "Passwort erfolgreich gesetzt"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -78,7 +78,7 @@ impl User {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Err("User hat schon ein Passwort...".into())
|
Err(t!("cant_update_pw_if_already_existing").into())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete(&self, db: &SqlitePool) -> Result<(), String> {
|
async fn delete(&self, db: &SqlitePool) -> Result<(), String> {
|
||||||
|
14
src/auth.rs
14
src/auth.rs
@ -1,4 +1,4 @@
|
|||||||
use crate::{err, page, succ, AppState};
|
use crate::{er, err, page, succ, AppState};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use axum::{
|
use axum::{
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
@ -105,17 +105,17 @@ pub fn routes() -> Router<AppState> {
|
|||||||
|
|
||||||
async fn login(session: Session) -> Markup {
|
async fn login(session: Session) -> Markup {
|
||||||
let content = html! {
|
let content = html! {
|
||||||
h1 { "Login" }
|
h1 { (t!("login")) }
|
||||||
form action="/auth/login" method="post" {
|
form action="/auth/login" method="post" {
|
||||||
label {
|
label {
|
||||||
"Name"
|
(t!("name"))
|
||||||
input type="text" name="name";
|
input type="text" name="name";
|
||||||
}
|
}
|
||||||
label {
|
label {
|
||||||
"Passwort"
|
(t!("pw"))
|
||||||
input type="password" name="password";
|
input type="password" name="password";
|
||||||
}
|
}
|
||||||
input type="submit" value="Einloggen";
|
input type="submit" value=(t!("do_login"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ pub async fn login_post(
|
|||||||
let user = match auth_session.authenticate(creds.clone()).await {
|
let user = match auth_session.authenticate(creds.clone()).await {
|
||||||
Ok(Some(user)) => user,
|
Ok(Some(user)) => user,
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
err!(session, "Invalid credentials");
|
er!(session, t!("invalid_credentials"));
|
||||||
|
|
||||||
return Redirect::to("/auth/login").into_response();
|
return Redirect::to("/auth/login").into_response();
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ pub async fn login_post(
|
|||||||
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
|
return StatusCode::INTERNAL_SERVER_ERROR.into_response();
|
||||||
}
|
}
|
||||||
|
|
||||||
succ!(session, "Successfully logged in as {}", user.name);
|
suc!(session, t!("login_succ", name = user.name));
|
||||||
|
|
||||||
Redirect::to("/admin").into_response()
|
Redirect::to("/admin").into_response()
|
||||||
}
|
}
|
||||||
|
40
src/lib.rs
40
src/lib.rs
@ -180,41 +180,40 @@ async fn set_pw(
|
|||||||
axum::extract::Path((id, code)): axum::extract::Path<(i64, String)>,
|
axum::extract::Path((id, code)): axum::extract::Path<(i64, String)>,
|
||||||
) -> Result<Markup, impl IntoResponse> {
|
) -> Result<Markup, impl IntoResponse> {
|
||||||
let Some(user) = User::find_by_id(&db, id).await else {
|
let Some(user) = User::find_by_id(&db, id).await else {
|
||||||
err!(session, "User mit ID {id} gibt's ned");
|
er!(session, t!("user_id_nonexisting", id = id));
|
||||||
return Err(Redirect::to("/"));
|
return Err(Redirect::to("/"));
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(correct_code) = user.require_new_password_code else {
|
let Some(correct_code) = user.require_new_password_code else {
|
||||||
err!(
|
er!(
|
||||||
session,
|
session,
|
||||||
"User {} hat bereits ein Passwort. Du kannst kein neues setzen.",
|
t!(
|
||||||
user.name
|
"cant_update_pw_if_already_existing_for_user",
|
||||||
|
user = user.name
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return Err(Redirect::to("/"));
|
return Err(Redirect::to("/"));
|
||||||
};
|
};
|
||||||
|
|
||||||
if correct_code != code {
|
if correct_code != code {
|
||||||
err!(
|
er!(
|
||||||
session,
|
session,
|
||||||
"Falscher Code zum Passwort setzen für User {}.",
|
t!("cant_updaet_pw_with_wrong_code", user = user.name)
|
||||||
user.name
|
|
||||||
);
|
);
|
||||||
return Err(Redirect::to("/"));
|
return Err(Redirect::to("/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let content = html! {
|
let content = html! {
|
||||||
h1 {
|
h1 {
|
||||||
"Neues Passwort für "
|
(t!("new_pw_for_user", user=user.name))
|
||||||
(user.name)
|
|
||||||
" setzen"
|
|
||||||
}
|
}
|
||||||
form action=(format!("/user/{}/set-pw", user.id)) method="post" {
|
form action=(format!("/user/{}/set-pw", user.id)) method="post" {
|
||||||
input type="hidden" name="code" value=(code);
|
input type="hidden" name="code" value=(code);
|
||||||
label {
|
label {
|
||||||
"Passwort"
|
(t!("pw"))
|
||||||
input type="password" name="password";
|
input type="password" name="password";
|
||||||
}
|
}
|
||||||
input type="submit" value="Einloggen";
|
input type="submit" value=(t!("do_login"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -233,24 +232,25 @@ async fn set_concrete_pw(
|
|||||||
Form(form): Form<NewPwForm>,
|
Form(form): Form<NewPwForm>,
|
||||||
) -> impl IntoResponse {
|
) -> impl IntoResponse {
|
||||||
let Some(user) = User::find_by_id(&db, id).await else {
|
let Some(user) = User::find_by_id(&db, id).await else {
|
||||||
err!(session, "User mit ID {id} gibt's ned");
|
er!(session, t!("user_id_nonexisting", id = id));
|
||||||
return Redirect::to("/").into_response();
|
return Redirect::to("/").into_response();
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(correct_code) = &user.require_new_password_code else {
|
let Some(correct_code) = &user.require_new_password_code else {
|
||||||
err!(
|
er!(
|
||||||
session,
|
session,
|
||||||
"User {} hat bereits ein Passwort. Du kannst kein neues setzen.",
|
t!(
|
||||||
user.name
|
"cant_update_pw_if_already_existing_for_user",
|
||||||
|
user = user.name
|
||||||
|
)
|
||||||
);
|
);
|
||||||
return Redirect::to("/").into_response();
|
return Redirect::to("/").into_response();
|
||||||
};
|
};
|
||||||
|
|
||||||
if correct_code != &form.code {
|
if correct_code != &form.code {
|
||||||
err!(
|
er!(
|
||||||
session,
|
session,
|
||||||
"Falscher Code zum Passwort setzen für User {}.",
|
t!("cant_update_pw_with_wrong_code", user = user.name)
|
||||||
user.name
|
|
||||||
);
|
);
|
||||||
return Redirect::to("/").into_response();
|
return Redirect::to("/").into_response();
|
||||||
}
|
}
|
||||||
@ -259,7 +259,7 @@ async fn set_concrete_pw(
|
|||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
let user = User::find_by_id(&db, id).await.unwrap();
|
let user = User::find_by_id(&db, id).await.unwrap();
|
||||||
auth_session.login(&user).await.unwrap();
|
auth_session.login(&user).await.unwrap();
|
||||||
succ!(session, "Passwort erfolgreich gesetzt");
|
suc!(session, t!("pw_set"));
|
||||||
Redirect::to("/admin").into_response()
|
Redirect::to("/admin").into_response()
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
@ -111,7 +111,7 @@ impl Rating {
|
|||||||
}
|
}
|
||||||
pub(crate) fn local_time_doing(&self) -> String {
|
pub(crate) fn local_time_doing(&self) -> String {
|
||||||
let Some(started_at) = self.started_at else {
|
let Some(started_at) = self.started_at else {
|
||||||
return String::from("noch nicht gestartet");
|
return t!("not_yet_started").into();
|
||||||
};
|
};
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(started_at, Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(started_at, Utc);
|
||||||
let datetime_local = datetime_utc.with_timezone(&Local);
|
let datetime_local = datetime_utc.with_timezone(&Local);
|
||||||
@ -121,7 +121,7 @@ impl Rating {
|
|||||||
|
|
||||||
pub(crate) fn local_time_left(&self) -> String {
|
pub(crate) fn local_time_left(&self) -> String {
|
||||||
let Some(left_at) = self.left_at else {
|
let Some(left_at) = self.left_at else {
|
||||||
return String::from("noch nicht fertig");
|
return t!("not_yet_done").into();
|
||||||
};
|
};
|
||||||
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(left_at, Utc);
|
let datetime_utc = DateTime::<Utc>::from_naive_utc_and_offset(left_at, Utc);
|
||||||
let datetime_local = datetime_utc.with_timezone(&Local);
|
let datetime_local = datetime_utc.with_timezone(&Local);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user