2024-03-27 18:26:07 +00:00
|
|
|
use actix_web::HttpRequest;
|
|
|
|
|
2022-04-19 15:49:57 +00:00
|
|
|
#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Clone)]
|
2022-04-19 17:30:14 +00:00
|
|
|
pub struct LoginRedirect(String);
|
2022-04-19 15:49:57 +00:00
|
|
|
|
2022-04-19 17:30:14 +00:00
|
|
|
impl LoginRedirect {
|
2024-03-27 18:26:07 +00:00
|
|
|
pub fn from_req(req: &HttpRequest) -> Self {
|
|
|
|
Self(req.uri().to_string())
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:49:57 +00:00
|
|
|
pub fn get(&self) -> &str {
|
|
|
|
match self.0.starts_with('/') && !self.0.starts_with("//") {
|
|
|
|
true => self.0.as_str(),
|
|
|
|
false => "/",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_encoded(&self) -> String {
|
|
|
|
urlencoding::encode(self.get()).to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 17:30:14 +00:00
|
|
|
impl Default for LoginRedirect {
|
2022-04-19 15:49:57 +00:00
|
|
|
fn default() -> Self {
|
|
|
|
Self("/".to_string())
|
|
|
|
}
|
2022-11-11 11:26:02 +00:00
|
|
|
}
|
2024-03-27 18:26:07 +00:00
|
|
|
|
|
|
|
/// Get the URL for 2FA authentication
|
|
|
|
pub fn get_2fa_url(redir: &LoginRedirect, force_2fa: bool) -> String {
|
|
|
|
format!(
|
|
|
|
"/2fa_auth?redirect={}&force_2fa={force_2fa}",
|
|
|
|
redir.get_encoded()
|
|
|
|
)
|
|
|
|
}
|