about summary refs log tree commit diff
path: root/corp/rih/src/main.rs
diff options
context:
space:
mode:
authorVincent Ambo <mail@tazj.in>2023-06-02T09·48+0300
committertazjin <tazjin@tvl.su>2023-06-06T11·43+0000
commit6f0ddbac06a9a72908b8b0b955cd743d3ae82378 (patch)
tree9092b069b2c07ff037e3dc3d839b2e50d2b81fe1 /corp/rih/src/main.rs
parentb2ff63586acbdcd8e1c8159cac2c09724306eda6 (diff)
feat(corp/rih): display & load captcha element inside the form r/6233
Change-Id: Ifd0f85d9e4f785c4cb1ae56ae67e6d999ff43c85
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8694
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Diffstat (limited to 'corp/rih/src/main.rs')
-rw-r--r--corp/rih/src/main.rs21
1 files changed, 18 insertions, 3 deletions
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<Self>, 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() {