From ae57359353cf31ff374a8932999742920878bf00 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Wed, 12 Oct 2022 22:52:15 +0200 Subject: upgrade to diesel 2.0 --- planetwars-server/src/db/users.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'planetwars-server/src/db/users.rs') diff --git a/planetwars-server/src/db/users.rs b/planetwars-server/src/db/users.rs index 9676dae..60cc20a 100644 --- a/planetwars-server/src/db/users.rs +++ b/planetwars-server/src/db/users.rs @@ -11,7 +11,7 @@ pub struct Credentials<'a> { } #[derive(Insertable)] -#[table_name = "users"] +#[diesel(table_name = users)] pub struct NewUser<'a> { pub username: &'a str, pub password_hash: &'a [u8], @@ -50,7 +50,7 @@ pub fn hash_password(password: &str) -> (Vec, [u8; 32]) { (hash, salt) } -pub fn create_user(credentials: &Credentials, conn: &PgConnection) -> QueryResult { +pub fn create_user(credentials: &Credentials, conn: &mut PgConnection) -> QueryResult { let (hash, salt) = hash_password(&credentials.password); let new_user = NewUser { @@ -63,19 +63,19 @@ pub fn create_user(credentials: &Credentials, conn: &PgConnection) -> QueryResul .get_result::(conn) } -pub fn find_user(user_id: i32, db_conn: &PgConnection) -> QueryResult { +pub fn find_user(user_id: i32, db_conn: &mut PgConnection) -> QueryResult { users::table .filter(users::id.eq(user_id)) .first::(db_conn) } -pub fn find_user_by_name(username: &str, db_conn: &PgConnection) -> QueryResult { +pub fn find_user_by_name(username: &str, db_conn: &mut PgConnection) -> QueryResult { users::table .filter(users::username.eq(username)) .first::(db_conn) } -pub fn set_user_password(credentials: Credentials, db_conn: &PgConnection) -> QueryResult<()> { +pub fn set_user_password(credentials: Credentials, db_conn: &mut PgConnection) -> QueryResult<()> { let (hash, salt) = hash_password(&credentials.password); let n_changes = diesel::update(users::table.filter(users::username.eq(&credentials.username))) @@ -91,7 +91,7 @@ pub fn set_user_password(credentials: Credentials, db_conn: &PgConnection) -> Qu } } -pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> Option { +pub fn authenticate_user(credentials: &Credentials, db_conn: &mut PgConnection) -> Option { find_user_by_name(credentials.username, db_conn) .optional() .unwrap() -- cgit v1.2.3