This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/frontend/src/components/forms/Register.vue

89 lines
2 KiB
Vue
Raw Normal View History

2019-05-06 14:18:23 +00:00
<template>
2019-05-08 20:55:15 +00:00
<FormDialog ref="main" buttonText="Register" @validated="doRegister">
2019-05-06 15:02:12 +00:00
<v-card-title class="headline">
2019-05-06 14:18:23 +00:00
Register
2019-05-06 15:02:12 +00:00
</v-card-title>
<v-card-text>
<v-text-field
ref="autofocus"
v-model="login"
:rules="loginRules"
label="User name"
required
></v-text-field>
<v-text-field
v-model="password"
:append-icon="showPassword ? 'visibility' : 'visibility_off'"
@click:append="showPassword = !showPassword"
:rules="passwordRules"
:type="showPassword ? 'text' : 'password'"
label="Password"
required
counter
></v-text-field>
2019-05-06 15:21:21 +00:00
<v-text-field
v-if="!showPassword"
v-model="passwordConfirm"
:rules="passwordConfirmRules"
:type="showPassword ? 'text' : 'password'"
label="Confirm Password"
required
></v-text-field>
2019-05-06 15:02:12 +00:00
</v-card-text>
</FormDialog>
2019-05-06 14:18:23 +00:00
</template>
<script>
2019-05-06 15:02:12 +00:00
import FormDialog from './FormDialog.vue'
2019-05-07 16:03:40 +00:00
import axios from '@/plugins/axios'
2019-05-06 15:02:12 +00:00
2019-05-06 14:18:23 +00:00
export default {
name: 'RegisterForm',
2019-05-06 15:02:12 +00:00
components: {
FormDialog
},
data: () => ({
2019-05-06 14:18:23 +00:00
login: '',
loginRules: [v => !!v || 'User name is required'],
password: '',
showPassword: false,
2019-05-06 15:21:21 +00:00
passwordRules: [v => !!v || 'Password is required'],
2019-05-07 08:55:01 +00:00
passwordConfirm: ''
2019-05-06 14:18:23 +00:00
}),
2019-05-06 15:21:21 +00:00
computed: {
passwordConfirmRules() {
return [
2019-05-07 08:55:01 +00:00
() => this.password === this.passwordConfirm || 'Passwords must match'
2019-05-06 15:21:21 +00:00
]
2019-05-07 08:55:01 +00:00
}
2019-05-06 15:21:21 +00:00
},
2019-05-06 14:18:23 +00:00
methods: {
2019-05-07 20:14:23 +00:00
doRegister() {
2019-05-07 16:03:40 +00:00
axios
2019-05-06 15:02:12 +00:00
.post('/user/register', {
2019-05-07 15:37:07 +00:00
session: null,
2019-05-06 15:02:12 +00:00
login: this.login,
password: this.password
})
.then(response => {
console.log('register', response.data)
2019-05-08 19:34:40 +00:00
if (response.data.success) {
this.$refs.main.showSnackbar("Registration successful!", 'success')
2019-05-08 19:34:40 +00:00
} else {
this.$refs.main.showSnackbar(response.data.message, 'error')
2019-05-08 19:34:40 +00:00
}
2019-05-06 14:18:23 +00:00
})
}
}
}
</script>