mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-07 02:21:23 +00:00
parse email address from index
This commit is contained in:
1 parent
a906bcf1be
commit
cc9089388f
4 files changed
+56
No files matched your search
@@ -1,3 +1,4 @@
|
||||
pub mod file_id;
|
||||
pub mod file_upload_spec;
|
||||
pub mod user_email;
|
||||
pub mod user_id;
|
||||
@@ -0,0 +1,3 @@
|
||||
/// Type for User Emails
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserEmail(pub String);
|
||||
@@ -5,3 +5,4 @@ pub mod parse_index_sentry_trace;
|
||||
pub mod parse_index_svg_paths;
|
||||
pub mod parse_index_verification_token;
|
||||
mod parse_index_user_id;
|
||||
mod parse_index_user_email;
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
use crate::datatypes::user_id::UserId;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use crate::datatypes::user_email::UserEmail;
|
||||
|
||||
/// Find the user email in the index.html payload
|
||||
/// eg.
|
||||
static JSON_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||
Regex::new(r#"\\?"email\\?":\s*\\?"([^"\\]+)\\?",?"#)
|
||||
.expect("Regex should parse")
|
||||
});
|
||||
|
||||
/// Parse the user email from the index.html
|
||||
pub fn parse_index_user_email(html: &str) -> Option<UserEmail> {
|
||||
let maybe_meta = scrape_user_email_via_regex(html);
|
||||
|
||||
if let Some(meta) = maybe_meta {
|
||||
return Some(UserEmail(meta))
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
fn scrape_user_email_via_regex(html: &str) -> Option<String> {
|
||||
let captures = JSON_REGEX.captures(html)?;
|
||||
let capture = captures.get(1)?;
|
||||
Some(capture.as_str().to_string())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::requests::index_page::get_index_page::{get_index, GetIndexPageArgs};
|
||||
use crate::requests::index_page::parsers::index::parse_index_user_email::parse_index_user_email;
|
||||
use crate::test_utils::get_test_cookies::get_test_cookies;
|
||||
use errors::AnyhowResult;
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore] // Manual test invocation
|
||||
async fn test() -> AnyhowResult<()> {
|
||||
let cookie = get_test_cookies()?;
|
||||
let index = get_index(GetIndexPageArgs {
|
||||
cookie: &cookie,
|
||||
}).await?;
|
||||
|
||||
let user_email = parse_index_user_email(&index.body);
|
||||
println!("User Email : {:?}", user_email);
|
||||
|
||||
assert_eq!(1, 2);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user