Updating name references
This commit is contained in:
Generated
+17
-17
@@ -1389,6 +1389,22 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "schedtxt_models"
|
||||
version = "0.5.3"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/schedtxt_models.git?tag=v0.5.3#597af4e84c082bb437cc94817bb19592614681a5"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
"josekit",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sqlx",
|
||||
"time",
|
||||
"utoipa",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.2.0"
|
||||
@@ -1824,10 +1840,10 @@ dependencies = [
|
||||
"argon2",
|
||||
"axum",
|
||||
"josekit",
|
||||
"schedtxt_models",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sqlx",
|
||||
"textsender_models",
|
||||
"time",
|
||||
"tokio",
|
||||
"tower",
|
||||
@@ -1839,22 +1855,6 @@ dependencies = [
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textsender_models"
|
||||
version = "0.5.2"
|
||||
source = "git+ssh://git@git.kundeng.us/phoenix/textsender_models.git?tag=v0.5.2#02061bf7a380657b7bc76d64d1824388bef8e55a"
|
||||
dependencies = [
|
||||
"const_format",
|
||||
"dotenvy",
|
||||
"josekit",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sqlx",
|
||||
"time",
|
||||
"utoipa",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.18"
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ time = { version = "0.3.53", features = ["macros", "serde"] }
|
||||
josekit = { version = "0.10.3" }
|
||||
utoipa = { version = "5.5.0", features = ["axum_extras"] }
|
||||
utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] }
|
||||
textsender_models = { git = "ssh://git@git.kundeng.us/phoenix/textsender_models.git", tag = "v0.5.2", features = ["config", "user"] }
|
||||
schedtxt_models = { git = "ssh://git@git.kundeng.us/phoenix/schedtxt_models.git", tag = "v0.5.3", features = ["config", "user"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tower = { version = "0.5.3", features = ["full"] }
|
||||
|
||||
+19
-19
@@ -84,13 +84,13 @@ pub mod response {
|
||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct LoginResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::token::LoginResult>,
|
||||
pub data: Vec<schedtxt_models::token::LoginResult>,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct ServiceUserLoginResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::token::LoginResult>,
|
||||
pub data: Vec<schedtxt_models::token::LoginResult>,
|
||||
}
|
||||
|
||||
pub async fn extract(
|
||||
@@ -114,7 +114,7 @@ pub mod response {
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct RefreshTokenResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::token::LoginResult>,
|
||||
pub data: Vec<schedtxt_models::token::LoginResult>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
@@ -126,13 +126,13 @@ pub mod response {
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct UserUpdateNameResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::user::User>,
|
||||
pub data: Vec<schedtxt_models::user::User>,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct GetUserProfileResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::user::UserProfile>,
|
||||
pub data: Vec<schedtxt_models::user::UserProfile>,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ pub async fn user_login(
|
||||
if matches {
|
||||
// Create token
|
||||
let key =
|
||||
textsender_models::envy::environment::get_secret_key().value;
|
||||
schedtxt_models::envy::environment::get_secret_key().value;
|
||||
let cst = match token_stuff::create_token(&key, &user.id) {
|
||||
Ok(token) => token,
|
||||
Err(_err) => {
|
||||
@@ -225,11 +225,11 @@ pub async fn user_login(
|
||||
axum::http::StatusCode::OK,
|
||||
axum::Json(response::LoginResponse {
|
||||
message: String::from("Successful"),
|
||||
data: vec![textsender_models::token::LoginResult {
|
||||
data: vec![schedtxt_models::token::LoginResult {
|
||||
user_id: user.id,
|
||||
access_token: cst.access_token,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
schedtxt_models::token::TOKEN_TYPE,
|
||||
),
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
@@ -351,7 +351,7 @@ pub async fn service_user_login(
|
||||
// Create token
|
||||
println!("Creating token");
|
||||
let key =
|
||||
textsender_models::envy::environment::get_secret_key().value;
|
||||
schedtxt_models::envy::environment::get_secret_key().value;
|
||||
let cst =
|
||||
token_stuff::create_token(&key, &service_user.id).unwrap();
|
||||
|
||||
@@ -370,11 +370,11 @@ pub async fn service_user_login(
|
||||
message: String::from(
|
||||
super::messages::SUCCESSFUL_MESSAGE,
|
||||
),
|
||||
data: vec![textsender_models::token::LoginResult {
|
||||
data: vec![schedtxt_models::token::LoginResult {
|
||||
user_id: service_user.id,
|
||||
access_token: cst.access_token,
|
||||
token_type: String::from(
|
||||
textsender_models::token::TOKEN_TYPE,
|
||||
schedtxt_models::token::TOKEN_TYPE,
|
||||
),
|
||||
issued_at: cst.issued,
|
||||
expires_in: cst.expires_in,
|
||||
@@ -456,12 +456,12 @@ pub async fn refresh_token(
|
||||
}),
|
||||
)
|
||||
} else {
|
||||
let key = textsender_models::envy::environment::get_secret_key().value;
|
||||
let key = schedtxt_models::envy::environment::get_secret_key().value;
|
||||
if token_stuff::verify_token(&key, &payload.access_token) {
|
||||
match token_stuff::extract_id_from_token(&key, &payload.access_token) {
|
||||
Ok(id) => {
|
||||
let generate_service_token =
|
||||
|id, key| -> Option<textsender_models::token::CreateTokenResult> {
|
||||
|id, key| -> Option<schedtxt_models::token::CreateTokenResult> {
|
||||
token_stuff::create_service_refresh_token(key, id).ok()
|
||||
};
|
||||
|
||||
@@ -475,12 +475,12 @@ pub async fn refresh_token(
|
||||
Some(cst) => {
|
||||
response.message =
|
||||
String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||
let lr = textsender_models::token::LoginResult {
|
||||
let lr = schedtxt_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),
|
||||
token_type: String::from(schedtxt_models::token::TOKEN_TYPE),
|
||||
};
|
||||
response.data.push(lr);
|
||||
(axum::http::StatusCode::OK, axum::Json(response))
|
||||
@@ -500,13 +500,13 @@ pub async fn refresh_token(
|
||||
Some(cst) => {
|
||||
response.message =
|
||||
String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||
let lr = textsender_models::token::LoginResult {
|
||||
let lr = schedtxt_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,
|
||||
schedtxt_models::token::TOKEN_TYPE,
|
||||
),
|
||||
};
|
||||
response.data.push(lr);
|
||||
@@ -785,7 +785,7 @@ pub async fn update_name_of_user(
|
||||
axum::http::StatusCode::OK,
|
||||
axum::Json(response::UserUpdateNameResponse {
|
||||
message: String::from(super::messages::SUCCESSFUL_MESSAGE),
|
||||
data: vec![textsender_models::user::User {
|
||||
data: vec![schedtxt_models::user::User {
|
||||
id: user.id,
|
||||
phone_number: user.phone_number,
|
||||
firstname: payload.firstname,
|
||||
@@ -844,7 +844,7 @@ pub async fn get_user_profile(
|
||||
|
||||
match repo::user::get_with_id(&pool, &id).await {
|
||||
Ok(user) => {
|
||||
let user_profile = textsender_models::user::UserProfile {
|
||||
let user_profile = schedtxt_models::user::UserProfile {
|
||||
user_id: user.id,
|
||||
phone_number: user.phone_number,
|
||||
firstname: user.firstname,
|
||||
|
||||
@@ -49,22 +49,22 @@ pub mod response {
|
||||
#[derive(Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::user::User>,
|
||||
pub data: Vec<schedtxt_models::user::User>,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize, Serialize, utoipa::ToSchema)]
|
||||
pub struct RegisterServiceUserResponse {
|
||||
pub message: String,
|
||||
pub data: Vec<textsender_models::user::ServiceUser>,
|
||||
pub data: Vec<schedtxt_models::user::ServiceUser>,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn generate_the_salt() -> (
|
||||
argon2::password_hash::SaltString,
|
||||
textsender_models::user::Salt,
|
||||
schedtxt_models::user::Salt,
|
||||
) {
|
||||
let salt_string = hashing::generate_salt().unwrap();
|
||||
let salt = textsender_models::user::Salt::default();
|
||||
let salt = schedtxt_models::user::Salt::default();
|
||||
(salt_string, salt)
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ pub async fn register_user(
|
||||
};
|
||||
|
||||
if registration_enabled {
|
||||
let mut user = textsender_models::user::User {
|
||||
let mut user = schedtxt_models::user::User {
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
phone_number: payload.phone_number.clone(),
|
||||
@@ -181,7 +181,7 @@ pub async fn register_user(
|
||||
/// Checks to see if registration is enabled
|
||||
async fn is_registration_enabled() -> Result<bool, std::io::Error> {
|
||||
let key = String::from("ENABLE_REGISTRATION");
|
||||
let var = textsender_models::envy::environment::get_env(&key);
|
||||
let var = schedtxt_models::envy::environment::get_env(&key);
|
||||
let parsed_value = var.value.to_uppercase();
|
||||
|
||||
if parsed_value == "TRUE" {
|
||||
@@ -248,7 +248,7 @@ pub async fn register_service_user(
|
||||
} else {
|
||||
let (generate_salt, mut salt) = generate_the_salt();
|
||||
salt.id = repo::salt::insert(&pool, &salt).await.unwrap();
|
||||
let mut service_user = textsender_models::user::ServiceUser {
|
||||
let mut service_user = schedtxt_models::user::ServiceUser {
|
||||
username: payload.username.clone(),
|
||||
passphrase: hashing::hash_password(&payload.passphrase, &generate_salt)
|
||||
.unwrap(),
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
|
||||
pub async fn create_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let database_url = textsender_models::envy::environment::get_db_url().value;
|
||||
let database_url = schedtxt_models::envy::environment::get_db_url().value;
|
||||
println!("Database url: {database_url}");
|
||||
|
||||
PgPoolOptions::new()
|
||||
|
||||
+3
-3
@@ -54,11 +54,11 @@ pub mod init {
|
||||
.max_age(std::time::Duration::from_secs(3600)); // Cache the preflight response for 1 hour:cite[2]
|
||||
|
||||
// Dynamically set the allowed origin based on the environment
|
||||
match std::env::var(textsender_models::envy::keys::APP_ENV).as_deref() {
|
||||
match std::env::var(schedtxt_models::envy::keys::APP_ENV).as_deref() {
|
||||
Ok("production") => {
|
||||
let allowed_origins_env =
|
||||
textsender_models::envy::environment::get_allowed_origins();
|
||||
match textsender_models::envy::utility::delimitize(&allowed_origins_env) {
|
||||
schedtxt_models::envy::environment::get_allowed_origins();
|
||||
match schedtxt_models::envy::utility::delimitize(&allowed_origins_env) {
|
||||
Ok(alwd) => {
|
||||
let allowed_origins: Vec<axum::http::HeaderValue> = alwd
|
||||
.into_iter()
|
||||
|
||||
+10
-10
@@ -12,7 +12,7 @@ pub mod user {
|
||||
pub async fn get(
|
||||
pool: &sqlx::PgPool,
|
||||
username: &String,
|
||||
) -> Result<textsender_models::user::User, sqlx::Error> {
|
||||
) -> Result<schedtxt_models::user::User, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, username, password, phone_number, salt_id, firstname, lastname, created, last_login FROM "user" WHERE username = $1
|
||||
@@ -24,7 +24,7 @@ pub mod user {
|
||||
|
||||
match result {
|
||||
Ok(r) => match r {
|
||||
Some(r) => Ok(textsender_models::user::User {
|
||||
Some(r) => Ok(schedtxt_models::user::User {
|
||||
id: r.try_get("id")?,
|
||||
username: r.try_get("username")?,
|
||||
password: r.try_get("password")?,
|
||||
@@ -44,7 +44,7 @@ pub mod user {
|
||||
pub async fn get_with_id(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::user::User, sqlx::Error> {
|
||||
) -> Result<schedtxt_models::user::User, sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"
|
||||
SELECT id, username, password, phone_number, salt_id, firstname, lastname, created, last_login FROM "user" WHERE id = $1
|
||||
@@ -54,7 +54,7 @@ pub mod user {
|
||||
.fetch_optional(pool)
|
||||
.await {
|
||||
Ok(r) => match r {
|
||||
Some(r) => Ok(textsender_models::user::User {
|
||||
Some(r) => Ok(schedtxt_models::user::User {
|
||||
id: r.try_get("id")?,
|
||||
username: r.try_get("username")?,
|
||||
password: r.try_get("password")?,
|
||||
@@ -73,7 +73,7 @@ pub mod user {
|
||||
|
||||
pub async fn update_last_login(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &textsender_models::user::User,
|
||||
user: &schedtxt_models::user::User,
|
||||
time: &time::OffsetDateTime,
|
||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
@@ -106,7 +106,7 @@ pub mod user {
|
||||
|
||||
pub async fn update_password(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &textsender_models::user::User,
|
||||
user: &schedtxt_models::user::User,
|
||||
updated_hashed_password: &String,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
match sqlx::query(
|
||||
@@ -189,7 +189,7 @@ pub mod user {
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &textsender_models::user::User,
|
||||
user: &schedtxt_models::user::User,
|
||||
) -> Result<(uuid::Uuid, std::option::Option<time::OffsetDateTime>), sqlx::Error> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
@@ -237,7 +237,7 @@ pub mod salt {
|
||||
pub async fn get(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::user::Salt, sqlx::Error> {
|
||||
) -> Result<schedtxt_models::user::Salt, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
r#"
|
||||
SELECT id, salt FROM "salt" WHERE id = $1
|
||||
@@ -249,7 +249,7 @@ pub mod salt {
|
||||
|
||||
match result {
|
||||
Ok(r) => match r {
|
||||
Some(r) => Ok(textsender_models::user::Salt {
|
||||
Some(r) => Ok(schedtxt_models::user::Salt {
|
||||
id: r.try_get("id")?,
|
||||
salt: r.try_get("salt")?,
|
||||
}),
|
||||
@@ -261,7 +261,7 @@ pub mod salt {
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
salt: &textsender_models::user::Salt,
|
||||
salt: &schedtxt_models::user::Salt,
|
||||
) -> Result<uuid::Uuid, sqlx::Error> {
|
||||
let row = sqlx::query(
|
||||
r#"
|
||||
|
||||
+7
-7
@@ -52,7 +52,7 @@ pub async fn get_passphrase(
|
||||
pub async fn get(
|
||||
pool: &sqlx::PgPool,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::user::ServiceUser, sqlx::Error> {
|
||||
) -> Result<schedtxt_models::user::ServiceUser, sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"SELECT id, username, passphrase, created, last_login, salt_id FROM "service_user" WHERE id = $1"#
|
||||
).bind(id)
|
||||
@@ -68,7 +68,7 @@ pub async fn get(
|
||||
}
|
||||
};
|
||||
|
||||
let service_user = textsender_models::user::ServiceUser {
|
||||
let service_user = schedtxt_models::user::ServiceUser {
|
||||
id: row.try_get("id")?,
|
||||
username: row.try_get("username")?,
|
||||
passphrase: row.try_get("passphrase")?,
|
||||
@@ -88,7 +88,7 @@ pub async fn get(
|
||||
pub async fn get_with_username(
|
||||
pool: &sqlx::PgPool,
|
||||
username: &String,
|
||||
) -> Result<textsender_models::user::ServiceUser, sqlx::Error> {
|
||||
) -> Result<schedtxt_models::user::ServiceUser, sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"SELECT id, username, passphrase, created, last_login, salt_id FROM "service_user" WHERE username = $1"#
|
||||
).bind(username)
|
||||
@@ -104,7 +104,7 @@ pub async fn get_with_username(
|
||||
}
|
||||
};
|
||||
|
||||
let service_user = textsender_models::user::ServiceUser {
|
||||
let service_user = schedtxt_models::user::ServiceUser {
|
||||
id: row.try_get("id")?,
|
||||
username: row.try_get("username")?,
|
||||
passphrase: row.try_get("passphrase")?,
|
||||
@@ -123,7 +123,7 @@ pub async fn get_with_username(
|
||||
|
||||
pub async fn update_last_login(
|
||||
pool: &sqlx::PgPool,
|
||||
service_user: &textsender_models::user::ServiceUser,
|
||||
service_user: &schedtxt_models::user::ServiceUser,
|
||||
time: &time::OffsetDateTime,
|
||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
||||
let result = sqlx::query(
|
||||
@@ -156,7 +156,7 @@ pub async fn update_last_login(
|
||||
|
||||
pub async fn update_passphrase(
|
||||
pool: &sqlx::PgPool,
|
||||
user: &textsender_models::user::ServiceUser,
|
||||
user: &schedtxt_models::user::ServiceUser,
|
||||
updated_hashed_passphrase: &String,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
match sqlx::query(
|
||||
@@ -182,7 +182,7 @@ pub async fn update_passphrase(
|
||||
|
||||
pub async fn insert(
|
||||
pool: &sqlx::PgPool,
|
||||
service_user: &textsender_models::user::ServiceUser,
|
||||
service_user: &schedtxt_models::user::ServiceUser,
|
||||
) -> Result<(uuid::Uuid, time::OffsetDateTime), sqlx::Error> {
|
||||
match sqlx::query(
|
||||
r#"INSERT INTO "service_user" (username, passphrase, salt_id)
|
||||
|
||||
+10
-10
@@ -19,40 +19,40 @@ pub fn get_expiration(issued: &time::OffsetDateTime) -> Result<time::OffsetDateT
|
||||
pub fn create_token(
|
||||
provided_key: &str,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
) -> Result<schedtxt_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = schedtxt_models::token::TokenResource {
|
||||
message: String::from(MESSAGE),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(provided_key, resource, time::Duration::hours(4))
|
||||
schedtxt_models::token::create_token(provided_key, resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn create_service_token(
|
||||
provided: &str,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
) -> Result<schedtxt_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = schedtxt_models::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(provided, resource, time::Duration::hours(1))
|
||||
schedtxt_models::token::create_token(provided, resource, time::Duration::hours(1))
|
||||
}
|
||||
|
||||
pub fn create_service_refresh_token(
|
||||
key: &str,
|
||||
id: &uuid::Uuid,
|
||||
) -> Result<textsender_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = textsender_models::token::TokenResource {
|
||||
) -> Result<schedtxt_models::token::CreateTokenResult, josekit::JoseError> {
|
||||
let resource = schedtxt_models::token::TokenResource {
|
||||
message: String::from(SERVICE_SUBJECT),
|
||||
issuer: String::from(ISSUER),
|
||||
audiences: vec![String::from(AUDIENCE)],
|
||||
user_id: *id,
|
||||
};
|
||||
textsender_models::token::create_token(key, resource, time::Duration::hours(4))
|
||||
schedtxt_models::token::create_token(key, resource, time::Duration::hours(4))
|
||||
}
|
||||
|
||||
pub fn verify_token(key: &str, token: &str) -> bool {
|
||||
@@ -119,7 +119,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_tokenize() {
|
||||
let special_key = textsender_models::envy::environment::get_secret_key();
|
||||
let special_key = schedtxt_models::envy::environment::get_secret_key();
|
||||
let id = uuid::Uuid::new_v4();
|
||||
match create_token(&special_key.value, &id) {
|
||||
Ok(cst) => {
|
||||
|
||||
+9
-9
@@ -9,7 +9,7 @@ mod db_mgr {
|
||||
pub const LIMIT: usize = 6;
|
||||
|
||||
pub async fn get_pool() -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let tm_db_url = textsender_models::envy::environment::get_db_url().value;
|
||||
let tm_db_url = schedtxt_models::envy::environment::get_db_url().value;
|
||||
let tm_options = sqlx::postgres::PgConnectOptions::from_str(&tm_db_url).unwrap();
|
||||
sqlx::PgPool::connect_with(tm_options).await
|
||||
}
|
||||
@@ -21,7 +21,7 @@ mod db_mgr {
|
||||
}
|
||||
|
||||
pub async fn connect_to_db(db_name: &str) -> Result<sqlx::PgPool, sqlx::Error> {
|
||||
let db_url = textsender_models::envy::environment::get_db_url().value;
|
||||
let db_url = schedtxt_models::envy::environment::get_db_url().value;
|
||||
let options = sqlx::postgres::PgConnectOptions::from_str(&db_url)?.database(db_name);
|
||||
sqlx::PgPool::connect_with(options).await
|
||||
}
|
||||
@@ -53,7 +53,7 @@ mod db_mgr {
|
||||
}
|
||||
|
||||
pub async fn get_database_name() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let database_url = textsender_models::envy::environment::get_db_url().value;
|
||||
let database_url = schedtxt_models::envy::environment::get_db_url().value;
|
||||
|
||||
let parsed_url = url::Url::parse(&database_url)?;
|
||||
if parsed_url.scheme() == "postgres" || parsed_url.scheme() == "postgresql" {
|
||||
@@ -308,7 +308,7 @@ mod flow {
|
||||
|
||||
pub async fn register_user(
|
||||
app: &axum::Router,
|
||||
) -> Result<textsender_models::user::User, std::io::Error> {
|
||||
) -> Result<schedtxt_models::user::User, std::io::Error> {
|
||||
match requests::register_user(&app).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::CREATED != response.status() {
|
||||
@@ -340,7 +340,7 @@ mod flow {
|
||||
app: &axum::Router,
|
||||
username: &str,
|
||||
password: &str,
|
||||
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||
) -> Result<schedtxt_models::token::LoginResult, std::io::Error> {
|
||||
match requests::login_user(&app, username, password).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::OK != response.status() {
|
||||
@@ -372,7 +372,7 @@ mod flow {
|
||||
|
||||
pub async fn register_service_user(
|
||||
app: &axum::Router,
|
||||
) -> Result<textsender_models::user::ServiceUser, std::io::Error> {
|
||||
) -> Result<schedtxt_models::user::ServiceUser, std::io::Error> {
|
||||
match requests::register_service_user(&app).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::CREATED != response.status() {
|
||||
@@ -406,7 +406,7 @@ mod flow {
|
||||
app: &axum::Router,
|
||||
username: &str,
|
||||
passphrase: &str,
|
||||
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||
) -> Result<schedtxt_models::token::LoginResult, std::io::Error> {
|
||||
match requests::login_service_user(&app, username, passphrase).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::OK != response.status() {
|
||||
@@ -439,7 +439,7 @@ mod flow {
|
||||
pub async fn refresh_token(
|
||||
app: &axum::Router,
|
||||
access_token: &str,
|
||||
) -> Result<textsender_models::token::LoginResult, std::io::Error> {
|
||||
) -> Result<schedtxt_models::token::LoginResult, std::io::Error> {
|
||||
match requests::refresh_token(app, access_token).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::OK != response.status() {
|
||||
@@ -518,7 +518,7 @@ mod flow {
|
||||
user_id: &uuid::Uuid,
|
||||
firstname: &str,
|
||||
lastname: &str,
|
||||
) -> Result<textsender_models::user::User, std::io::Error> {
|
||||
) -> Result<schedtxt_models::user::User, std::io::Error> {
|
||||
match requests::update_name_of_user(app, user_id, firstname, lastname).await {
|
||||
Ok(response) => {
|
||||
if axum::http::StatusCode::OK != response.status() {
|
||||
|
||||
Reference in New Issue
Block a user