aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-03-13 15:20:03 +0100
committerIlion Beyst <ilion.beyst@gmail.com>2022-03-13 15:20:03 +0100
commitfd52e266c6e25999a49c36f17342977b759a2612 (patch)
tree9c727cac949c9698343d003ee87cfe73c6c6204a /planetwars-server/src/db
parentf7655005ff099e8314ecd31e95b26ad74d4efd02 (diff)
downloadplanetwars.dev-fd52e266c6e25999a49c36f17342977b759a2612.tar.xz
planetwars.dev-fd52e266c6e25999a49c36f17342977b759a2612.zip
apply clippy suggestions
Diffstat (limited to 'planetwars-server/src/db')
-rw-r--r--planetwars-server/src/db/sessions.rs9
-rw-r--r--planetwars-server/src/db/users.rs12
2 files changed, 10 insertions, 11 deletions
diff --git a/planetwars-server/src/db/sessions.rs b/planetwars-server/src/db/sessions.rs
index 96f3926..a91d954 100644
--- a/planetwars-server/src/db/sessions.rs
+++ b/planetwars-server/src/db/sessions.rs
@@ -24,12 +24,11 @@ pub fn create_session(user: &User, conn: &PgConnection) -> Session {
token: gen_session_token(),
user_id: user.id,
};
- let session = insert_into(sessions::table)
+
+ insert_into(sessions::table)
.values(&new_session)
.get_result::<Session>(conn)
- .unwrap();
-
- return session;
+ .unwrap()
}
pub fn find_user_by_session(token: &str, conn: &PgConnection) -> QueryResult<(Session, User)> {
@@ -42,5 +41,5 @@ pub fn find_user_by_session(token: &str, conn: &PgConnection) -> QueryResult<(Se
pub fn gen_session_token() -> String {
let mut rng = rand::thread_rng();
let token: [u8; 32] = rng.gen();
- return base64::encode(&token);
+ base64::encode(&token)
}
diff --git a/planetwars-server/src/db/users.rs b/planetwars-server/src/db/users.rs
index a97ade5..3c071de 100644
--- a/planetwars-server/src/db/users.rs
+++ b/planetwars-server/src/db/users.rs
@@ -48,7 +48,7 @@ pub fn create_user(credentials: &Credentials, conn: &PgConnection) -> QueryResul
let salt: [u8; 32] = rand::thread_rng().gen();
let hash = argon2::hash_raw(credentials.password.as_bytes(), &salt, &argon_config).unwrap();
let new_user = NewUser {
- username: &credentials.username,
+ username: credentials.username,
password_salt: &salt,
password_hash: &hash,
};
@@ -73,9 +73,9 @@ pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> O
.unwrap();
if password_matches {
- return Some(user);
+ Some(user)
} else {
- return None;
+ None
}
})
}
@@ -91,15 +91,15 @@ fn test_argon() {
let salt: [u8; 32] = rand::thread_rng().gen();
let hash = argon2::hash_raw(credentials.password.as_bytes(), &salt, &argon_config).unwrap();
let new_user = NewUser {
- username: &credentials.username,
+ username: credentials.username,
password_hash: &hash,
password_salt: &salt,
};
let password_matches = argon2::verify_raw(
credentials.password.as_bytes(),
- &new_user.password_salt,
- &new_user.password_hash,
+ new_user.password_salt,
+ new_user.password_hash,
&argon2_config(),
)
.unwrap();