From 6f0ddbac06a9a72908b8b0b955cd743d3ae82378 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Fri, 2 Jun 2023 12:48:52 +0300 Subject: feat(corp/rih): display & load captcha element inside the form Change-Id: Ifd0f85d9e4f785c4cb1ae56ae67e6d999ff43c85 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8694 Tested-by: BuildkiteCI Reviewed-by: tazjin --- corp/rih/Cargo.lock | 1 + corp/rih/Cargo.toml | 5 +++-- corp/rih/index.html | 5 +++-- corp/rih/src/home.html | 14 ++++++++++++++ corp/rih/src/main.rs | 21 ++++++++++++++++++--- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/corp/rih/Cargo.lock b/corp/rih/Cargo.lock index 3ed11c4ef221..7e472e5fe158 100644 --- a/corp/rih/Cargo.lock +++ b/corp/rih/Cargo.lock @@ -1085,6 +1085,7 @@ dependencies = [ "fuzzy-matcher", "getrandom", "gloo", + "js-sys", "rand", "rust_iso3166", "serde", diff --git a/corp/rih/Cargo.toml b/corp/rih/Cargo.toml index 16221b7a55c8..2dd8cb7b97ad 100644 --- a/corp/rih/Cargo.toml +++ b/corp/rih/Cargo.toml @@ -7,14 +7,15 @@ edition = "2021" [dependencies] fuzzy-matcher = "0.3.7" +getrandom = { version = "0.2", features = ["js"] } gloo = "0.8" +js-sys = "0.3" +rand = "0.8" rust_iso3166 = "0.1.10" serde_json = "1.0" serde_urlencoded = "*" # pinned by yew yew = { version = "0.20", features = ["csr"] } yew-router = "0.17" -rand = "0.8" -getrandom = { version = "0.2", features = ["js"] } # needs to be in sync with nixpkgs wasm-bindgen = "= 0.2.84" diff --git a/corp/rih/index.html b/corp/rih/index.html index b7d1803f1139..4f0f8f36041d 100644 --- a/corp/rih/index.html +++ b/corp/rih/index.html @@ -11,7 +11,8 @@ + + + - - diff --git a/corp/rih/src/home.html b/corp/rih/src/home.html index 7f2614497949..95a77877d317 100644 --- a/corp/rih/src/home.html +++ b/corp/rih/src/home.html @@ -1,5 +1,17 @@ html! {
+ +
@@ -156,6 +168,8 @@ html! {
{"Any specific places where you'd like to live? Would you be moving with family? Any other assistance required?"}
+
+

{"This page is still under construction! Please reach out at contact@ if you have any questions."}

diff --git a/corp/rih/src/main.rs b/corp/rih/src/main.rs index 7360a6979d76..2fed9dfd8f4a 100644 --- a/corp/rih/src/main.rs +++ b/corp/rih/src/main.rs @@ -1,8 +1,7 @@ use fuzzy_matcher::skim::SkimMatcherV2; use fuzzy_matcher::FuzzyMatcher; use gloo::console; -use gloo::history::BrowserHistory; -use gloo::history::History; +use gloo::history::{BrowserHistory, History}; use gloo::storage::{LocalStorage, Storage}; use rand::seq::IteratorRandom; use rand::thread_rng; @@ -10,12 +9,21 @@ use serde::{Deserialize, Serialize}; use static_markdown::markdown; use std::collections::BTreeSet; use wasm_bindgen::closure::Closure; -use wasm_bindgen::JsCast; +use wasm_bindgen::{JsCast, JsValue}; use web_sys::{HtmlInputElement, HtmlTextAreaElement, KeyboardEvent}; use yew::html::Scope; use yew::prelude::*; use yew_router::prelude::*; +/// Form submission is protected with a captcha. The development +/// version of the captcha does not do domain checking and works on +/// `localhost` as well. +#[cfg(debug_assertions)] +const CAPTCHA_KEY: &'static str = "ysc1_K7iOi3FSmsyO8pZGu8Im2iQClCtPsVx7jSRyhyCV435a732c"; + +#[cfg(not(debug_assertions))] +const CAPTCHA_KEY: &'static str = "ysc1_a3LVlaDRDMwU8CLSZ0WKENTI2exyOxz5J2c6x28P5339d410"; + /// This code ends up being compiled for the native and for the /// webassembly architectures during the build & test process. /// However, the `rust_iso3166` crate exposes a different API (!) @@ -388,6 +396,13 @@ impl Component for App { Route::NotFound => todo!(), } } + + fn rendered(&mut self, _: &Context, first_render: bool) { + if first_render { + let func = js_sys::Function::new_with_args("key", "captchaOnload(key)"); + let _ = func.call1(&JsValue::NULL, &JsValue::from_str(CAPTCHA_KEY)); + } + } } fn main() { -- cgit 1.4.1