pub use crate::api::auth::{
auth_step, next_step_request, AuthStep, NextStepRequest, Session, StepBackRequest,
StreamStepsRequest,
};
use super::*;
use crate::api::auth::next_step_request::form_fields::Field;
#[derive(Debug, Clone)]
pub enum AuthStepResponse {
Choice(String),
Form(Vec<Field>),
Initial,
}
impl AuthStepResponse {
#[inline(always)]
pub fn choice(choice: impl ToString) -> Self {
Self::Choice(choice.to_string())
}
#[inline(always)]
pub fn form(fields: Vec<Field>) -> Self {
Self::Form(fields)
}
#[inline(always)]
pub fn login_choice() -> Self {
Self::choice("login")
}
#[inline(always)]
pub fn register_choice() -> Self {
Self::choice("register")
}
pub fn login_form(email: impl ToString, password: impl ToString) -> Self {
Self::form(vec![
Field::String(email.to_string()),
Field::Bytes(password.to_string().into_bytes()),
])
}
pub fn register_form(
email: impl ToString,
username: impl ToString,
password: impl ToString,
) -> Self {
Self::form(vec![
Field::String(username.to_string()),
Field::String(email.to_string()),
Field::Bytes(password.to_string().into_bytes()),
])
}
}
impl From<AuthStepResponse> for Option<next_step_request::Step> {
fn from(other: AuthStepResponse) -> Option<next_step_request::Step> {
match other {
AuthStepResponse::Choice(choice) => {
Some(next_step_request::Step::Choice(next_step_request::Choice {
choice,
}))
}
AuthStepResponse::Form(fields) => {
Some(next_step_request::Step::Form(next_step_request::Form {
fields: fields
.into_iter()
.map(|f| next_step_request::FormFields { field: Some(f) })
.collect(),
}))
}
AuthStepResponse::Initial => None,
}
}
}
#[into_request("NextStepRequest")]
#[derive(Debug, Clone, new)]
pub struct AuthResponse {
auth_id: String,
step: AuthStepResponse,
}
#[into_request("StepBackRequest", "StreamStepsRequest")]
#[derive(Debug, Clone, From, Into, Display, new)]
pub struct AuthId {
auth_id: String,
}