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
This commit is contained in:
parent
d5f13d63e1
commit
f4826c5ca9
19
src/main.rs
19
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<Ownership> = 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;
|
||||
} 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<Ownership>
|
||||
failed_owner_reg: bool,
|
||||
ownerships: Vec<Ownership>,
|
||||
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()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,19 +36,27 @@
|
|||
</nav>
|
||||
|
||||
<div id="body" class="p-5">
|
||||
<h3>Your Client ID: {{client_id}}</h3>
|
||||
<p>
|
||||
<h5>
|
||||
Your Client ID:
|
||||
</h5>
|
||||
<button id="client_id" class="border-0 bg-transparent" onclick="copy_content(event)" data-bs-toggle="tooltip"
|
||||
data-bs-title="Click To Copy">
|
||||
{{client_id}}
|
||||
</button>
|
||||
</p>
|
||||
<p>
|
||||
<h5>
|
||||
Registration Link:
|
||||
</h5>
|
||||
<button id="reg_link" class="border-0 bg-transparent" onclick="copy_content(event)" data-bs-toggle="tooltip"
|
||||
data-bs-title="Click To Copy">
|
||||
{{host}}/ownership_registration?owner_id=937b0f08-a3af-457b-b65e-4ed858517588
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<form target="/owner_registration">
|
||||
<h5>Ownership Registration</h5>
|
||||
<input type="text" name="owner_id">
|
||||
</form>
|
||||
|
||||
{{#if disp_owner_reg}}
|
||||
<p>Registered new owner {{owner_id}} for {{client_id}}</p>
|
||||
{{/if}}
|
||||
|
||||
<h3>Owned Clients</h3>
|
||||
<table>
|
||||
<h5>Owned Clients</h5>
|
||||
<table class="table table-striped m-1">
|
||||
<tr>
|
||||
<th>Client ID</th>
|
||||
</tr>
|
||||
|
|
@ -60,10 +68,82 @@
|
|||
</tr>
|
||||
{{/each}}
|
||||
</table>
|
||||
|
||||
<form action="/ownership_registration" method="get">
|
||||
<h5>Ownership Registration</h5>
|
||||
<div class="p-1">
|
||||
<h6>Instructions:</h6>
|
||||
<p>
|
||||
Copy the Client ID from the browser you'd like to see your requests. Paste it into the Owner ID Form and
|
||||
submit.
|
||||
</p>
|
||||
<p>
|
||||
This will allow the other client to access any requests you've made in the history page.
|
||||
</p>
|
||||
<p>
|
||||
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.
|
||||
</p>
|
||||
</div>
|
||||
<div class="mb-3 ms-1 me-1">
|
||||
<label for="owner_id" class="form-label">Owner ID</label>
|
||||
<input class="form-control" type="text" name="owner_id">
|
||||
</div>
|
||||
<div class="">
|
||||
<button type="submit" class="btn btn-primary mb-3">Submit</button>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
{{#if disp_owner_reg}}
|
||||
<p>Registered new owner {{owner_id}} for {{client_id}}</p>
|
||||
{{/if}}
|
||||
|
||||
{{#if failed_owner_reg}}
|
||||
<p>Failed to register {{owner_id}} for {{client_id}}.</p>
|
||||
<p>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.</p>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
||||
<div class="toast-container position-fixed bottom-0 end-0 p-3">
|
||||
<div id="clipboard_toast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
|
||||
<div class="toast-header">
|
||||
<svg class="bd-placeholder-img rounded me-2" width="20" height="20" xmlns="http://www.w3.org/2000/svg"
|
||||
aria-hidden="true" preserveAspectRatio="xMidYMid slice" focusable="false">
|
||||
<rect width="100%" height="100%" fill="#007aff"></rect>
|
||||
</svg>
|
||||
<strong class="me-auto">Clipboard</strong>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="toast-body">
|
||||
Copied to Clipboard.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
<script>
|
||||
function copy_content(event) {
|
||||
// Get the text field
|
||||
var copyText = document.getElementById(event.target.id);
|
||||
|
||||
// Copy the text inside the text field
|
||||
navigator.clipboard.writeText(copyText.innerText);
|
||||
|
||||
const toastLiveExample = document.getElementById('clipboard_toast')
|
||||
|
||||
const toastBootstrap = bootstrap.Toast.getOrCreateInstance(toastLiveExample)
|
||||
toastBootstrap.show()
|
||||
}
|
||||
|
||||
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]');
|
||||
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl));
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Loading…
Reference in New Issue