cargo fmt

This commit is contained in:
2026-06-27 17:41:41 -04:00
parent b9351e0030
commit 477af9ba18
+12 -19
View File
@@ -189,8 +189,7 @@ pub async fn user_login(
let key = textsender_models::envy::environment::get_secret_key() let key = textsender_models::envy::environment::get_secret_key()
.await .await
.value; .value;
let cst = let cst = token_stuff::create_token(&key, &user.id).unwrap();
token_stuff::create_token(&key, &user.id).unwrap();
if token_stuff::verify_token(&key, &cst.access_token) { if token_stuff::verify_token(&key, &cst.access_token) {
let current_time = time::OffsetDateTime::now_utc(); let current_time = time::OffsetDateTime::now_utc();
@@ -355,7 +354,7 @@ pub async fn service_user_login(
textsender_models::token::TOKEN_TYPE, textsender_models::token::TOKEN_TYPE,
), ),
issued_at: cst.issued, issued_at: cst.issued,
expires_in: cst.expires_in expires_in: cst.expires_in,
}], }],
}), }),
) )
@@ -440,7 +439,8 @@ pub async fn refresh_token(
if token_stuff::verify_token(&key, &payload.access_token) { if token_stuff::verify_token(&key, &payload.access_token) {
match token_stuff::extract_id_from_token(&key, &payload.access_token) { match token_stuff::extract_id_from_token(&key, &payload.access_token) {
Ok(id) => { Ok(id) => {
let generate_service_token = |id, key| -> Option<textsender_models::token::CreateTokenResult> { let generate_service_token =
|id, key| -> Option<textsender_models::token::CreateTokenResult> {
match token_stuff::create_service_refresh_token(key, id) { match token_stuff::create_service_refresh_token(key, id) {
Ok(cst) => Some(cst), Ok(cst) => Some(cst),
Err(_err) => None, Err(_err) => None,
@@ -453,8 +453,7 @@ pub async fn refresh_token(
}; };
match repo::user::get_with_id(&pool, &id).await { match repo::user::get_with_id(&pool, &id).await {
Ok(_user) => { Ok(_user) => match generate_service_token(&id, &key) {
match generate_service_token(&id, &key) {
Some(cst) => { Some(cst) => {
response.message = response.message =
String::from(super::messages::SUCCESSFUL_MESSAGE); String::from(super::messages::SUCCESSFUL_MESSAGE);
@@ -463,13 +462,11 @@ pub async fn refresh_token(
access_token: cst.access_token, access_token: cst.access_token,
issued_at: cst.issued, issued_at: cst.issued,
expires_in: cst.expires_in, expires_in: cst.expires_in,
token_type: String::from( token_type: String::from(textsender_models::token::TOKEN_TYPE),
textsender_models::token::TOKEN_TYPE,
),
}; };
response.data.push(lr); response.data.push(lr);
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
}, }
None => ( None => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse { axum::Json(response::RefreshTokenResponse {
@@ -477,17 +474,14 @@ pub async fn refresh_token(
data: Vec::new(), data: Vec::new(),
}), }),
), ),
} },
}
Err(err) => { Err(err) => {
println!("Unable to find user, checking service user: {err:?}"); println!("Unable to find user, checking service user: {err:?}");
match repo::service::get(&pool, &id).await { match repo::service::get(&pool, &id).await {
Ok(_service_user) => { Ok(_service_user) => match generate_service_token(&id, &key) {
match generate_service_token(&id, &key) {
Some(cst) => { Some(cst) => {
response.message = String::from( response.message =
super::messages::SUCCESSFUL_MESSAGE, String::from(super::messages::SUCCESSFUL_MESSAGE);
);
let lr = textsender_models::token::LoginResult { let lr = textsender_models::token::LoginResult {
user_id: id, user_id: id,
access_token: cst.access_token, access_token: cst.access_token,
@@ -507,8 +501,7 @@ pub async fn refresh_token(
data: Vec::new(), data: Vec::new(),
}), }),
), ),
} },
}
Err(err) => ( Err(err) => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR, axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse { axum::Json(response::RefreshTokenResponse {