-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add experimental turnstile captcha & add timeout to recaptcha b…
…adge
- Loading branch information
1 parent
38ed5c3
commit 62f7ae0
Showing
4 changed files
with
86 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
javascript/tokenscript-viewer/src/integration/turnstileCaptcha.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
declare global { | ||
var turnstile: any; | ||
} | ||
|
||
const DEFAULT_SITE_KEY = "0x4AAAAAAA0Rmw6kZyekmiSB"; | ||
|
||
export async function getTurnstileToken(sitekey?: string){ | ||
|
||
return new Promise((resolve, reject) => { | ||
|
||
if (!sitekey) | ||
sitekey = DEFAULT_SITE_KEY; | ||
|
||
const elemId = `turnstile-${sitekey}`; | ||
let elem; | ||
|
||
try { | ||
let widgetId; | ||
//if (widgetIds[sitekey] === undefined){ | ||
if (!document.getElementById(elemId)) { | ||
elem = document.createElement("div"); | ||
elem.id = elemId; | ||
elem.classList.add("turnstile-widget"); | ||
document.body.getElementsByTagName("app-root")[0].append(elem); | ||
} | ||
widgetId = turnstile.render("#" + elemId, { | ||
sitekey, | ||
callback: function (token) { | ||
console.log(`Challenge Success ${token}`); | ||
resolve(token); | ||
turnstile.remove(widgetId); | ||
elem.remove(); | ||
}, | ||
'error-callback': function (error){ | ||
console.error("Turnstile error: ", error); | ||
turnstile.remove(widgetId); | ||
elem.remove(); | ||
reject(error); | ||
} | ||
}); | ||
//widgetIds[sitekey] = widgetId; | ||
/*} else { | ||
widgetId = widgetIds[sitekey]; | ||
}*/ | ||
} catch (e){ | ||
reject(e); | ||
if (elem) | ||
elem.remove(); | ||
} | ||
}) | ||
} |