tsk-69: Retrieve username from the db (#76)
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 43s
Rust Build / Test Suite (push) Successful in 1m17s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 41s
Rust Build / build (push) Successful in 57s
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 43s
Rust Build / Test Suite (push) Successful in 1m17s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 41s
Rust Build / build (push) Successful in 57s
Closes #69 Reviewed-on: #76 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit was merged in pull request #76.
This commit is contained in:
@@ -59,10 +59,6 @@ pub mod endpoint {
|
||||
use super::request;
|
||||
use super::response;
|
||||
|
||||
// TODO: At some point, get the username from the DB
|
||||
// Name of service username when returning a login result
|
||||
pub const SERVICE_USERNAME: &str = "service";
|
||||
|
||||
async fn not_found(message: &str) -> (StatusCode, Json<response::Response>) {
|
||||
(
|
||||
StatusCode::NOT_FOUND,
|
||||
@@ -118,7 +114,7 @@ pub mod endpoint {
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
return not_found("Could not verify password").await;
|
||||
return not_found("Could not verify token").await;
|
||||
}
|
||||
} else {
|
||||
return not_found("Error Hashing").await;
|
||||
@@ -154,7 +150,7 @@ pub mod endpoint {
|
||||
let mut response = response::service_login::Response::default();
|
||||
|
||||
match repo::service::valid_passphrase(&pool, &payload.passphrase).await {
|
||||
Ok((id, _passphrase, _date_created)) => {
|
||||
Ok((id, username, _date_created)) => {
|
||||
let key = icarus_envy::environment::get_secret_key().await.value;
|
||||
let (token_literal, duration) =
|
||||
token_stuff::create_service_token(&key, &id).unwrap();
|
||||
@@ -162,7 +158,7 @@ pub mod endpoint {
|
||||
if token_stuff::verify_token(&key, &token_literal) {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
id,
|
||||
username: String::from(SERVICE_USERNAME),
|
||||
username,
|
||||
token: token_literal,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
expiration: duration,
|
||||
@@ -216,15 +212,15 @@ pub mod endpoint {
|
||||
// Get passphrase record with id
|
||||
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||
Ok(id) => match repo::service::get_passphrase(&pool, &id).await {
|
||||
Ok((returned_id, _, _)) => {
|
||||
match token_stuff::create_service_refresh_token(&key, &returned_id) {
|
||||
Ok((username, _, _)) => {
|
||||
match token_stuff::create_service_refresh_token(&key, &id) {
|
||||
Ok((access_token, exp_dur)) => {
|
||||
let login_result = icarus_models::login_result::LoginResult {
|
||||
id: returned_id,
|
||||
id,
|
||||
token: access_token,
|
||||
expiration: exp_dur,
|
||||
token_type: String::from(icarus_models::token::TOKEN_TYPE),
|
||||
username: String::from(SERVICE_USERNAME),
|
||||
username,
|
||||
};
|
||||
response.message = String::from("Successful");
|
||||
response.data.push(login_result);
|
||||
|
||||
Reference in New Issue
Block a user