Browse Source

refactor: Hide registration buttons and prevent opening register modal if registration is disabled

Owen Diffey 2 years ago
parent
commit
2e7ceab660

+ 1 - 0
.wiki/Configuration.md

@@ -74,6 +74,7 @@ Location: `frontend/dist/config/default.json`
 | `siteSettings.github` | URL of GitHub repository, defaults to `https://github.com/Musare/MusareNode`. |
 | `siteSettings.mediasession` | Whether to enable mediasession functionality. |
 | `siteSettings.christmas` | Whether to enable christmas theming. |
+| `siteSettings.registrationDisabled` | If set to true, users can't register accounts. |
 | `messages.accountRemoval` | Message to return to users on account removal. |
 | `shortcutOverrides` | Overwrite keyboard shortcuts, for example `"editSong.useAllDiscogs": { "keyCode": 68, "ctrl": true, "alt": true, "shift": false, "preventDefault": true }`. |
 | `debug.git.remote` | Allow the website/users to view the current Git repository's remote. [^1] |

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

@@ -24,7 +24,8 @@
 		"sitename": "Musare",
 		"github": "https://github.com/Musare/Musare",
 		"mediasession": false,
-		"christmas": false
+		"christmas": false,
+		"registrationDisabled": false
 	},
 	"messages": {
 		"accountRemoval": "Your account will be deactivated instantly and your data will shortly be deleted by an admin."
@@ -49,5 +50,5 @@
 		"version": true
 	},
 	"skipConfigVersionCheck": false,
-	"configVersion": 9
+	"configVersion": 10
 }

+ 8 - 2
frontend/src/components/layout/MainHeader.vue

@@ -63,7 +63,12 @@
 			</span>
 			<span v-if="!loggedIn && !hideLoggedOut" class="grouped">
 				<a class="nav-item" @click="openModal('login')">Login</a>
-				<a class="nav-item" @click="openModal('register')">Register</a>
+				<a
+					v-if="!siteSettings.registrationDisabled"
+					class="nav-item"
+					@click="openModal('register')"
+					>Register</a
+				>
 			</span>
 		</div>
 
@@ -98,7 +103,8 @@ export default {
 			siteSettings: {
 				logo: "",
 				sitename: "",
-				christmas: false
+				christmas: false,
+				registrationDisabled: false
 			},
 			windowWidth: 0
 		};

+ 9 - 2
frontend/src/components/modals/Login.vue

@@ -89,7 +89,10 @@
 					</a>
 				</div>
 
-				<p class="content-box-optional-helper">
+				<p
+					v-if="!registrationDisabled"
+					class="content-box-optional-helper"
+				>
 					<a @click="changeToRegisterModal()">
 						Don't have an account?
 					</a>
@@ -116,11 +119,15 @@ export default {
 				value: "",
 				visible: false
 			},
-			apiDomain: ""
+			apiDomain: "",
+			registrationDisabled: false
 		};
 	},
 	async mounted() {
 		this.apiDomain = await lofig.get("backend.apiDomain");
+		this.registrationDisabled = await lofig.get(
+			"siteSettings.registrationDisabled"
+		);
 	},
 	methods: {
 		checkForAutofill(event) {

+ 12 - 1
frontend/src/components/modals/Register.vue

@@ -171,7 +171,8 @@ export default {
 				token: "",
 				enabled: false
 			},
-			apiDomain: ""
+			apiDomain: "",
+			registrationDisabled: false
 		};
 	},
 	watch: {
@@ -230,6 +231,16 @@ export default {
 	async mounted() {
 		this.apiDomain = await lofig.get("backend.apiDomain");
 
+		lofig
+			.get("siteSettings.registrationDisabled")
+			.then(registrationDisabled => {
+				this.registrationDisabled = registrationDisabled;
+				if (registrationDisabled) {
+					new Toast("Registration is disabled.");
+					this.closeModal("register");
+				}
+			});
+
 		lofig.get("recaptcha").then(obj => {
 			this.recaptcha.enabled = obj.enabled;
 			if (obj.enabled === true) {

+ 1 - 1
frontend/src/main.js

@@ -11,7 +11,7 @@ import store from "./store";
 
 import AppComponent from "./App.vue";
 
-const REQUIRED_CONFIG_VERSION = 9;
+const REQUIRED_CONFIG_VERSION = 10;
 
 const handleMetadata = attrs => {
 	document.title = `Musare | ${attrs.title}`;

+ 7 - 3
frontend/src/pages/Home.vue

@@ -15,7 +15,7 @@
 						<img
 							class="logo"
 							src="/assets/white_wordmark.png"
-							:alt="`${this.sitename}` || `Musare`"
+							:alt="`${this.siteSettings.sitename}` || `Musare`"
 						/>
 						<div v-if="!loggedIn" class="buttons">
 							<button
@@ -25,6 +25,7 @@
 								Login
 							</button>
 							<button
+								v-if="!siteSettings.registrationDisabled"
 								class="button register"
 								@click="openModal('register')"
 							>
@@ -536,7 +537,10 @@ export default {
 			stations: [],
 			favoriteStations: [],
 			searchQuery: "",
-			sitename: "Musare",
+			siteSettings: {
+				sitename: "Musare",
+				registrationDisabled: false
+			},
 			orderOfFavoriteStations: [],
 			handledLoginRegisterRedirect: false,
 			editingStationId: null
@@ -591,7 +595,7 @@ export default {
 		}
 	},
 	async mounted() {
-		this.sitename = await lofig.get("siteSettings.sitename");
+		this.siteSettings = await lofig.get("siteSettings");
 
 		if (
 			!this.loggedIn &&