2021-10-06 20:20:05 +00:00
|
|
|
use lemmy_utils::LemmyError;
|
|
|
|
use url::Url;
|
|
|
|
|
2022-01-13 00:17:00 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
struct DomainError;
|
|
|
|
|
|
|
|
impl std::fmt::Display for DomainError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
write!(f, "Domain mismatch")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for DomainError {}
|
|
|
|
|
2021-10-06 20:20:05 +00:00
|
|
|
pub fn verify_domains_match(a: &Url, b: &Url) -> Result<(), LemmyError> {
|
|
|
|
if a.domain() != b.domain() {
|
|
|
|
return Err(DomainError.into());
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn verify_urls_match(a: &Url, b: &Url) -> Result<(), LemmyError> {
|
|
|
|
if a != b {
|
|
|
|
return Err(DomainError.into());
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|