use racal::Queryable;
use serde::{Deserialize, Serialize};
use super::{Authenticating, Authentication};
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct GetCurrentUser;
impl Queryable<Authenticating, crate::model::LoginResponseOrCurrentUser>
for GetCurrentUser
{
fn url(&self, _: &Authenticating) -> String {
format!("{}/auth/user", crate::API_BASE_URI)
}
}
impl Queryable<Authentication, crate::model::CurrentAccount>
for GetCurrentUser
{
fn url(&self, _: &Authentication) -> String {
format!("{}/auth/user", crate::API_BASE_URI)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum VerifySecondFactor {
Code(String),
Recovery(String),
Email(String),
}
impl Queryable<Authentication, crate::model::SecondFactorVerificationStatus>
for VerifySecondFactor
{
fn url(&self, _: &Authentication) -> String {
format!(
"{}/auth/twofactorauth/{}/verify",
crate::API_BASE_URI,
match self {
Self::Code(_) => "totp",
Self::Recovery(_) => "otp",
Self::Email(_) => "emailotp",
}
)
}
fn body(
&self, _state: &Authentication,
) -> Option<serde_json::Result<Vec<u8>>> {
let code = match self {
Self::Code(v) | Self::Recovery(v) | Self::Email(v) => v,
};
Some(serde_json::to_vec(&serde_json::json!({ "code": code })))
}
fn method(&self, _state: &Authentication) -> racal::RequestMethod {
racal::RequestMethod::Post
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct Verify;
impl Queryable<Authentication, crate::model::AuthStatus> for Verify {
fn url(&self, _: &Authentication) -> String {
format!("{}/auth", crate::API_BASE_URI)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct Logout;
impl Queryable<Authentication, crate::model::StatusResponse> for Logout {
fn url(&self, _: &Authentication) -> String {
format!("{}/logout", crate::API_BASE_URI)
}
fn method(&self, _state: &Authentication) -> racal::RequestMethod {
racal::RequestMethod::Put
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub struct DeleteAccount {
pub id: crate::id::User,
}
impl Queryable<Authentication, crate::model::CurrentAccount> for DeleteAccount {
fn url(&self, _: &Authentication) -> String {
format!("{}/users/{}/delete", crate::API_BASE_URI, self.id.as_ref())
}
fn method(&self, _state: &Authentication) -> racal::RequestMethod {
racal::RequestMethod::Put
}
}