From f4826c5ca9cf78ee1919237192d8ba014ed67d8a Mon Sep 17 00:00:00 2001 From: RaspberryProgramming Date: Fri, 19 Jul 2024 14:57:49 +0000 Subject: [PATCH] Ownership Registration - New functionality added ability to copy client id to clipboard by clicking Fixed submit bug where it would open a new page. Added link to copy and allow remote clients to submit ownership registration. This can be done with things such as curl or other cli tools that can't visually see the html form on this page --- src/main.rs | 25 ++++-- templates/ownership_registration.html.hbs | 104 +++++++++++++++++++--- 2 files changed, 110 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 57d953a..c34b5d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -409,26 +409,33 @@ fn history_details(history_id: i64, _info: RequestInfo, cookies: &CookieJar<'_>) #[get("/ownership_registration")] fn ownership_registration(info: RequestInfo, cookies: &CookieJar<'_>) -> Template { + let host_pair = info.header.iter().find(|&h| h.key == "host").unwrap(); let client_id = get_cookie("mirror-id", cookies); let owner_id_pair = info.find_query_key("owner_id"); let mut disp_owner_reg = false; + let mut failed_owner_reg = false; let re = Regex::new(r"^[{]?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}[}]?$").unwrap(); let connection: &mut PgConnection = &mut establish_connection(); let ownerships: Vec = get_ownerships(&client_id, connection); let owner_id = match owner_id_pair { - Some(v) => v.value.to_string(), + Some(v) => v.value.trim().to_string(), None => "".to_string() }; if - owner_id_pair.is_some() && + owner_id_pair.is_some() + { + if re.is_match(&owner_id) && owner_id != client_id && !ownership_exists(&client_id, &owner_id, connection) - { - create_owner_record(connection, owner_id.clone(), client_id.clone()); - disp_owner_reg = true; + { + create_owner_record(connection, owner_id.clone(), client_id.clone()); + disp_owner_reg = true; + } else { + failed_owner_reg = true; + } } #[derive(Serialize)] @@ -436,14 +443,18 @@ fn ownership_registration(info: RequestInfo, cookies: &CookieJar<'_>) -> Templat client_id: String, owner_id: String, disp_owner_reg: bool, - ownerships: Vec + failed_owner_reg: bool, + ownerships: Vec, + host: String } Template::render("ownership_registration", Context { client_id, owner_id, disp_owner_reg, - ownerships + failed_owner_reg, + ownerships, + host: host_pair.value.to_string() }) } diff --git a/templates/ownership_registration.html.hbs b/templates/ownership_registration.html.hbs index 621bf35..4fe71c1 100644 --- a/templates/ownership_registration.html.hbs +++ b/templates/ownership_registration.html.hbs @@ -36,19 +36,27 @@
-

Your Client ID: {{client_id}}

+

+

+ Your Client ID: +
+ +

+

+

+ Registration Link: +
+ +

-
-
Ownership Registration
- -
- - {{#if disp_owner_reg}} -

Registered new owner {{owner_id}} for {{client_id}}

- {{/if}} - -

Owned Clients

- +
Owned Clients
+
@@ -60,10 +68,82 @@ {{/each}}
Client ID
+ +
+
Ownership Registration
+
+
Instructions:
+

+ Copy the Client ID from the browser you'd like to see your requests. Paste it into the Owner ID Form and + submit. +

+

+ This will allow the other client to access any requests you've made in the history page. +

+

+ If you'd like to register a new owner on a client that doesn't have access to this html form, you can make the + request directly + by making an http/https request to the registration link above. Click it to copy to your clipboard. +

+
+
+ + +
+
+ +
+ +
+ + {{#if disp_owner_reg}} +

Registered new owner {{owner_id}} for {{client_id}}

+ {{/if}} + + {{#if failed_owner_reg}} +

Failed to register {{owner_id}} for {{client_id}}.

+

This may have ocurred because the owner_id does not exist, is already registered as an owner, or that it is the same as the client_id.

+ {{/if}}
+ +
+ +
+ + + \ No newline at end of file