forked from Roflin/gamenight
Added Location and location ownership/rights to gamenight.
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
use argon2::password_hash::Salt;
|
||||
use diesel::Connection;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use uuid::Uuid;
|
||||
use diesel::{ExpressionMethods, QueryDsl, RunQueryDsl, Insertable, Queryable};
|
||||
use diesel_derive_enum::DbEnum;
|
||||
use argon2::password_hash::SaltString;
|
||||
use crate::DbConnection;
|
||||
use argon2::Argon2;
|
||||
use argon2::PasswordHash;
|
||||
use argon2::PasswordVerifier;
|
||||
use argon2::Argon2;
|
||||
use argon2::password_hash::PasswordHasher;
|
||||
use argon2::password_hash::Salt;
|
||||
use argon2::password_hash::SaltString;
|
||||
use argon2::password_hash::rand_core::OsRng;
|
||||
use argon2::password_hash::rand_core::RngCore;
|
||||
use crate::DbConnection;
|
||||
use diesel::Connection;
|
||||
use diesel::{ExpressionMethods, Insertable, QueryDsl, Queryable, RunQueryDsl};
|
||||
use diesel_derive_enum::DbEnum;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
use super::schema::{pwd, client};
|
||||
pub use super::error::DatabaseError;
|
||||
|
||||
|
||||
use super::schema::{client, pwd};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Insertable, Queryable)]
|
||||
#[diesel(table_name = pwd)]
|
||||
@@ -38,12 +36,12 @@ pub struct User {
|
||||
#[ExistingTypePath = "crate::schema::sql_types::Role"]
|
||||
pub enum Role {
|
||||
Admin,
|
||||
User
|
||||
User,
|
||||
}
|
||||
|
||||
pub struct LoginUser {
|
||||
pub username: String,
|
||||
pub password: String
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
@@ -61,7 +59,7 @@ pub struct RegisterResult {
|
||||
pub struct Register {
|
||||
pub username: String,
|
||||
pub email: String,
|
||||
pub password: String
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
pub fn login(conn: &mut DbConnection, user: LoginUser) -> Result<Option<User>, DatabaseError> {
|
||||
@@ -85,7 +83,7 @@ pub fn login(conn: &mut DbConnection, user: LoginUser) -> Result<Option<User>, D
|
||||
Ok(Some(client::table.find(id).first(conn)?))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_user(conn: &mut DbConnection, id: Uuid) -> Result<User, DatabaseError> {
|
||||
@@ -125,16 +123,26 @@ pub fn register(conn: &mut DbConnection, register: Register) -> Result<(), Datab
|
||||
})
|
||||
}
|
||||
|
||||
pub fn count_users_with_username(conn: &mut DbConnection, username: &String) -> Result<i64, DatabaseError> {
|
||||
pub fn count_users_with_username(
|
||||
conn: &mut DbConnection,
|
||||
username: &String,
|
||||
) -> Result<i64, DatabaseError> {
|
||||
Ok(client::table
|
||||
.count()
|
||||
.filter(client::username.eq(username))
|
||||
.get_result::<i64>(conn)?)
|
||||
}
|
||||
|
||||
pub fn count_users_with_email(conn: &mut DbConnection, email: &String) -> Result<i64, DatabaseError> {
|
||||
pub fn count_users_with_email(
|
||||
conn: &mut DbConnection,
|
||||
email: &String,
|
||||
) -> Result<i64, DatabaseError> {
|
||||
Ok(client::table
|
||||
.count()
|
||||
.filter(client::email.eq(email))
|
||||
.get_result::<i64>(conn)?)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_users(conn: &mut DbConnection) -> Result<Vec<User>, DatabaseError> {
|
||||
Ok(client::table.load(conn)?)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user