Login endpoint bug fix (#24)
All checks were successful
Release Tagging / release (push) Successful in 46s
Rust Build / Check (push) Successful in 57s
Rust Build / Test Suite (push) Successful in 1m0s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 50s
Rust Build / build (push) Successful in 1m20s
Rust Build / Check (pull_request) Successful in 50s
Rust Build / Test Suite (pull_request) Successful in 1m7s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 1m7s
Rust Build / build (pull_request) Successful in 1m31s
All checks were successful
Release Tagging / release (push) Successful in 46s
Rust Build / Check (push) Successful in 57s
Rust Build / Test Suite (push) Successful in 1m0s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 50s
Rust Build / build (push) Successful in 1m20s
Rust Build / Check (pull_request) Successful in 50s
Rust Build / Test Suite (pull_request) Successful in 1m7s
Rust Build / Rustfmt (pull_request) Successful in 29s
Rust Build / Clippy (pull_request) Successful in 1m7s
Rust Build / build (pull_request) Successful in 1m31s
Reviewed-on: #24 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
@@ -45,45 +45,30 @@ pub mod endpoint {
|
||||
// Check if user exists
|
||||
match repo::user::get(&pool, &payload.username).await {
|
||||
Ok(user) => {
|
||||
let salt = repo::salt::get(&pool, &user.salt_id).await.unwrap();
|
||||
let salt_str = hashing::get_salt(&salt.salt).unwrap();
|
||||
let unhashed_password = payload.password;
|
||||
if hashing::verify_password(&payload.password, user.password.clone()).unwrap() {
|
||||
// Create token
|
||||
let key = token_stuff::get_key().unwrap();
|
||||
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
||||
|
||||
// Check if password is correct
|
||||
match hashing::hash_password(&unhashed_password, &salt_str) {
|
||||
Ok(hash_password) => {
|
||||
if hashing::verify_password(&unhashed_password, hash_password.clone())
|
||||
.unwrap()
|
||||
{
|
||||
// Create token
|
||||
let key = token_stuff::get_key().unwrap();
|
||||
let (token_literal, duration) =
|
||||
token_stuff::create_token(&key).unwrap();
|
||||
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(response::Response {
|
||||
message: String::from("Successful"),
|
||||
data: vec![icarus_models::login_result::LoginResult {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
token: token_literal,
|
||||
token_type: String::from(token_stuff::TOKENTYPE),
|
||||
expiration: duration,
|
||||
}],
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
return not_found("Could not verify password").await;
|
||||
}
|
||||
} else {
|
||||
return not_found("Error Hashing").await;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return not_found(&err.to_string()).await;
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(response::Response {
|
||||
message: String::from("Successful"),
|
||||
data: vec![icarus_models::login_result::LoginResult {
|
||||
id: user.id,
|
||||
username: user.username,
|
||||
token: token_literal,
|
||||
token_type: String::from(token_stuff::TOKENTYPE),
|
||||
expiration: duration,
|
||||
}],
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
return not_found("Could not verify password").await;
|
||||
}
|
||||
} else {
|
||||
return not_found("Error Hashing").await;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
|
Reference in New Issue
Block a user