Improve redirect URI management

This commit is contained in:
2022-04-19 19:30:14 +02:00
parent ce7118ff81
commit 806a085c97
7 changed files with 27 additions and 26 deletions

View File

@@ -0,0 +1,21 @@
#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct LoginRedirect(String);
impl LoginRedirect {
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()
}
}
impl Default for LoginRedirect {
fn default() -> Self {
Self("/".to_string())
}
}