even more strings externalized
This commit is contained in:
parent
cb6f8a258a
commit
eceabda0c3
@ -6,7 +6,13 @@ logout: "Ausloggen"
|
||||
save: "Speichern"
|
||||
change_that_below: "Das kannst du hier ändern ⤵️"
|
||||
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"
|
||||
teams: "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"
|
||||
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();
|
||||
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> {
|
||||
|
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 axum::{
|
||||
http::StatusCode,
|
||||
@ -105,17 +105,17 @@ pub fn routes() -> Router<AppState> {
|
||||
|
||||
async fn login(session: Session) -> Markup {
|
||||
let content = html! {
|
||||
h1 { "Login" }
|
||||
h1 { (t!("login")) }
|
||||
form action="/auth/login" method="post" {
|
||||
label {
|
||||
"Name"
|
||||
(t!("name"))
|
||||
input type="text" name="name";
|
||||
}
|
||||
label {
|
||||
"Passwort"
|
||||
(t!("pw"))
|
||||
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 {
|
||||
Ok(Some(user)) => user,
|
||||
Ok(None) => {
|
||||
err!(session, "Invalid credentials");
|
||||
er!(session, t!("invalid_credentials"));
|
||||
|
||||
return Redirect::to("/auth/login").into_response();
|
||||
}
|
||||
@ -143,7 +143,7 @@ pub async fn login_post(
|
||||
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()
|
||||
}
|
||||
|
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)>,
|
||||
) -> Result<Markup, impl IntoResponse> {
|
||||
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("/"));
|
||||
};
|
||||
|
||||
let Some(correct_code) = user.require_new_password_code else {
|
||||
err!(
|
||||
er!(
|
||||
session,
|
||||
"User {} hat bereits ein Passwort. Du kannst kein neues setzen.",
|
||||
user.name
|
||||
t!(
|
||||
"cant_update_pw_if_already_existing_for_user",
|
||||
user = user.name
|
||||
)
|
||||
);
|
||||
return Err(Redirect::to("/"));
|
||||
};
|
||||
|
||||
if correct_code != code {
|
||||
err!(
|
||||
er!(
|
||||
session,
|
||||
"Falscher Code zum Passwort setzen für User {}.",
|
||||
user.name
|
||||
t!("cant_updaet_pw_with_wrong_code", user = user.name)
|
||||
);
|
||||
return Err(Redirect::to("/"));
|
||||
}
|
||||
|
||||
let content = html! {
|
||||
h1 {
|
||||
"Neues Passwort für "
|
||||
(user.name)
|
||||
" setzen"
|
||||
(t!("new_pw_for_user", user=user.name))
|
||||
}
|
||||
form action=(format!("/user/{}/set-pw", user.id)) method="post" {
|
||||
input type="hidden" name="code" value=(code);
|
||||
label {
|
||||
"Passwort"
|
||||
(t!("pw"))
|
||||
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>,
|
||||
) -> impl IntoResponse {
|
||||
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();
|
||||
};
|
||||
|
||||
let Some(correct_code) = &user.require_new_password_code else {
|
||||
err!(
|
||||
er!(
|
||||
session,
|
||||
"User {} hat bereits ein Passwort. Du kannst kein neues setzen.",
|
||||
user.name
|
||||
t!(
|
||||
"cant_update_pw_if_already_existing_for_user",
|
||||
user = user.name
|
||||
)
|
||||
);
|
||||
return Redirect::to("/").into_response();
|
||||
};
|
||||
|
||||
if correct_code != &form.code {
|
||||
err!(
|
||||
er!(
|
||||
session,
|
||||
"Falscher Code zum Passwort setzen für User {}.",
|
||||
user.name
|
||||
t!("cant_update_pw_with_wrong_code", user = user.name)
|
||||
);
|
||||
return Redirect::to("/").into_response();
|
||||
}
|
||||
@ -259,7 +259,7 @@ async fn set_concrete_pw(
|
||||
Ok(()) => {
|
||||
let user = User::find_by_id(&db, id).await.unwrap();
|
||||
auth_session.login(&user).await.unwrap();
|
||||
succ!(session, "Passwort erfolgreich gesetzt");
|
||||
suc!(session, t!("pw_set"));
|
||||
Redirect::to("/admin").into_response()
|
||||
}
|
||||
Err(e) => {
|
||||
|
@ -111,7 +111,7 @@ impl Rating {
|
||||
}
|
||||
pub(crate) fn local_time_doing(&self) -> String {
|
||||
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_local = datetime_utc.with_timezone(&Local);
|
||||
@ -121,7 +121,7 @@ impl Rating {
|
||||
|
||||
pub(crate) fn local_time_left(&self) -> String {
|
||||
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_local = datetime_utc.with_timezone(&Local);
|
||||
|
Loading…
x
Reference in New Issue
Block a user