瀏覽代碼

Add admin account creation via token functionality

sbkwgh 8 年之前
父節點
當前提交
09505c9422
共有 4 個文件被更改,包括 28 次插入6 次删除
  1. 16 5
      src/App.vue
  2. 1 1
      src/components/AdminNewAdmin.vue
  3. 6 0
      src/components/routes/Index.vue
  4. 5 0
      src/store/index.js

+ 16 - 5
src/App.vue

@@ -9,7 +9,10 @@
 		<modal-window v-model='showAccountModal'>
 			<tab-view :tabs='["Sign up", "Login"]' v-model="showAccountTab" padding='true'>
 				<template slot='Sign up'>
-					<p style='margin-top: 0;'>
+					<p style='margin-top: 0;' v-if='$store.state.token'>
+						<strong>Providing the token is still valid, this will create an admin account</strong>
+					</p>
+					<p style='margin-top: 0;' v-else>
 						Sign up to create and post in threads.
 						<br/>It only takes a few seconds
 					</p>
@@ -220,6 +223,8 @@
 				this.signup.username = ''
 				this.signup.password = ''
 				this.signup.confirmPassword = ''
+
+				this.$store.commit('setToken', null)
 			},
 			clearSignupErrors () {
 				this.signup.errors.username = ''
@@ -244,15 +249,21 @@
 			createAccount () {
 				this.clearSignupErrors()
 
+				let postParams = {
+					username: this.signup.username,
+					password: this.signup.password
+				}
+				if(this.$store.state.token) {
+					postParams.admin = true
+					postParams.token = this.$store.state.token
+				}
+
 				if(this.signup.password !== this.signup.confirmPassword) {
 					this.signup.errors.confirmPassword = 'Passwords must match'
 				} else {
 					this.signup.loading = true
 
-					this.axios.post('/api/v1/user', {
-						username: this.signup.username,
-						password: this.signup.password
-					}).then(res => {
+					this.axios.post('/api/v1/user', postParams).then(res => {
 						this.signup.loading = false
 						this.$store.commit('setUsername', res.data.username)
 						this.$store.commit('setAdmin', res.data.admin)

+ 1 - 1
src/components/AdminNewAdmin.vue

@@ -44,7 +44,7 @@
 				this.axios
 					.post('/api/v1/admin_token')
 					.then(res => {
-						this.link = window.location.origin + '/newaccount?token=' + res.data.token
+						this.link = window.location.origin + '/?token=' + res.data.token
 						this.toggleModal()
 					})
 					.catch(AjaxErrorHandler(this.$store))

+ 6 - 0
src/components/routes/Index.vue

@@ -207,6 +207,12 @@
 					this.newThreads++
 				}
 			})
+
+			if(this.$route.query.token) {
+				this.$store.commit('setToken', this.$route.query.token)
+				this.$store.commit('setAccountTabs', 0)
+				this.$store.commit('setAccountModalState', true)
+			}
 		},
 		destroyed () {
 			socket.emit('leave', 'index')

+ 5 - 0
src/store/index.js

@@ -21,6 +21,8 @@ export default new Vuex.Store({
 		username: '',
 		admin: false,
 
+		token: null,
+
 		ajaxErrors: [],
 		ajaxErrorsModal: false
 	},
@@ -66,6 +68,9 @@ export default new Vuex.Store({
 		}
 	},
 	mutations: {
+		setToken (state, token) {
+			state.token = token
+		},
 		setAccountTabs (state, index) {
 			state.accountTabs = index;
 		},