#![allow(clippy::struct_excessive_bools)]
#![allow(clippy::module_name_repetitions)]
use racal::FromApiState;
use serde::{Deserialize, Serialize};
mod contact;
mod group;
mod message;
mod session;
mod stats;
mod testing;
mod user;
mod user_session;
pub use contact::*;
pub use group::*;
pub use message::*;
pub use session::*;
pub use stats::*;
pub use testing::*;
pub use user::*;
pub use user_session::*;
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(Debug, PartialEq, Eq, Clone, Hash, Deserialize, Serialize)]
pub struct UserSessionQueryWithHeaders {
pub body: crate::query::UserSession,
#[serde(flatten)]
pub data: Authenticating,
}
pub struct NoAuthentication {}
impl racal::FromApiState<Self> for NoAuthentication {
fn from_state(state: &Self) -> &Self { state }
}
impl racal::FromApiState<Authentication> for NoAuthentication {
fn from_state(_: &Authentication) -> &Self { &Self {} }
}
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[derive(PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
pub struct Authentication {
pub token: String,
pub user_id: crate::id::User,
}
impl Authentication {
#[must_use]
pub fn to_header(&self) -> (&'static str, String) {
(
"Authorization",
("res ".to_owned() + self.user_id.as_ref() + ":" + &self.token),
)
}
}
impl From<crate::model::UserSession> for Authentication {
fn from(value: crate::model::UserSession) -> Self {
Self { token: value.token, user_id: value.user_id }
}
}
impl std::fmt::Debug for Authentication {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Authentication")
.field("token", &"*****")
.field("user_id", &self.user_id)
.finish()
}
}
impl FromApiState<Self> for Authentication {
fn from_state(state: &Self) -> &Self { state }
}
#[cfg_attr(
feature = "borsh",
derive(borsh::BorshSerialize, borsh::BorshDeserialize)
)]
#[serde_with::serde_as]
#[derive(Debug, PartialEq, Eq, Hash, Clone, Deserialize, Serialize)]
pub struct Authenticating {
#[serde(rename = "TOTP")]
#[serde_as(deserialize_as = "serde_with::DefaultOnNull")]
#[serde(default)]
#[serde(skip_serializing_if = "Option::is_none")]
pub second_factor: Option<String>,
#[serde(rename = "UID")]
pub unique_machine_identifier: String,
}
impl FromApiState<Self> for Authenticating {
fn from_state(state: &Self) -> &Self { state }
}