Simplifying code
All checks were successful
Rust Build / Check (pull_request) Successful in 46s
Rust Build / Test Suite (pull_request) Successful in 1m6s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 47s
Rust Build / build (pull_request) Successful in 1m14s
All checks were successful
Rust Build / Check (pull_request) Successful in 46s
Rust Build / Test Suite (pull_request) Successful in 1m6s
Rust Build / Rustfmt (pull_request) Successful in 32s
Rust Build / Clippy (pull_request) Successful in 47s
Rust Build / build (pull_request) Successful in 1m14s
This commit is contained in:
@@ -49,53 +49,52 @@ pub mod endpoint {
|
||||
};
|
||||
|
||||
// Check if user exists
|
||||
match repo::user::exists(&pool, &usr.username).await {
|
||||
Ok(exists) => {
|
||||
if !exists {
|
||||
return not_found("Not Found").await;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return not_found(&err.to_string()).await;
|
||||
}
|
||||
};
|
||||
// match repo::user::exists(&pool, &usr.username).await {
|
||||
match repo::user::get(&pool, &usr.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 user = repo::user::get(&pool, &usr.username).await.unwrap();
|
||||
let salt = repo::salt::get(&pool, &user.salt_id).await.unwrap();
|
||||
let salt_str = hashing::get_salt(&salt.salt).unwrap();
|
||||
// Check if password is correct
|
||||
match hashing::hash_password(&usr.password, &salt_str) {
|
||||
Ok(hash_password) => {
|
||||
if hashing::verify_password(&usr.password, hash_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(&usr.password, &salt_str) {
|
||||
Ok(hash_password) => {
|
||||
if hashing::verify_password(&usr.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;
|
||||
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;
|
||||
}
|
||||
} else {
|
||||
return not_found("Error Hashing").await;
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
return not_found(&err.to_string()).await;
|
||||
}
|
||||
}
|
||||
|
||||
// let user = repo::user::get(&pool, &usr.username).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user