Fixes 3 potential panics when querying the user and pwd table.

This commit is contained in:
Dennis Brentjes 2022-04-21 21:51:57 +02:00
parent b5e9420c1f
commit aab60dcc11

View File

@ -147,18 +147,18 @@ pub async fn login(conn: DbConn, login: Login) -> Result<LoginResult, DatabaseEr
.filter(user::username.eq(&login.username))
.or_filter(user::email.eq(&login.username))
.select(user::id)
.get_results(c)
.first(c)
{
Ok(id) => id[0],
Ok(id) => id,
Err(error) => return Err(DatabaseError::Query(error.to_string())),
};
let pwd: String = match pwd::table
.filter(pwd::user_id.eq(id))
.select(pwd::password)
.get_results::<String>(c)
.first(c)
{
Ok(pwd) => pwd[0].clone(),
Ok(pwd) => pwd,
Err(error) => return Err(DatabaseError::Query(error.to_string())),
};
@ -174,9 +174,9 @@ pub async fn login(conn: DbConn, login: Login) -> Result<LoginResult, DatabaseEr
let role: Role = match user::table
.filter(user::id.eq(id))
.select(user::role)
.get_results::<Role>(c)
.first(c)
{
Ok(role) => role[0].clone(),
Ok(role) => role,
Err(error) => return Err(DatabaseError::Query(error.to_string())),
};