From b137ce9beff035372ece02485402c3876ddcd5a4 Mon Sep 17 00:00:00 2001 From: Fulgen301 Date: Sun, 16 Sep 2018 18:18:30 +0200 Subject: ApiAuth: Add registration functionality --- src/components/ApiAuth.vue | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/components') diff --git a/src/components/ApiAuth.vue b/src/components/ApiAuth.vue index 30c7e14..5139f74 100644 --- a/src/components/ApiAuth.vue +++ b/src/components/ApiAuth.vue @@ -11,6 +11,7 @@ Parry login + Register @@ -59,6 +60,7 @@ username: this.username, password: this.password, } + console.log(params) this.authError = undefined this.$http.post('/auth', params).then((response) => { that.$store.commit('user/setAuthToken', { authToken: response.data.token }) @@ -78,6 +80,28 @@ } }) }, + parryRegister() { + let that = this + let params = { + username: this.username, + password: this.password + } + this.authError = undefined + this.$http.post('/auth/register', params).catch(error => { + switch (error.response.status) + { + case 303: + this.parryLogin() + return + case 409: + this.authError = 'User already exists' + break + default: + this.authError = 'Failed to register' + } + console.error({error}) + }) + }, checkTokenLoop (retryCount) { let token = LocalStorage.get.item('authToken') if (token) { -- cgit v1.2.3-54-g00ecf