Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
137398405f |
Generated
+152
-427
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "textsender_models"
|
name = "textsender_models"
|
||||||
version = "0.4.11"
|
version = "0.5.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.96"
|
rust-version = "1.96"
|
||||||
description = "Models used for the textsender project"
|
description = "Models used for the textsender project"
|
||||||
@@ -9,7 +9,7 @@ description = "Models used for the textsender project"
|
|||||||
serde = { version = "1.0.228", features = ["derive"] }
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
serde_json = { version = "1.0.150" }
|
serde_json = { version = "1.0.150" }
|
||||||
time = { version = "0.3.49", features = ["formatting", "macros", "parsing", "serde"] }
|
time = { version = "0.3.49", features = ["formatting", "macros", "parsing", "serde"] }
|
||||||
sqlx = { version = "0.8.6", features = ["postgres", "runtime-tokio-native-tls", "time", "uuid"] }
|
sqlx = { version = "0.9.0", features = ["runtime-tokio", "tls-native-tls", "postgres", "time", "uuid"] }
|
||||||
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
uuid = { version = "1.23.3", features = ["v4", "serde"] }
|
||||||
dotenvy = { version = "0.15.7" }
|
dotenvy = { version = "0.15.7" }
|
||||||
const_format = { version = "0.2.36" }
|
const_format = { version = "0.2.36" }
|
||||||
|
|||||||
@@ -4,13 +4,10 @@
|
|||||||
pub struct Contact {
|
pub struct Contact {
|
||||||
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
#[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
||||||
pub id: Option<uuid::Uuid>,
|
pub id: Option<uuid::Uuid>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub firstname: Option<String>,
|
pub firstname: Option<String>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub lastname: Option<String>,
|
pub lastname: Option<String>,
|
||||||
// empty?
|
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub nickname: Option<String>,
|
pub nickname: Option<String>,
|
||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
|
|||||||
+8
-8
@@ -78,8 +78,8 @@ pub struct CreateTokenResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_token(
|
pub fn create_token(
|
||||||
key: &String,
|
key: &str,
|
||||||
token_resource: &TokenResource,
|
token_resource: TokenResource,
|
||||||
duration: time::Duration,
|
duration: time::Duration,
|
||||||
) -> Result<CreateTokenResult, josekit::JoseError> {
|
) -> Result<CreateTokenResult, josekit::JoseError> {
|
||||||
let mut header = josekit::jws::JwsHeader::new();
|
let mut header = josekit::jws::JwsHeader::new();
|
||||||
@@ -103,7 +103,7 @@ pub fn create_token(
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ok(CreateTokenResult {
|
Ok(CreateTokenResult {
|
||||||
access_token: access_token,
|
access_token,
|
||||||
issued: issued.unix_timestamp(),
|
issued: issued.unix_timestamp(),
|
||||||
expires_in: expire.unix_timestamp(),
|
expires_in: expire.unix_timestamp(),
|
||||||
token_issued: issued,
|
token_issued: issued,
|
||||||
@@ -114,7 +114,7 @@ pub fn create_token(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn init_payload(
|
fn init_payload(
|
||||||
token_resource: &TokenResource,
|
token_resource: TokenResource,
|
||||||
duration: time::Duration,
|
duration: time::Duration,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
@@ -125,9 +125,9 @@ fn init_payload(
|
|||||||
josekit::JoseError,
|
josekit::JoseError,
|
||||||
> {
|
> {
|
||||||
let mut payload = josekit::jwt::JwtPayload::new();
|
let mut payload = josekit::jwt::JwtPayload::new();
|
||||||
payload.set_subject(&token_resource.message);
|
payload.set_subject(token_resource.message);
|
||||||
payload.set_issuer(&token_resource.issuer);
|
payload.set_issuer(token_resource.issuer);
|
||||||
payload.set_audience(token_resource.audiences.clone());
|
payload.set_audience(token_resource.audiences);
|
||||||
|
|
||||||
if !token_resource.user_id.is_nil() {
|
if !token_resource.user_id.is_nil() {
|
||||||
match payload.set_claim("user_id", Some(serde_json::json!(token_resource.user_id))) {
|
match payload.set_claim("user_id", Some(serde_json::json!(token_resource.user_id))) {
|
||||||
@@ -192,7 +192,7 @@ mod tests {
|
|||||||
let token_duration = time::Duration::minutes(30);
|
let token_duration = time::Duration::minutes(30);
|
||||||
let key = String::from(TEST_KEY);
|
let key = String::from(TEST_KEY);
|
||||||
|
|
||||||
match super::create_token(&key, &token_resource, token_duration) {
|
match super::create_token(&key, token_resource, token_duration) {
|
||||||
Ok(cst) => match time::OffsetDateTime::from_unix_timestamp(cst.issued) {
|
Ok(cst) => match time::OffsetDateTime::from_unix_timestamp(cst.issued) {
|
||||||
Ok(d_result) => {
|
Ok(d_result) => {
|
||||||
let they_match = {
|
let they_match = {
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ pub struct User {
|
|||||||
pub phone_number: String,
|
pub phone_number: String,
|
||||||
pub username: String,
|
pub username: String,
|
||||||
pub password: String,
|
pub password: String,
|
||||||
// Firstname is a pointer
|
|
||||||
pub firstname: String,
|
pub firstname: String,
|
||||||
// Lastname is a pointer
|
|
||||||
pub lastname: String,
|
pub lastname: String,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub created: Option<time::OffsetDateTime>,
|
pub created: Option<time::OffsetDateTime>,
|
||||||
@@ -27,7 +25,6 @@ pub struct ServiceUser {
|
|||||||
pub passphrase: String,
|
pub passphrase: String,
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub created: Option<time::OffsetDateTime>,
|
pub created: Option<time::OffsetDateTime>,
|
||||||
// When serializing to json, if empty do not populate
|
|
||||||
#[serde(with = "time::serde::rfc3339::option")]
|
#[serde(with = "time::serde::rfc3339::option")]
|
||||||
pub last_login: Option<time::OffsetDateTime>,
|
pub last_login: Option<time::OffsetDateTime>,
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
@@ -81,7 +78,6 @@ pub struct UserProfile {
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
|
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize, sqlx::FromRow)]
|
||||||
pub struct Salt {
|
pub struct Salt {
|
||||||
// #[serde(skip_serializing_if = "crate::init::is_uuid_nil")]
|
|
||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub salt: String,
|
pub salt: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user