File tree Expand file tree Collapse file tree 4 files changed +53
-27
lines changed
Expand file tree Collapse file tree 4 files changed +53
-27
lines changed Original file line number Diff line number Diff line change 1919 Profile
2020 </router-link >
2121 </div >
22-
23- <div class =" navbar-end" >
24- <div class =" navbar-item" >
25- <div class =" buttons" >
26- <router-link :to =" { name: 'index' }" class =" button is-light" >
27- Log in
28- </router-link >
29- </div >
30- </div >
31- </div >
3222 </div >
3323 </div >
3424 </nav >
35- < div class = " container " >
36- <!-- component matched by the route will render here -->
37- <router-view ></router-view >
38- </ div >
25+
26+ <!-- component matched by the route will render here -->
27+ <router-view ></router-view >
28+
3929 <footer class =" footer" >
4030 <div class =" content has-text-centered" >
4131 <p >© ; Copyleft {{ new Date().toLocaleString('it-IT', { year: 'numeric' }) }} Point of Vue</p >
@@ -55,11 +45,6 @@ export default {
5545
5646 html ,
5747 body {
58- width : 100% ;
59- height : 100% ;
60- min-height : 100% ;
61- padding : 0 ;
62- margin : 0 ;
6348 overflow-x : hidden ;
6449 }
6550 </style >
Original file line number Diff line number Diff line change 11<template >
2- <div class =" container" >
3-
4- </div >
2+ <section class =" hero is-medium" >
3+ <div class =" hero-body" >
4+ <div class =" container has-text-centered" >
5+ <div class =" column is-4 is-offset-4" >
6+ <p class =" subtitle has-text-black" >Please login to proceed.</p >
7+ <div class =" box" >
8+ <form @submit.prevent =" loginSubmit" >
9+ <div class =" field" >
10+ <div class =" control" >
11+ <input v-model =" email" class =" input" type =" text" placeholder =" Your Email" autofocus =" " >
12+ </div >
13+ </div >
14+ <div class =" field" >
15+ <div class =" control" >
16+ <input v-model =" password" class =" input" type =" password" placeholder =" Your Password" >
17+ </div >
18+ </div >
19+ <button class =" button is-block is-info is-fullwidth" >Login</button >
20+ </form >
21+ </div >
22+ </div >
23+ </div >
24+ </div >
25+ </section >
526</template >
627
728<script >
@@ -10,8 +31,18 @@ export default {
1031
1132 data () {
1233 return {
13-
34+ email: null ,
35+ password: null ,
1436 };
1537 },
38+
39+ methods: {
40+ loginSubmit () {
41+ this .$store .dispatch (' doLogin' , {
42+ email: this .email ,
43+ password: this .password ,
44+ });
45+ }
46+ }
1647}
1748 </script >
Original file line number Diff line number Diff line change @@ -33,10 +33,10 @@ const router = new VueRouter({
3333 * Redirect to login if the user is not authenticated
3434 */
3535router . beforeEach ( ( to , from , next ) => {
36- if ( to . name !== 'login' && ! store . state . accessToken ) {
37- next ( '/login' ) ;
36+ if ( store . state . accessToken || to . name === 'login' ) {
37+ next ( ) ;
3838 }
39- next ( ) ;
39+ next ( '/login' ) ;
4040} ) ;
4141
4242Vue . use ( VueRouter ) ;
Original file line number Diff line number Diff line change 11import Vue from 'vue' ;
22import Vuex from 'vuex' ;
33
4+ import router from '../router' ;
5+
46Vue . use ( Vuex ) ;
57
68const user = {
@@ -14,7 +16,12 @@ const user = {
1416 } ,
1517 mutations : {
1618 updateUser : ( state , data ) => {
17- state = data ;
19+ state . id = data . id ;
20+ state . registeredAt = data . registeredAt ;
21+ state . avatar = data . avatar ;
22+ state . name = data . name ;
23+ state . email = data . email ;
24+ state . accessToken = data . accessToken ;
1825 } ,
1926 logout : ( state ) => {
2027 state . accessToken = null ;
@@ -32,10 +39,13 @@ const user = {
3239 } ) ;
3340 const response = await rawResponse . json ( ) ;
3441 commit ( 'updateUser' , response ) ;
42+ console . log ( response ) ;
43+ router . push ( '/' ) ;
3544 } ,
3645
3746 doLogout ( { commit } ) {
3847 commit ( 'logout' ) ;
48+ router . push ( '/' ) ;
3949 }
4050 } ,
4151 getters : { } ,
You can’t perform that action at this time.
0 commit comments