Implemented settings for properties of reservation. Fixed bugs on empty database.
This commit is contained in:
+7
-1
@@ -9,6 +9,7 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
||||
use actix_session::*;
|
||||
use leptos_actix::{extract, redirect};
|
||||
use log::{info, warn};
|
||||
use crate::error::AppError;
|
||||
|
||||
pub async fn has_admin_user(pool: &PgPool) -> Result<bool, Error> {
|
||||
let count: (i64,) = query_as(r#"SELECT COUNT(id) FROM "user" WHERE admin = $1"#)
|
||||
@@ -19,7 +20,7 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
||||
Ok(count.0 > 0)
|
||||
}
|
||||
|
||||
pub async fn create_admin(pool: &PgPool) -> Result<(), Error> {
|
||||
pub async fn create_admin(pool: &PgPool) -> Result<(), AppError> {
|
||||
if !has_admin_user(pool).await? {
|
||||
let pwd = pwhash::bcrypt::hash("admin");
|
||||
query(r#"INSERT INTO "user"(login, password, full_name, admin) VALUES($1, $2, $3, $4)"#)
|
||||
@@ -44,6 +45,11 @@ cfg_if! { if #[cfg(feature = "ssr")] {
|
||||
extract(|session: Session| async move {
|
||||
session.get::<User>("user").unwrap_or(None)
|
||||
}).await.unwrap_or(None)
|
||||
/*let mut usr = User::default();
|
||||
usr.full_name = Some("PokAdm".to_string());
|
||||
usr.admin = true;
|
||||
|
||||
Some(usr)*/
|
||||
}
|
||||
|
||||
pub async fn is_logged_in() -> bool {
|
||||
|
||||
Reference in New Issue
Block a user