Match registration rules in frontend

This commit is contained in:
Hubert Van De Walle 2020-06-18 17:07:54 +02:00
parent 1611ca6ab4
commit a786cc848c
2 changed files with 13 additions and 22 deletions

View File

@ -19,7 +19,6 @@
+ Request (application/json) + Request (application/json)
+ Attributes (object) + Attributes (object)
+ username: babar (string) + username: babar (string)
+ email: `michel@seed-it.eu` (string)
+ password: tortue (string) + password: tortue (string)
+ Response 200 (application/json) + Response 200 (application/json)
@ -85,4 +84,3 @@ Receive the username and email from the currently logged in user
+ Attributes + Attributes
+ user: (object) + user: (object)
+ username: babar (string) + username: babar (string)
+ email: `michel@seed-it.eu` (string)

View File

@ -10,14 +10,6 @@
:prepend-icon="mdiAccount" :prepend-icon="mdiAccount"
></v-text-field> ></v-text-field>
<v-text-field
v-model="form.email"
:rules="emailRules"
label="Email"
required
:prepend-icon="mdiAt"
></v-text-field>
<v-text-field <v-text-field
v-model="form.password" v-model="form.password"
:rules="passwordRules" :rules="passwordRules"
@ -36,7 +28,6 @@
type="password" type="password"
></v-text-field> ></v-text-field>
</v-card-text> </v-card-text>
<v-divider />
<v-card-actions> <v-card-actions>
<v-spacer /> <v-spacer />
<v-btn <v-btn
@ -53,7 +44,7 @@
</template> </template>
<script> <script>
import { mdiLock, mdiAccount, mdiAt } from '@mdi/js' import { mdiAccount, mdiAt, mdiLock } from '@mdi/js'
export default { export default {
name: 'RegisterForm', name: 'RegisterForm',
@ -64,20 +55,22 @@ export default {
valid: false, valid: false,
form: { form: {
username: '', username: '',
email: '',
password: '', password: '',
}, },
usernameRules: [ usernameRules: [
(v) => !!v || 'Name is required', (v) => !!v || 'Username is required',
(v) => /^[a-zA-Z0-9]+$/.test(v) || 'Name must be alphanumeric', (v) =>
], v.length <= 50 ||
emailRules: [ 'Username must be shorter or equal to 50 characters',
(v) => !!v || 'Email is required', (v) =>
(v) => /.+@.+/.test(v) || 'E-mail must be valid', v.length >= 3 ||
'Username must be longer or equal to 3 characters',
], ],
passwordRules: [ passwordRules: [
(v) => !!v || 'Password is required', (v) => !!v || 'Password is required',
(v) => v.length >= 6 || 'Password must be longer than 6 characters', (v) =>
v.length >= 6 ||
'Password must be longer or equal to 6 characters',
], ],
confirm: '', confirm: '',
confirmRules: [ confirmRules: [
@ -89,8 +82,8 @@ export default {
registerUser() { registerUser() {
this.$axios this.$axios
.post('/user', this.form) .post('/user', this.form)
.then((_) => this.$root.$emit('register::success')) .then(() => this.$root.$emit('register::success'))
.catch((_) => .catch(() =>
this.$root.$emit( this.$root.$emit(
'toast', 'toast',
'Please choose another username', 'Please choose another username',