on master help sign in
captcha
commitb5b21d6599cb699592403a7f2f7e0d5736e2aadf authoriko <ilyakooo0@gmail.com> dateMon 1 Aug 2022, 17:58 (4 years ago) parenta1214e1
5 files changed+37
backend/Data/HCaptcha.js+10 backend/Data/HCaptcha.purs+6 backend/Main.purs+2 frontend/Pages/Login.elm+1 packages.dhall+18
backend/Data/HCaptcha.jsnew file+10
@@ -0,0 +1,10 @@
1+export function bindHCaptchToken(callback) {
2+ return () => {
3+ window.addEventListener("message", (e) => {
4+ if (typeof e.data === 'object' && "hCaptchaToken" in e.data) {
5+ callback(e.data.hCaptchaToken)();
6+ }
7+ })
8+
9+ }
10+}
backend/Data/HCaptcha.pursnew file+6
@@ -0,0 +1,6 @@
1+module Data.HCaptcha where
2+
3+import Prelude
4+import Effect (Effect)
5+
6+foreign import bindHCaptchToken :: (String -> Effect Unit) -> Effect Unit
backend/Main.purs+2
@@ -18,6 +18,7 @@ import Data.Array as Array
1818import Data.Clipboard as Clipboard
1919import Data.DateTime (DateTime)
2020import Data.Either (Either(..))
21+import Data.HCaptcha (bindHCaptchToken)
2122import Data.JNullable (fromJNullable, jnull, nullify)
2223import Data.JNullable as JNullable
2324import Data.JOpt (fromJOpt)
@@ -50,6 +51,7 @@ main = do
5051 storage <- Html.window >>= Window.localStorage
5152 services <- WB.getServices
5253 masterKeyRef <- Ref.new Nothing
54+ bindHCaptchToken log
5355 let run act = do
5456 maybeKey <- Ref.read masterKeyRef
5557 runElmAff app $ flip runReaderT {app: app, crypto : services.crypto, storage: storage} $
frontend/Pages/Login.elm+1
@@ -94,6 +94,7 @@ view model =
9494 , Attr.attribute "autocomplete" "current-password"
9595 ]
9696 []
97+ , iframe [ Attr.src "https://iko.soy/warden/hcaptcha.html" ] []
9798 , alignRight [ button [ Attr.type_ "submit" ] [ text "Log in" ] ]
9899 ]
99100 ]
packages.dhall+18
@@ -128,3 +128,21 @@ in upstream
128128 "https://github.com/ilyakooo0/purescript-argonaut-aeson-generic.git"
129129 , version = "purescript-0.14"
130130 }
131+ with untagged-union =
132+ { dependencies =
133+ [ "assert"
134+ , "console"
135+ , "effect"
136+ , "either"
137+ , "foreign"
138+ , "foreign-object"
139+ , "literals"
140+ , "maybe"
141+ , "newtype"
142+ , "prelude"
143+ , "tuples"
144+ , "unsafe-coerce"
145+ ]
146+ , repo = "https://github.com/ilyakooo0/purescript-untagged-union.git"
147+ , version = "ps-15"
148+ }