diff --git a/dist/assets/js/upload-verify.js b/dist/assets/js/upload-verify.js new file mode 100644 index 0000000..0617c8e --- /dev/null +++ b/dist/assets/js/upload-verify.js @@ -0,0 +1,34 @@ +const container = document.getElementById("container"); +const postform = document.getElementById("postform"); +const pleasewait = document.getElementById("pleasewait"); +const failed = document.getElementById("failed"); +const form = document.getElementById("postform"); +const url = form.getAttribute("action"); + +fetch(url, { method: "POST" }) + .then(result => result.text()) + .then(body => { + const frag = document.createElement("div"); + frag.innerHTML = body; + container.appendChild(frag); + const result = document.getElementById("verification-result"); + if (result !== null) { + while (result.firstChild) { + container.appendChild(result.firstChild); + } + container.removeChild(frag); + } else { + // Leave the full content appended since it'll likely be plain text + } + // Hide the pleasewait too + pleasewait.style.display = "none"; + }) + .catch(err => { + // On error, hide the 'please wait' and show the 'Something went wrong' + pleasewait.style.display = "none"; + failed.textContent = failed.textContent + err; + failed.style.display = "block"; + }); +// Hide the form and display the 'please wait' block +postform.style.display = "none"; +pleasewait.style.display = "block"; diff --git a/dist/templates/upload/publish-result.html.hbs b/dist/templates/upload/publish-result.html.hbs index 4ac130d..b2da52b 100644 --- a/dist/templates/upload/publish-result.html.hbs +++ b/dist/templates/upload/publish-result.html.hbs @@ -1,5 +1,5 @@ {{#> layout}} -
+
{{#if verified }}

Your key diff --git a/dist/templates/upload/verification-form.html.hbs b/dist/templates/upload/verification-form.html.hbs new file mode 100644 index 0000000..731a91b --- /dev/null +++ b/dist/templates/upload/verification-form.html.hbs @@ -0,0 +1,18 @@ +{{#> layout}} +

+
+

+ Please click here to complete the verification process: + +

+
+ + +
+ + +{{/layout}} diff --git a/src/web/mod.rs b/src/web/mod.rs index 373d52b..0bb4d8b 100644 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -364,6 +364,7 @@ fn rocket_factory(mut rocket: rocket::Rocket) -> Result { vks_web::request_verify_form, vks_web::request_verify_form_data, vks_web::verify_confirm, + vks_web::verify_confirm_form, vks_web::quick_upload, vks_web::quick_upload_proceed, // Debug @@ -1095,7 +1096,7 @@ pub mod tests { let pattern = format!("{}(/verify/[^ \t\n]*)", BASE_URI); let confirm_uri = pop_mail_capture_pattern(filemail_path, &pattern); - let response = client.get(&confirm_uri).dispatch(); + let response = client.post(&confirm_uri).dispatch(); assert_eq!(response.status(), Status::Ok); } diff --git a/src/web/vks_web.rs b/src/web/vks_web.rs index 2bc404a..859a470 100644 --- a/src/web/vks_web.rs +++ b/src/web/vks_web.rs @@ -37,6 +37,11 @@ mod forms { } mod template { + #[derive(Serialize)] + pub struct VerifyForm { + pub token: String, + } + #[derive(Serialize)] pub struct Verify { pub verified: bool, @@ -437,7 +442,7 @@ pub fn request_verify_form_data( MyResponse::upload_response(result) } -#[get("/verify/")] +#[post("/verify/")] pub fn verify_confirm( db: rocket::State, token_service: rocket::State, @@ -461,3 +466,11 @@ pub fn verify_confirm( } } +#[get("/verify/")] +pub fn verify_confirm_form( + token: String, +) -> MyResponse { + MyResponse::ok("upload/verification-form", template::VerifyForm { + token + }) +} \ No newline at end of file