Add initial database schema and references
Some checks are pending
Build Crate / build (push) Waiting to run
Some checks are pending
Build Crate / build (push) Waiting to run
Also look into users a bit
This commit is contained in:
@@ -1,3 +1,38 @@
|
||||
use axum_login::{AuthUser, AuthnBackend, UserId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub type PlayerId = u32;
|
||||
|
||||
// References
|
||||
// https://github.com/maxcountryman/axum-login/tree/main/examples/sqlite/src
|
||||
// https://framesurge.sh/perseus/en-US/docs/0.4.x/state/intro
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
id: u64,
|
||||
pub username: String,
|
||||
password: String,
|
||||
}
|
||||
|
||||
// Override debug to prevent logging password hash
|
||||
impl std::fmt::Debug for User {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("User")
|
||||
.field("id", &self.id)
|
||||
.field("username", &self.username)
|
||||
.field("password", &"[hidden]")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthUser for User {
|
||||
type Id = u64;
|
||||
|
||||
fn id(&self) -> Self::Id {
|
||||
self.id
|
||||
}
|
||||
|
||||
fn session_auth_hash(&self) -> &[u8] {
|
||||
self.password.as_bytes()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ cfg_if::cfg_if! {
|
||||
stores::MutableStore,
|
||||
turbine::Turbine,
|
||||
};
|
||||
use futures::executor::block_on;
|
||||
use sea_orm::{Database};
|
||||
use crate::server::routes::register_routes;
|
||||
}
|
||||
}
|
||||
@@ -35,6 +37,13 @@ pub async fn dflt_server<M: MutableStore + 'static, T: TranslationsManager + 'st
|
||||
|
||||
app = register_routes(app);
|
||||
|
||||
// TODO -> Update to use environment variable
|
||||
if let Err(err) = block_on(Database::connect(
|
||||
"postgres://elo:elo@localhost:5432/elo_app",
|
||||
)) {
|
||||
panic!("{}", err);
|
||||
}
|
||||
|
||||
axum::Server::bind(&addr)
|
||||
.serve(app.into_make_service())
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user