Update dependencies #17

Merged
phoenix merged 12 commits from update_dependencies into main 2026-06-27 17:47:20 -04:00
Showing only changes of commit 477af9ba18 - Show all commits
+44 -51
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,12 +439,13 @@ 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 =
match token_stuff::create_service_refresh_token(key, id) { |id, key| -> Option<textsender_models::token::CreateTokenResult> {
Ok(cst) => Some(cst), match token_stuff::create_service_refresh_token(key, id) {
Err(_err) => None, Ok(cst) => Some(cst),
} Err(_err) => None,
}; }
};
let mut response = response::RefreshTokenResponse { let mut response = response::RefreshTokenResponse {
message: String::new(), message: String::new(),
@@ -453,9 +453,33 @@ 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 =
String::from(super::messages::SUCCESSFUL_MESSAGE);
let lr = textsender_models::token::LoginResult {
user_id: id,
access_token: cst.access_token,
issued_at: cst.issued,
expires_in: cst.expires_in,
token_type: String::from(textsender_models::token::TOKEN_TYPE),
};
response.data.push(lr);
(axum::http::StatusCode::OK, axum::Json(response))
}
None => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse {
message: String::from("Refresh token not generated"),
data: Vec::new(),
}),
),
},
Err(err) => {
println!("Unable to find user, checking service user: {err:?}");
match repo::service::get(&pool, &id).await {
Ok(_service_user) => match generate_service_token(&id, &key) {
Some(cst) => {
response.message = response.message =
String::from(super::messages::SUCCESSFUL_MESSAGE); String::from(super::messages::SUCCESSFUL_MESSAGE);
let lr = textsender_models::token::LoginResult { let lr = textsender_models::token::LoginResult {
@@ -469,46 +493,15 @@ pub async fn refresh_token(
}; };
response.data.push(lr); response.data.push(lr);
(axum::http::StatusCode::OK, axum::Json(response)) (axum::http::StatusCode::OK, axum::Json(response))
}
None => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse {
message: String::from("Issued at not returned"),
data: Vec::new(),
}),
),
}, },
None => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse {
message: String::from("Refresh token not generated"),
data: Vec::new(),
}),
),
}
}
Err(err) => {
println!("Unable to find user, checking service user: {err:?}");
match repo::service::get(&pool, &id).await {
Ok(_service_user) => {
match generate_service_token(&id, &key) {
Some(cst) => {
response.message = String::from(
super::messages::SUCCESSFUL_MESSAGE,
);
let lr = textsender_models::token::LoginResult {
user_id: id,
access_token: cst.access_token,
issued_at: cst.issued,
expires_in: cst.expires_in,
token_type: String::from(
textsender_models::token::TOKEN_TYPE,
),
};
response.data.push(lr);
(axum::http::StatusCode::OK, axum::Json(response))
}
None => (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
axum::Json(response::RefreshTokenResponse {
message: String::from("Issued at not returned"),
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 {