aboutsummaryrefslogtreecommitdiff
path: root/planetwars-server/src/db/users.rs
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-04-09 10:04:12 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-04-09 10:04:12 +0200
commitcc7014b04bc4714cb2de7af39e62ff9762827489 (patch)
tree6c8b6de746a8551639090b745b848573a471a2b4 /planetwars-server/src/db/users.rs
parent0e3ff9201e8479935f928c05ed6b11ae1c086e00 (diff)
downloadplanetwars.dev-cc7014b04bc4714cb2de7af39e62ff9762827489.tar.xz
planetwars.dev-cc7014b04bc4714cb2de7af39e62ff9762827489.zip
add validation to user registration
Diffstat (limited to 'planetwars-server/src/db/users.rs')
-rw-r--r--planetwars-server/src/db/users.rs8
1 files changed, 6 insertions, 2 deletions
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::<User>(conn)
}
-pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> Option<User> {
+pub fn find_user(username: &str, db_conn: &PgConnection) -> QueryResult<User> {
users::table
- .filter(users::username.eq(&credentials.username))
+ .filter(users::username.eq(username))
.first::<User>(db_conn)
+}
+
+pub fn authenticate_user(credentials: &Credentials, db_conn: &PgConnection) -> Option<User> {
+ find_user(credentials.username, db_conn)
.optional()
.unwrap()
.and_then(|user| {