about summary refs log tree commit diff
path: root/corp/rih/src/main.rs
diff options
context:
space:
mode:
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() {