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
|
// Check if user exists
|
||||||
match repo::user::exists(&pool, &usr.username).await {
|
// match repo::user::exists(&pool, &usr.username).await {
|
||||||
Ok(exists) => {
|
match repo::user::get(&pool, &usr.username).await {
|
||||||
if !exists {
|
Ok(user) => {
|
||||||
return not_found("Not Found").await;
|
let salt = repo::salt::get(&pool, &user.salt_id).await.unwrap();
|
||||||
}
|
let salt_str = hashing::get_salt(&salt.salt).unwrap();
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
return not_found(&err.to_string()).await;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let user = repo::user::get(&pool, &usr.username).await.unwrap();
|
// Check if password is correct
|
||||||
let salt = repo::salt::get(&pool, &user.salt_id).await.unwrap();
|
match hashing::hash_password(&usr.password, &salt_str) {
|
||||||
let salt_str = hashing::get_salt(&salt.salt).unwrap();
|
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
|
if token_stuff::verify_token(&key, &token_literal) {
|
||||||
match hashing::hash_password(&usr.password, &salt_str) {
|
(
|
||||||
Ok(hash_password) => {
|
StatusCode::OK,
|
||||||
if hashing::verify_password(&usr.password, hash_password.clone()).unwrap() {
|
Json(response::Response {
|
||||||
// Create token
|
message: String::from("Successful"),
|
||||||
let key = token_stuff::get_key().unwrap();
|
data: vec![icarus_models::login_result::LoginResult {
|
||||||
let (token_literal, duration) = token_stuff::create_token(&key).unwrap();
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
if token_stuff::verify_token(&key, &token_literal) {
|
token: token_literal,
|
||||||
(
|
token_type: String::from(token_stuff::TOKENTYPE),
|
||||||
StatusCode::OK,
|
expiration: duration,
|
||||||
Json(response::Response {
|
}],
|
||||||
message: String::from("Successful"),
|
}),
|
||||||
data: vec![icarus_models::login_result::LoginResult {
|
)
|
||||||
id: user.id,
|
} else {
|
||||||
username: user.username,
|
return not_found("Could not verify password").await;
|
||||||
token: token_literal,
|
}
|
||||||
token_type: String::from(token_stuff::TOKENTYPE),
|
} else {
|
||||||
expiration: duration,
|
return not_found("Error Hashing").await;
|
||||||
}],
|
}
|
||||||
}),
|
}
|
||||||
)
|
Err(err) => {
|
||||||
} else {
|
return not_found(&err.to_string()).await;
|
||||||
return not_found("Could not verify password").await;
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return not_found("Error Hashing").await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
return not_found(&err.to_string()).await;
|
return not_found(&err.to_string()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let user = repo::user::get(&pool, &usr.username).await.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user