aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/ApiAuth.vue
diff options
context:
space:
mode:
authorFulgen301 <tokmajigeorge@gmail.com>2018-09-16 18:18:30 +0200
committerFulgen301 <tokmajigeorge@gmail.com>2018-09-16 18:18:30 +0200
commitb137ce9beff035372ece02485402c3876ddcd5a4 (patch)
tree1f39e6eedc49e4a226a9ef10f7ff729ad0edc793 /src/components/ApiAuth.vue
parent1ba019edcfdb574edcf511e6941afd5402787f8d (diff)
downloadparry-ui-b137ce9beff035372ece02485402c3876ddcd5a4.tar.gz
parry-ui-b137ce9beff035372ece02485402c3876ddcd5a4.zip
ApiAuth: Add registration functionality
Diffstat (limited to 'src/components/ApiAuth.vue')
-rw-r--r--src/components/ApiAuth.vue24
1 files changed, 24 insertions, 0 deletions
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 @@
<q-input @keyup.enter="parryLogin" :error="authError !== undefined" v-model="username" name="user" float-label="Username" />
<q-input @keyup.enter="parryLogin" :error="authError !== undefined" v-model="password" name="pass" type="password" float-label="Password" />
<q-btn color="positive" @click="parryLogin" icon="fa-sign-in">Parry login</q-btn>
+ <q-btn color="positive" @click="parryRegister">Register</q-btn>
</div>
</div>
</div>
@@ -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) {