diff --git a/plume-models/src/signups.rs b/plume-models/src/signups.rs index 07bdff15..7a520eab 100644 --- a/plume-models/src/signups.rs +++ b/plume-models/src/signups.rs @@ -1,3 +1,5 @@ +use crate::CONFIG; +use rocket::request::{FromRequest, Outcome, Request}; use std::fmt; use std::str::FromStr; @@ -43,3 +45,28 @@ impl fmt::Display for StrategyError { } impl std::error::Error for StrategyError {} + +pub struct Password(); +pub struct Email(); + +impl<'a, 'r> FromRequest<'a, 'r> for Password { + type Error = (); + + fn from_request(_request: &'a Request<'r>) -> Outcome { + match matches!(CONFIG.signup, Strategy::Password) { + true => Outcome::Success(Self()), + false => Outcome::Forward(()), + } + } +} + +impl<'a, 'r> FromRequest<'a, 'r> for Email { + type Error = (); + + fn from_request(_request: &'a Request<'r>) -> Outcome { + match matches!(CONFIG.signup, Strategy::Email) { + true => Outcome::Success(Self()), + false => Outcome::Forward(()), + } + } +}