From 46aec7b4ca323448b8f9d65b688385d69b347841 Mon Sep 17 00:00:00 2001 From: konrad Date: Sat, 8 Sep 2018 22:27:13 +0200 Subject: [PATCH] Added register page --- src/auth/index.js | 23 +++++++ src/components/{ => user}/Login.vue | 9 ++- src/components/user/Register.vue | 101 ++++++++++++++++++++++++++++ src/router/index.js | 9 ++- 4 files changed, 138 insertions(+), 4 deletions(-) rename src/components/{ => user}/Login.vue (90%) create mode 100644 src/components/user/Register.vue diff --git a/src/auth/index.js b/src/auth/index.js index 1935df59..2cff69d9 100644 --- a/src/auth/index.js +++ b/src/auth/index.js @@ -44,6 +44,29 @@ export default { }) }, + register (context, creds, redirect) { + HTTP.post('register', { + username: creds.username, + email: creds.email, + password: creds.password + }) + .then(response => { + // eslint-disable-next-line + console.log(response) + this.login(context, creds, redirect) + }) + .catch(e => { + // Hide the loader + context.loading = false + if (e.response) { + context.error = e.response.data.message + if (e.response.status === 401) { + context.error = 'Wrong username or password.' + } + } + }) + }, + logout () { localStorage.removeItem('token') router.push({ name: 'login' }) diff --git a/src/components/Login.vue b/src/components/user/Login.vue similarity index 90% rename from src/components/Login.vue rename to src/components/user/Login.vue index abca443a..2f05beab 100644 --- a/src/components/Login.vue +++ b/src/components/user/Login.vue @@ -18,6 +18,7 @@
+ Register
@@ -34,8 +35,8 @@ diff --git a/src/components/user/Register.vue b/src/components/user/Register.vue new file mode 100644 index 00000000..f75e006e --- /dev/null +++ b/src/components/user/Register.vue @@ -0,0 +1,101 @@ + + + + + diff --git a/src/router/index.js b/src/router/index.js index 662836bf..e291fcda 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -2,7 +2,9 @@ import Vue from 'vue' import Router from 'vue-router' import HomeComponent from '@/components/Home' -import LoginComponent from '@/components/Login' +// User Handling +import LoginComponent from '@/components/user/Login' +import RegisterComponent from '@/components/user/Register' Vue.use(Router) @@ -17,6 +19,11 @@ export default new Router({ path: '/login', name: 'login', component: LoginComponent + }, + { + path: '/register', + name: 'register', + component: RegisterComponent } ] }) \ No newline at end of file