summaryrefslogtreecommitdiffstats
path: root/src/views/Register.vue
blob: eb382c5ceb9d428b1508c0b40cb04f9cfd999daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<template>
  <div id="register">
      <form @submit="register">
        <input type="text" placeholder="Login" v-model="login">
        <input type="password" placeholder="Password" v-model="password">
        <input type="password" placeholder="Repeat password" v-model="repeat_password">     

        <input type="submit" value="Register!">
      </form>

      <router-link to="/login">Already have an account?</router-link>
      
    </div>
</template>

<script>
import AuthService from '@/services/AuthService'

export default {
    data: () => {
        return {
            login: "",
            password: "",
            repeat_password: "",
        }
    },
    methods: {
        async register(e) {
            this.messages = []

            e.preventDefault()
            if(this.password !== this.repeat_password){
                this.$notify({
                    type: 'warn',
                    text: 'Passwords not equals',
                })
                this.password = ""
                this.repeat_password = ""

                return null
            }

            const register_data = {
                "username": this.login,
                "password": this.password
            }

            const { status } = await AuthService.register(register_data)
            if (status === 200) {
                this.$notify({
                    type: 'success',
                    text:'Register success, you can now login.!'
                })
                this.$router.push('/login')
            }
        }
    },
    created() {
        if(this.$store.getters['is_logged_in']) {
            this.$router.push('/')
        }
    }

}
</script>

<style>

</style>