123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <template>
- <div class="md-layout md-alignment-center-center" style="height: 100vh;">
- <md-card class="md-layout-item md-size-50">
- <md-card-header>
- <div class="md-title">
- Register
- </div>
- </md-card-header>
- <form @submit.prevent="validateForm">
- <md-card-content>
- <md-field :class="getValidationClass('email')" md-clearable>
- <label for="email">Email</label>
- <md-input
- id="email"
- v-model="form.email"
- :disabled="loading"
- type="email"
- name="email"
- autocomplete="email"
- />
- <span v-if="!$v.form.email.required" class="md-error">The email is required</span>
- <span v-else-if="!$v.form.email.email" class="md-error">Invalid required</span>
- </md-field>
- <md-field :class="getValidationClass('password')">
- <label for="password">password</label>
- <md-input
- id="password"
- v-model="form.password"
- :disabled="loading"
- type="password"
- name="password"
- autocomplete="password"
- />
- <span v-if="!$v.form.password.required" class="md-error">The email is required</span>
- <span v-else-if="!$v.form.password.minLength" class="md-error">password too short</span>
- <span v-else-if="!$v.form.password.maxLength" class="md-error">password too Long</span>
- </md-field>
- </md-card-content>
- <md-card-actions>
- <md-button to="/login">
- Go To Login
- </md-button>
- <md-button class="md-primary md-raised" type="submit">
- Submit
- </md-button>
- </md-card-actions>
- </form>
- <md-snackbar :md-active.sync="isAuthenticated">
- {{ form.email }} was successfully registerd!
- </md-snackbar>
- </md-card>
- <!-- Back Button -->
- <md-button @click="$router.go(-1)" class="md-fixed md-fab-bottom-right md-fab md-primary">
- <md-icon>arrow_back</md-icon>
- </md-button>
- </div>
- </template>
- <script>
- import { validationMixin } from 'vuelidate'
- import { required, email, minLength, maxLength } from 'vuelidate/lib/validators'
- export default {
- middleware: 'auth',
- mixins: [validationMixin],
- validations: {
- form: {
- email: {
- required,
- email
- },
- password: {
- required,
- minLength: minLength(6),
- maxLength: maxLength(20)
- }
- }
- },
- data: () => ({
- form: {
- email: '',
- password: ''
- }
- }),
- computed: {
- loading () {
- return this.$store.getters.loading
- },
- isAuthenticated () {
- return this.$store.getters.isAuthenticated
- }
- },
- watch: {
- isAuthenticated (value) {
- if (value) {
- setTimeout(() => this.$router.push('/'), 500)
- }
- }
- },
- methods: {
- validateForm () {
- this.$v.$touch()
- if (!this.$v.$invalid) {
- this.resisterUser()
- }
- },
- async resisterUser () {
- await this.$store.dispatch('authenticateUser', {
- action: 'register',
- email: this.form.email,
- password: this.form.password,
- resturnSecureToken: true
- })
- },
- getValidationClass (fieldName) {
- const field = this.$v.form[fieldName]
- if (field) {
- return {
- 'md-invalid': field.$invalid && field.$dirty
- }
- }
- }
- }
- }
- </script>
|