diff options
Diffstat (limited to 'src/views/Register.vue')
| -rw-r--r-- | src/views/Register.vue | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/views/Register.vue b/src/views/Register.vue new file mode 100644 index 0000000..c03f5fd --- /dev/null +++ b/src/views/Register.vue | |||
| @@ -0,0 +1,70 @@ | |||
| 1 | <template> | ||
| 2 | <div id="register"> | ||
| 3 | <form @submit="register"> | ||
| 4 | <input type="text" placeholder="Login" v-model="login"> | ||
| 5 | <input type="password" placeholder="Password" v-model="password"> | ||
| 6 | <input type="password" placeholder="Repeat password" v-model="repeat_password"> | ||
| 7 | |||
| 8 | <input type="submit" value="Register!"> | ||
| 9 | </form> | ||
| 10 | <p v-for="(mess, key) in messages" :key="key">{{mess}}</p> | ||
| 11 | |||
| 12 | <router-link to="/login">Already have account?</router-link> | ||
| 13 | |||
| 14 | </div> | ||
| 15 | </template> | ||
| 16 | |||
| 17 | <script> | ||
| 18 | import AuthService from '@/services/AuthService' | ||
| 19 | |||
| 20 | export default { | ||
| 21 | data: () => { | ||
| 22 | return { | ||
| 23 | login: "", | ||
| 24 | password: "", | ||
| 25 | repeat_password: "", | ||
| 26 | messages: [] | ||
| 27 | } | ||
| 28 | }, | ||
| 29 | methods: { | ||
| 30 | async register(e) { | ||
| 31 | this.messages = [] | ||
| 32 | |||
| 33 | e.preventDefault() | ||
| 34 | if(this.password !== this.repeat_password){ | ||
| 35 | this.messages.push("Passwords not equals") | ||
| 36 | this.password = "" | ||
| 37 | this.repeat_password = "" | ||
| 38 | |||
| 39 | return null | ||
| 40 | } | ||
| 41 | |||
| 42 | const data = { | ||
| 43 | "username": this.login, | ||
| 44 | "password": this.password | ||
| 45 | } | ||
| 46 | |||
| 47 | try { | ||
| 48 | await AuthService.register(data) | ||
| 49 | this.messages.push("Success!") | ||
| 50 | }catch (error) { | ||
| 51 | if(error.response.data.username) | ||
| 52 | this.messages.push(error.response.data.username[0]) | ||
| 53 | if (error.response.data.password) | ||
| 54 | this.messages.push(error.response.data.password[0]) | ||
| 55 | |||
| 56 | } | ||
| 57 | } | ||
| 58 | }, | ||
| 59 | created() { | ||
| 60 | if(this.$store.getters['is_logged_in']) { | ||
| 61 | this.$router.push('/') | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | } | ||
| 66 | </script> | ||
| 67 | |||
| 68 | <style> | ||
| 69 | |||
| 70 | </style> \ No newline at end of file | ||
