-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to add most server logic (not routes) for auth
- Loading branch information
1 parent
d9514aa
commit 1d1f38e
Showing
6 changed files
with
113 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use lazy_static::lazy_static; | ||
use std::error::Error; | ||
use sea_orm::*; | ||
use crate::user::model::{Model, Entity as ModelEntity, Column as ModelColumn}; | ||
|
||
pub struct DatabaseConnectix { | ||
connection: DatabaseConnection | ||
} | ||
|
||
impl Default for DatabaseConnectix { | ||
pub async fn default() -> Self { | ||
let uri = std::env::var("DB_URL").unwrap(); | ||
let db: DatabaseConnection = Database::connect(uri).await?; | ||
|
||
return Self { | ||
connection: db | ||
}; | ||
} | ||
} | ||
|
||
impl DatabaseConnectix { | ||
pub async fn new(uri: &str) -> Self { | ||
let db: DatabaseConnection = Database::connect(uri).await?; | ||
|
||
return Self { | ||
connection: db | ||
}; | ||
} | ||
|
||
/// Gets a possible user id (if one exists) for a username. | ||
pub async fn get_user_id(&self, name: &str) -> Result<i32, Box<dyn Error>> { | ||
if let Some(res) = ModelEntity::find().expr(Expr::col("id").max()).filter(ModelColumn::Name.eq(name)).one(self.connection).await? { | ||
if res.id == 9999 { return Box::new(Err("username is taken")); } | ||
Ok(res.id+1) | ||
} else { | ||
Ok(0001) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod model; | ||
pub mod model; | ||
pub mod auth; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters