summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2019-02-26 01:18:03 +0100
committerJannik Schönartz2019-02-26 01:18:03 +0100
commit741cf724ae6cff9b023016b9a6f42a8a9f23647c (patch)
tree49e8f95b7d88e8dc069a5d41e540c3160d6bc018
parent[webapp] small ui fixes (diff)
downloadbas-741cf724ae6cff9b023016b9a6f42a8a9f23647c.tar.gz
bas-741cf724ae6cff9b023016b9a6f42a8a9f23647c.tar.xz
bas-741cf724ae6cff9b023016b9a6f42a8a9f23647c.zip
[webapp/setup] StartPageSetup now uses the new UserCreateForm component & small fixes
-rw-r--r--server/api/authentication.js4
-rw-r--r--server/lib/authentication.js2
-rw-r--r--webapp/package-lock.json28
-rw-r--r--webapp/src/components/StartPageSetup.vue85
-rw-r--r--webapp/src/components/UserCreateForm.vue6
5 files changed, 45 insertions, 80 deletions
diff --git a/server/api/authentication.js b/server/api/authentication.js
index 050031c..18158ce 100644
--- a/server/api/authentication.js
+++ b/server/api/authentication.js
@@ -20,8 +20,8 @@ noAuthRouter.post('/logout', (req, res) => {
// Setup method for creating the initial root account.
noAuthRouter.post('/setup', (req, res) => {
db.user.findAll().then(users => {
- if (users.length > 0) res.send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
- else if (req.body.username) authentication.signup(req, res)
+ if (users.length > 0) res.status(500).send({ status: 'USERTABLE_NOT_EMPTY', error_message: 'The user table is not empty, unauthorized creation is forbidden.' })
+ else if (req.body.username) return authentication.signup(req, res)
else res.send({ status: 'SUCCESS' })
})
})
diff --git a/server/lib/authentication.js b/server/lib/authentication.js
index 9c1062c..b9c87d1 100644
--- a/server/lib/authentication.js
+++ b/server/lib/authentication.js
@@ -38,7 +38,7 @@ async function signup (req, res) {
// TODO: Implement some security stuff. Not every user who call this request should be able to sign up.
var params = req.body
if (!params.username) return res.status(400).send({ auth: false, status: 'USER_MISSING', error_message: 'This service requires an username.' })
- if (validateUsername(params.username)) return res.status(400).send({ auth: false, status: 'INVALID_USERNAME', error_message: 'Username does not fullfill the requirements. (No whitespaces)' })
+ if (!validateUsername(params.username)) return res.status(400).send({ auth: false, status: 'INVALID_USERNAME', error_message: 'Username does not fullfill the requirements. (No whitespaces)' })
if (!params.password) return res.status(400).send({ auth: false, status: 'PASSWORD_MISSING', error_message: 'This services requires a password.' })
// if (!params.email) return res.status(500).send({ auth: false, status: 'EMAIL_MISSING', error_message: 'This services requires an email.' })
diff --git a/webapp/package-lock.json b/webapp/package-lock.json
index b03144b..f8a2299 100644
--- a/webapp/package-lock.json
+++ b/webapp/package-lock.json
@@ -4295,12 +4295,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@@ -4315,17 +4317,20 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"core-util-is": {
"version": "1.0.2",
@@ -4442,7 +4447,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"ini": {
"version": "1.3.5",
@@ -4454,6 +4460,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@@ -4468,6 +4475,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@@ -4475,12 +4483,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"minipass": {
"version": "2.2.4",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"safe-buffer": "^5.1.1",
"yallist": "^3.0.0"
@@ -4499,6 +4509,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"minimist": "0.0.8"
}
@@ -4579,7 +4590,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
- "dev": true
+ "dev": true,
+ "optional": true
},
"object-assign": {
"version": "4.1.1",
@@ -4591,6 +4603,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"wrappy": "1"
}
@@ -4712,6 +4725,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
+ "optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
diff --git a/webapp/src/components/StartPageSetup.vue b/webapp/src/components/StartPageSetup.vue
index 32dd1a3..8d41f81 100644
--- a/webapp/src/components/StartPageSetup.vue
+++ b/webapp/src/components/StartPageSetup.vue
@@ -34,87 +34,38 @@
<template>
<div class="setup-page">
<label style="color: red; font-size: large">{{ $t('createRoot') }}</label>
- <v-form class="setup-form" ref="form" v-model="valid" lazy-validation @submit.prevent="setup">
- <v-text-field
- validate-on-blur
- :label="$t('username')"
- v-model="username"
- :rules="usernameRules"
- autocomplete="off"
- ></v-text-field>
- <v-text-field
- validate-on-blur
- type="password"
- :label="$t('password')"
- v-model="password"
- :rules="passwordRules"
- autocomplete="off"
- ></v-text-field>
- <v-text-field
- validate-on-blur
- type="password"
- :label="$t('confirmPassword')"
- v-model="confirmPassword"
- :rules="confirmPasswordRules"
- autocomplete="off"
- ></v-text-field>
- <v-text-field
- :label="$t('name')"
- autocomplete="off"
- v-model="name"
- ></v-text-field>
- <v-text-field
- validate-on-blur
- :label="$t('email')"
- :rules="emailRules"
- autocomplete="off"
- v-model="email"
- ></v-text-field>
- <v-btn type="submit" class="setup-button primary" raised>{{ $t('signup') }}</v-btn>
- </v-form>
+ <signup v-model="user" ref="setupRoot"></signup>
+ <v-btn @click="setup" class="setup-button primary" raised>{{ $t('signup') }}</v-btn>
</div>
</template>
<script>
import Vue from 'vue'
+import signup from '@/components/UserCreateForm'
export default {
name: 'StartPageSetup',
+ components: {
+ signup
+ },
data () {
return {
- valid: true,
- username: '',
- usernameError: false,
- usernameRules: [
- v => !!v || this.$t('usernameEmptyError'),
- v => !this.usernameError || this.$t('usernameError')
- ],
- password: '',
- passwordError: false,
- passwordRules: [
- v => !!v || this.$t('passwordEmptyError'),
- v => v.length >= 8 || this.$t('passwordLengthError'),
- v => !this.passwordError || this.$t('passwordError')
- ],
- confirmPassword: '',
- confirmPasswordRules: [
- v => !!v || this.$t('passwordEmptyError'),
- v => v === this.password || this.$t('passwordMatchError')
- ],
- confirmPasswordError: false,
- email: '',
- emailRules: [
- v => this.$validateEmail(v) || this.$t('emailError')
- ],
- name: ''
+ user: { }
}
},
methods: {
setup () {
- if (this.$refs.form.validate()) {
- this.$http.post('/api/authentication/setup', { username: this.username, password: this.password, name: this.name, email: this.email }).then(response => {
+ if (this.$refs.setupRoot.validate()) {
+ this.$http.post('/api/authentication/setup', {
+ username: this.user.username,
+ password: this.user.password,
+ name: this.user.name,
+ email: this.user.email
+ }).then(response => {
this.$snackbar({ color: 'success', text: this.$t('rootCreated'), timeout: 15000 })
this.$router.replace({ name: 'login' })
+ }).catch(error => {
+ this.$snackbar({ color: 'error', text: error.response.data.error_message, timeout: 15000 })
})
}
}
@@ -139,10 +90,6 @@ export default {
align-items: center;
}
-.setup-form {
- width: 300px;
-}
-
.setup-button {
margin-top: 20px;
float: right;
diff --git a/webapp/src/components/UserCreateForm.vue b/webapp/src/components/UserCreateForm.vue
index 616ca3c..4287e1d 100644
--- a/webapp/src/components/UserCreateForm.vue
+++ b/webapp/src/components/UserCreateForm.vue
@@ -111,7 +111,8 @@ export default {
},
computed: {
...mapState('users', ['dialog']),
- show () { return this.dialog.show }
+ show () { return this.dialog.show },
+ usernameField () { return this.user.username }
},
watch: {
show (value) {
@@ -131,6 +132,9 @@ export default {
handler () {
this.$emit('input', this.user)
}
+ },
+ usernameField () {
+ this.usernameExistsError = false
}
},
methods: {