From cc7014b04bc4714cb2de7af39e62ff9762827489 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 9 Apr 2022 10:04:12 +0200 Subject: add validation to user registration --- planetwars-server/src/db/users.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 3c071de..3a74c53 100644 --- a/planetwars-server/src/db/users.rs +++ b/planetwars-server/src/db/users.rs @@ -57,10 +57,14 @@ pub fn create_user(credentials: &Credentials, conn: &PgConnection) -> QueryResul .get_result::(conn) } -pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> Option { +pub fn find_user(username: &str, db_conn: &PgConnection) -> QueryResult { users::table - .filter(users::username.eq(&credentials.username)) + .filter(users::username.eq(username)) .first::(db_conn) +} + +pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> Option { + find_user(credentials.username, db_conn) .optional() .unwrap() .and_then(|user| { -- cgit v1.2.3