Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
callmeclover authored Apr 25, 2024
1 parent 66753e2 commit 8f33362
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/user/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,18 @@ impl DatabaseConnectix {

/// Gets a possible user id (if one exists) for a username.
pub fn get_user_id(&self, name: &str) -> Result<i32, Box<dyn Error>> {
if let Some(res) = Some(self.connection.query_one("select max(id) from users where name=$1", &[&name])?) {
if res.id == 9999 { return Err("username is taken".into()); }
Ok(res.id+1)
} else {
Ok(1)
match self.connection.query_one("select max(id) from users where name=$1", &[&name]) {
Ok(res) => {
if let Some(id) = res.get(0) {
if id == 9999 { return Err("username is taken".into()); }
Ok(id+1)
} else {
Ok(1)
}
},
Err(err) => {
eprintln!("{}", err);
}
}
}

Expand Down

0 comments on commit 8f33362

Please sign in to comment.