summaryrefslogtreecommitdiff
path: root/server/src/models/user.rs
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2022-08-23 18:10:18 +0200
committerSanto Cariotti <santo@dcariotti.me>2022-08-23 18:10:18 +0200
commiteedc536c23c3230c6ebeac8b495b2cfef0317830 (patch)
tree198007257cfa195c410c28b0a576f46fb8870ab9 /server/src/models/user.rs
parent0dace9fb82953cc91e6d603c4c9970631ac036ad (diff)
Auth login
Diffstat (limited to 'server/src/models/user.rs')
-rw-r--r--server/src/models/user.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/server/src/models/user.rs b/server/src/models/user.rs
index 964f04a..38ec121 100644
--- a/server/src/models/user.rs
+++ b/server/src/models/user.rs
@@ -16,7 +16,7 @@ pub struct User {
#[derive(Deserialize, Serialize)]
pub struct UserList {
- id: i32,
+ pub id: i32,
email: String,
is_staff: Option<bool>,
}
@@ -61,6 +61,26 @@ impl User {
Ok(rec)
}
+ pub async fn find(user: User) -> Result<UserList, AppError> {
+ let pool = unsafe { get_client() };
+
+ let crypted_password = sha256::digest(user.password);
+
+ let rec = sqlx::query_as!(
+ UserList,
+ r#"
+ SELECT id, email, is_staff FROM "users"
+ WHERE email = $1 AND password = $2
+ "#,
+ user.email,
+ crypted_password
+ )
+ .fetch_one(pool)
+ .await?;
+
+ Ok(rec)
+ }
+
pub async fn list() -> Result<Vec<UserList>, AppError> {
let pool = unsafe { get_client() };
let rows = sqlx::query_as!(UserList, r#"SELECT id, email, is_staff FROM users"#)