Improved error messages. Added README.md
This commit is contained in:
+1
-1
@@ -68,7 +68,7 @@ fn app_footer() -> impl IntoView {
|
||||
|
||||
view! {
|
||||
<footer class="content-footer footer bg-footer-theme" style={move || if loc.pathname.get().starts_with("/admin") {"display: none;"} else {"display: block;"}}>
|
||||
<div class="mb-2 mb-md-0" >
|
||||
<div class="mb-2 mb-md-0" align="center">
|
||||
<a href="https://rezervovator.cz" target="_blank"><img src="/rezervovator_l.svg" width="110"/></a> {format!(" v {}", env!("CARGO_PKG_VERSION"))}
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
+27
-18
@@ -105,9 +105,10 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
||||
pub async fn login(username: String, password: String) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use actix_session::*;
|
||||
use leptos_actix::extract;
|
||||
use actix_web::http::StatusCode;
|
||||
use leptos_actix::ResponseOptions;
|
||||
//use actix_web::http::StatusCode;
|
||||
//use leptos_actix::ResponseOptions;
|
||||
use crate::backend::get_pool;
|
||||
use crate::locales::trl;
|
||||
|
||||
let pool = get_pool().await?;
|
||||
let user = user_from_login(&pool, &username).await.unwrap_or(User::default());
|
||||
@@ -123,10 +124,10 @@ pub async fn login(username: String, password: String) -> Result<ApiResponse<()>
|
||||
}
|
||||
|
||||
warn!("Login failed for user {}", username);
|
||||
let response = expect_context::<ResponseOptions>();
|
||||
response.set_status(StatusCode::UNAUTHORIZED);
|
||||
//let response = expect_context::<ResponseOptions>();
|
||||
//response.set_status(StatusCode::UNAUTHORIZED);
|
||||
|
||||
return Ok(ApiResponse::Error("Bad username or password".to_string()))
|
||||
Ok(ApiResponse::Error(trl("Bad username or password")()))
|
||||
}
|
||||
|
||||
#[server]
|
||||
@@ -173,15 +174,16 @@ pub async fn get_users() -> Result<ApiResponse<Vec<User>>, ServerFnError> {
|
||||
pub async fn update_profile(user: UserProfile) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::user_check;
|
||||
use crate::backend::get_pool;
|
||||
use crate::locales::trl;
|
||||
|
||||
user_check!(user.login());
|
||||
let usr = logged_in_user().await.unwrap_or(User::default());
|
||||
|
||||
if !usr.admin && user.admin() {
|
||||
let response = expect_context::<ResponseOptions>();
|
||||
response.set_status(StatusCode::FORBIDDEN);
|
||||
//let response = expect_context::<ResponseOptions>();
|
||||
//response.set_status(StatusCode::FORBIDDEN);
|
||||
|
||||
return Ok(ApiResponse::Error("You can't escalate your privileges".to_string()))
|
||||
return Ok(ApiResponse::Error(trl("You can't escalate your privileges")()))
|
||||
}
|
||||
|
||||
let pool = get_pool().await?;
|
||||
@@ -213,6 +215,7 @@ impl ForValidation for UpdateProfile {
|
||||
pub async fn change_pwd(new_pw: PwdChange) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::user_check;
|
||||
use crate::backend::get_pool;
|
||||
use crate::locales::trl;
|
||||
|
||||
user_check!(new_pw.login());
|
||||
|
||||
@@ -222,10 +225,10 @@ pub async fn change_pwd(new_pw: PwdChange) -> Result<ApiResponse<()>, ServerFnEr
|
||||
|
||||
if (!user.admin || user.login == new_pw.login())
|
||||
&& !pwhash::bcrypt::verify(new_pw.old_password(), &usr.password) {
|
||||
let response = expect_context::<ResponseOptions>();
|
||||
response.set_status(StatusCode::UNAUTHORIZED);
|
||||
//let response = expect_context::<ResponseOptions>();
|
||||
//response.set_status(StatusCode::UNAUTHORIZED);
|
||||
|
||||
return Ok(ApiResponse::Error("Invalid old password".to_string()))
|
||||
return Ok(ApiResponse::Error(trl("Invalid old password")()))
|
||||
}
|
||||
|
||||
sqlx::query(r#"UPDATE "user" SET password = $1 WHERE login = $2"#)
|
||||
@@ -249,6 +252,7 @@ impl ForValidation for ChangePwd {
|
||||
pub async fn create_user(user: UserProfile) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::perm_check;
|
||||
use crate::backend::get_pool;
|
||||
use crate::locales::trl;
|
||||
|
||||
perm_check!(is_admin);
|
||||
|
||||
@@ -259,10 +263,10 @@ pub async fn create_user(user: UserProfile) -> Result<ApiResponse<()>, ServerFnE
|
||||
.await?;
|
||||
|
||||
if count.0 != 0 {
|
||||
let response = expect_context::<ResponseOptions>();
|
||||
response.set_status(StatusCode::CONFLICT);
|
||||
//let response = expect_context::<ResponseOptions>();
|
||||
//response.set_status(StatusCode::CONFLICT);
|
||||
|
||||
return Ok(ApiResponse::Error("Username already exists".to_string()));
|
||||
return Ok(ApiResponse::Error(trl("Username already exists")()));
|
||||
}
|
||||
|
||||
let usr_pw = user.password().clone();
|
||||
@@ -292,15 +296,16 @@ impl ForValidation for CreateUser {
|
||||
pub async fn delete_user(id: i32) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
use crate::perm_check;
|
||||
use crate::backend::get_pool;
|
||||
use crate::locales::trl;
|
||||
|
||||
perm_check!(is_admin);
|
||||
let user = logged_in_user().await.unwrap_or_default();
|
||||
|
||||
if user.id() == id {
|
||||
let response = expect_context::<ResponseOptions>();
|
||||
response.set_status(StatusCode::NOT_ACCEPTABLE);
|
||||
//let response = expect_context::<ResponseOptions>();
|
||||
//response.set_status(StatusCode::NOT_ACCEPTABLE);
|
||||
|
||||
return Ok(ApiResponse::Error("You can't delete yourself".to_string()))
|
||||
return Ok(ApiResponse::Error(trl("You can't delete yourself")()))
|
||||
}
|
||||
|
||||
sqlx::query(r#"DELETE FROM "user" WHERE id=$1"#)
|
||||
@@ -317,5 +322,9 @@ pub async fn delete_user(id: i32) -> Result<ApiResponse<()>, ServerFnError> {
|
||||
pub async fn get_pow() -> Result<String, ServerFnError> {
|
||||
use leptos_captcha::spow::pow::Pow;
|
||||
|
||||
Ok(Pow::new(10)?.to_string())
|
||||
if !cfg!(debug_assertions) {
|
||||
Ok(Pow::with_difficulty(10, 10)?.to_string())
|
||||
} else {
|
||||
Ok(Pow::new(10)?.to_string())
|
||||
}
|
||||
}
|
||||
@@ -13,11 +13,12 @@ fn about(opener: DialogOpener) -> impl IntoView {
|
||||
<ModalBody>
|
||||
<img src="/rezervovator_l.svg" width="180"/> <br /><br/>
|
||||
<p>
|
||||
{trl("Online booking application for sports facilities and service providers.")}<br/><br/>
|
||||
{trl("Online booking application for sports facilities and service providers.")}<br/>
|
||||
{format!(" v {}", env!("CARGO_PKG_VERSION"))}<br/><br/>
|
||||
<div align="center">
|
||||
<a href="https://www.rust-lang.org" target="_blank"><img src="/rust.png" height="40"/></a>" "
|
||||
<a href="https://leptos.dev" target="_blank"><img src="/Leptos_logo.png" height="40"/></a> <br/><br/>
|
||||
"(c) 2023 - 2024"
|
||||
"(c) 2023 - 2025"
|
||||
</div>
|
||||
</p>
|
||||
</ModalBody>
|
||||
|
||||
@@ -161,7 +161,13 @@ lazy_static! {
|
||||
("Closing days: ", "Zavírací dny: "),
|
||||
("Closing days", "Zavírací dny"),
|
||||
("From", "Od"),
|
||||
("To", "do")
|
||||
("To", "do"),
|
||||
("Delete closing days", "Smazat zavírací dny"),
|
||||
("Are you sure you want to delete closing days?", "Opravdu chcete smazat zavírací dny?"),
|
||||
("Bad username or password", "Špatné uživatelské jméno nebo heslo"),
|
||||
("You can't escalate your privileges", "Nemůžete povýšit práva sami sobě"),
|
||||
("Username already exists", "Uživatel již existuje"),
|
||||
("You can't delete yourself", "Nemůžete smazat sami sebe")
|
||||
])),
|
||||
("sk", HashMap::from( [
|
||||
("Dashboard", "Prehlad"),
|
||||
|
||||
Reference in New Issue
Block a user