Added a user system with no proper user validation but working authorisation. #1

Merged
Roflin merged 6 commits from user-system into main 2022-04-23 13:17:32 +02:00
Showing only changes of commit aab60dcc11 - Show all commits

View File

@ -147,18 +147,18 @@ pub async fn login(conn: DbConn, login: Login) -> Result<LoginResult, DatabaseEr
.filter(user::username.eq(&login.username)) .filter(user::username.eq(&login.username))
.or_filter(user::email.eq(&login.username)) .or_filter(user::email.eq(&login.username))
.select(user::id) .select(user::id)
.get_results(c) .first(c)
{ {
Ok(id) => id[0], Ok(id) => id,
Roflin marked this conversation as resolved Outdated

generates a panic if the user does not exist

generates a panic if the user does not exist
Err(error) => return Err(DatabaseError::Query(error.to_string())), Err(error) => return Err(DatabaseError::Query(error.to_string())),
}; };
let pwd: String = match pwd::table let pwd: String = match pwd::table
.filter(pwd::user_id.eq(id)) .filter(pwd::user_id.eq(id))
.select(pwd::password) .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())), 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 let role: Role = match user::table
.filter(user::id.eq(id)) .filter(user::id.eq(id))
.select(user::role) .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())), Err(error) => return Err(DatabaseError::Query(error.to_string())),
}; };