Verified Commit afcadc77 authored by Rigel Kent's avatar Rigel Kent
Browse files

mtcaptcha init

parents
node_modules
.cache
dist
LICENSE
\ No newline at end of file
This diff is collapsed.
# MTCaptcha
PeerTube plugin adding MTCaptcha to the signup
## Read First
This plugin is NOT supported by Framasoft, nor any organisation.
![](http://lutim.cpy.re/BesALGBX.png)
.g-recaptcha {
margin-bottom: 2rem;
}
\ No newline at end of file
import loadjs from "loadjs"
function register({ registerHook, peertubeHelpers }) {
initMTC(registerHook, peertubeHelpers).catch(err =>
console.error("Cannot initialize mtcaptcha plugin", err)
)
}
export { register }
function initMTC(registerHook, peertubeHelpers) {
return peertubeHelpers.getSettings().then(async s => {
if (!s || !s["mtcaptcha-site-key"]) {
console.error(
"MTCaptcha plugin lacks a site key set to use the MTCaptcha. Falling back to normal registration."
)
return
}
// add captcha to the first form (user form)
const node = document.getElementsByTagName("form")[0]
const div = document.createElement("div")
div.setAttribute("class", "mtcaptcha")
node.appendChild(div)
window.mtcaptchaConfig = {
"sitekey": s["mtcaptcha-site-key"],
"render": "auto",
"customStyle": {
"cardColor": "#f5f5f5",
"cardBorder": "#9EA1A0",
"placeHolderColor": "#F89300",
"inputTextColor": "#F87800",
"inputBackgroundColor": "#fafafa",
"inputBorderColor": {
"byDefault": "#F89300",
"hover": "#f07000",
"active": "#f07000"
},
"buttonIconColor": {
"refresh": "#dddddd",
"verify": "#55caf1",
"audio": "#F89300",
"audiofocus": "#f07000"
}
},
"verified-callback": state => window.MTCaptchaLoadCallbackResponse = state.verifiedToken,
"renderQueue": []
}
loadjs([
"https://service.mtcaptcha.com/mtcv1/client/mtcaptcha.min.js",
"https://service2.mtcaptcha.com/mtcv1/client/mtcaptcha2.min.js",
])
registerHook({
target: "filter:api.signup.registration.create.params",
handler: body =>
Object.assign({}, body, {
"mtcaptcha-response": window.MTCaptchaLoadCallbackResponse
})
})
})
}
const get = require("simple-get")
async function register({
registerHook,
registerSetting,
settingsManager
}) {
// see https://www.mtcaptcha.com/dev-guide-quickstart
registerSetting({
name: 'mtcaptcha-site-key',
label: 'MTCaptcha Site Key',
type: 'input',
private: false
})
registerSetting({
name: 'mtcaptcha-secret-key',
label: 'MTCaptcha Secret Key',
type: 'input',
private: true
})
registerHook({
target: "filter:api.user.signup.allowed.result",
handler: (result, params) => verifyCaptcha(result, params, settingsManager)
})
}
async function unregister() {
return
}
module.exports = {
register,
unregister
}
async function verifyCaptcha (result, params, settingsManager) {
// mtcaptcha-response is the key that browser will generate upon form submit.
// if its blank or null means user has not selected the captcha, so return the error.
if (!params.body["mtcaptcha-response"]) {
return { allowed: false, errorMessage: "Captcha wasn't filled" }
}
const secretKey = await settingsManager.getSetting('mtcaptcha-secret-key')
if (!secretKey) return result
// params.connection.remoteAddress will provide IP address of connected user.
const verificationUrl =
"https://service.mtcaptcha.com/mtcv1/api/checktoken?privateKey=" +
secretKey +
"&token=" +
params.body["g-recaptcha-response"]
return get(verificationUrl, function (err, res, body) {
body = JSON.parse(body)
if (body.success !== undefined && !body.success) {
return { allowed: false, errorMessage: "Wrong captcha" }
}
return result
})
}
This diff is collapsed.
{
"name": "peertube-plugin-mtcaptcha",
"description": "PeerTube plugin adding MTCaptcha to the signup",
"version": "0.0.1",
"author": "Rigel Kent",
"bugs": "https://framagit.org/rigelk/eertube-plugin-mtcaptcha/issues",
"clientScripts": [
{
"script": "dist/signup-client-plugin.js",
"scopes": [
"signup"
]
}
],
"css": [
"assets/style.css"
],
"dependencies": {
"loadjs": "^4.0.1",
"simple-get": "^3.1.0"
},
"devDependencies": {
"@purtuga/esm-webpack-plugin": "^1.1.1",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10"
},
"engine": {
"peertube": ">=2.1.0"
},
"homepage": "https://framagit.org/rigelk/peertube-plugin-mtcaptcha",
"keywords": [
"peertube",
"plugin",
"captcha"
],
"library": "./main.js",
"license": "AGPL-3.0-or-later",
"repository": "https://framagit.org/rigelk/peertube-plugin-mtcaptcha",
"scripts": {
"build": "webpack --mode=production"
},
"staticDirs": {},
"translations": {}
}
const path = require("path")
const EsmWebpackPlugin = require("@purtuga/esm-webpack-plugin")
let config = {
entry: "./client/signup-client-plugin.js",
output: {
path: path.resolve(__dirname, "./dist"),
filename: "./signup-client-plugin.js",
library: "script",
libraryTarget: "var"
},
plugins: [new EsmWebpackPlugin()]
}
module.exports = config
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment