Browse Source

Added option to disable recaptcha

Kristian Vos 3 years ago
parent
commit
341c84260a

+ 3 - 0
README.md

@@ -47,8 +47,10 @@ We currently only utilize 1 backend, 1 MongoDB server and 1 Redis server running
     | `serverPort` | Should be the port where the backend will listen on, should always be `8080` for Docker, and is recommended for non-Docker. |
     | `isDocker` | Self-explanatory. Are you using Docker? |
     | `serverPort` | Should be the port where the backend will listen on, should always be `8080` for Docker, and is recommended for non-Docker. |
+    | `registrationDisabled` | If set to true, users can't register accounts. |
     | `apis.youtube.key`            | Can be obtained by setting up a [YouTube API Key](https://developers.google.com/youtube/v3/getting-started). You need to use the YouTube Data API v3, and create an API key. |
     | `apis.recaptcha.secret`       | Can be obtained by setting up a [ReCaptcha Site (v3)](https://www.google.com/recaptcha/admin). |
+    | `apis.recaptcha.enabled`       | Keep at false to keep disabled. |
     | `apis.github` | Can be obtained by setting up a [GitHub OAuth Application](https://github.com/settings/developers). You need to fill in some values to create the OAuth application. The homepage is the homepage of frontend. The authorization callback url is the backend url with `/auth/github/authorize/callback` added at the end. For example `http://localhost:8080/auth/github/authorize/callback`. |
     | `apis.discord.token` | Token for the Discord bot. |
     | `apis.discord.loggingServer`  | Server ID of the Discord logging server. |
@@ -70,6 +72,7 @@ We currently only utilize 1 backend, 1 MongoDB server and 1 Redis server running
     | `frontendDomain` | Should be the url where the frontend will be accessible from, usually `http://localhost` for docker or `http://localhost:80` for non-Docker. |
     | `frontendPort` | Should be the port where the frontend will be accessible from, should always be port `81` for Docker, and is recommended to be port `80` for non-Docker. |
     | `recaptcha.key` | Can be obtained by setting up a [ReCaptcha Site (v3)](https://www.google.com/recaptcha/admin). |
+    | `recaptcha.enabled` | Keep at false to keep disabled. |
     | `cookie.domain` | Should be the ip or address you use to access the site, without protocols (http/https), so for example `localhost`. |
     | `cookie.secure` | Should be `true` for SSL connections, and `false` for normal http connections. |
     | `siteSettings.logo` | Path to the logo image, by default it is `/assets/wordmark.png`. |

+ 2 - 1
backend/config/template.json

@@ -13,7 +13,8 @@
 			"key": ""
 		},
 		"recaptcha": {
-			"secret": ""
+			"secret": "",
+			"enabled": false
 		},
 		"github": {
 			"client": "",

+ 21 - 17
backend/logic/actions/users.js

@@ -328,7 +328,6 @@ module.exports = {
                     return next();
                 },
 
-                // verify the request with google recaptcha
                 (next) => {
                     if (!db.passwordValid(password))
                         return next(
@@ -337,29 +336,34 @@ module.exports = {
                     return next();
                 },
 
+                // verify the request with google recaptcha
                 (next) => {
-                    request(
-                        {
-                            url:
-                                "https://www.google.com/recaptcha/api/siteverify",
-                            method: "POST",
-                            form: {
-                                secret: config.get("apis").recaptcha.secret,
-                                response: recaptcha,
+                    if (config.get("apis.recaptcha.enabled") === true)
+                        request(
+                            {
+                                url:
+                                    "https://www.google.com/recaptcha/api/siteverify",
+                                method: "POST",
+                                form: {
+                                    secret: config.get("apis").recaptcha.secret,
+                                    response: recaptcha,
+                                },
                             },
-                        },
-                        next
-                    );
+                            next
+                        );
+                    else next(null, null, null);
                 },
 
                 // check if the response from Google recaptcha is successful
                 // if it is, we check if a user with the requested username already exists
                 (response, body, next) => {
-                    let json = JSON.parse(body);
-                    if (json.success !== true)
-                        return next(
-                            "Response from recaptcha was not successful."
-                        );
+                    if (config.get("apis.recaptcha.enabled") === true) {
+                        let json = JSON.parse(body);
+                        if (json.success !== true)
+                            return next(
+                                "Response from recaptcha was not successful."
+                            );
+                    }
                     userModel.findOne(
                         { username: new RegExp(`^${username}$`, "i") },
                         next

+ 21 - 17
frontend/components/Modals/Register.vue

@@ -138,7 +138,8 @@ export default {
 			},
 			recaptcha: {
 				key: "",
-				token: ""
+				token: "",
+				enabled: false
 			},
 			serverDomain: ""
 		};
@@ -198,24 +199,27 @@ export default {
 		});
 
 		lofig.get("recaptcha").then(obj => {
-			this.recaptcha.key = obj.key;
+			this.recaptcha.enabled = obj.enabled;
+			if (obj.enabled === true) {
+				this.recaptcha.key = obj.key;
 
-			const recaptchaScript = document.createElement("script");
-			recaptchaScript.onload = () => {
-				grecaptcha.ready(() => {
-					grecaptcha
-						.execute(this.recaptcha.key, { action: "login" })
-						.then(token => {
-							this.recaptcha.token = token;
-						});
-				});
-			};
+				const recaptchaScript = document.createElement("script");
+				recaptchaScript.onload = () => {
+					grecaptcha.ready(() => {
+						grecaptcha
+							.execute(this.recaptcha.key, { action: "login" })
+							.then(token => {
+								this.recaptcha.token = token;
+							});
+					});
+				};
 
-			recaptchaScript.setAttribute(
-				"src",
-				`https://www.google.com/recaptcha/api.js?render=${this.recaptcha.key}`
-			);
-			document.head.appendChild(recaptchaScript);
+				recaptchaScript.setAttribute(
+					"src",
+					`https://www.google.com/recaptcha/api.js?render=${this.recaptcha.key}`
+				);
+				document.head.appendChild(recaptchaScript);
+			}
 		});
 	},
 	methods: {

+ 2 - 1
frontend/dist/config/template.json

@@ -1,6 +1,7 @@
 {
 	"recaptcha": {
-		"key": ""
+		"key": "",
+		"enabled": false
 	},
 	"serverDomain": "http://localhost:8080",
 	"frontendDomain": "http://localhost",

+ 5 - 1
frontend/store/modules/modals.js

@@ -32,7 +32,11 @@ const getters = {};
 
 const actions = {
 	closeModal: ({ commit }, data) => {
-		if (data.modal === "register") window.location.reload();
+		if (data.modal === "register") {
+			lofig.get("recaptcha.enabled").then(recaptchaEnabled => {
+				if (recaptchaEnabled) window.location.reload();
+			});
+		}
 		commit("closeModal", data);
 	},
 	openModal: ({ commit }, data) => {