@@ -12,6 +12,7 @@ const api = `${config.api.protocol}://${config.api.host}:${config.api.port}/${co
1212const getters = {
1313 isLoggedIn : ( state ) => ! ! state . cookieExpire ,
1414 authStatus : ( state ) => state . status ,
15+ mail : ( state ) => state . mail ,
1516} ;
1617
1718/**
@@ -31,7 +32,7 @@ const actions = {
3132 dispatch ( 'refreshNav' ) ;
3233 } catch ( err ) {
3334 localStorage . removeItem ( 'token' ) ;
34- commit ( 'auth_error' ) ;
35+ commit ( 'auth_error' , err ) ;
3536 }
3637 } ,
3738 signup : async ( { commit, dispatch } , params ) => {
@@ -47,47 +48,79 @@ const actions = {
4748 dispatch ( 'refreshNav' ) ;
4849 } catch ( err ) {
4950 localStorage . removeItem ( 'token' ) ;
50- commit ( 'auth_error' ) ;
51+ commit ( 'auth_error' , err ) ;
5152 }
5253 } ,
53- signout ( { commit } ) {
54- return new Promise ( ( resolve ) => {
54+ signout : ( { commit } ) =>
55+ new Promise ( ( resolve ) => {
5556 commit ( 'auth_logout' ) ;
5657 localStorage . removeItem ( `${ config . cookie . prefix } UserRoles` ) ;
5758 localStorage . removeItem ( `${ config . cookie . prefix } CookieExpire` ) ;
5859 resolve ( ) ;
59- } ) ;
60+ } ) ,
61+ forgot : async ( { commit } , params ) => {
62+ try {
63+ const res = await Vue . prototype . axios ( {
64+ url : `${ api } /${ config . api . endPoints . auth } /forgot` ,
65+ data : params ,
66+ method : 'POST' ,
67+ } ) ;
68+ commit ( 'forgot_success' , res . data ) ;
69+ } catch ( err ) {
70+ commit ( 'auth_error' , err ) ;
71+ }
72+ } ,
73+ reset : async ( { commit, dispatch } , params ) => {
74+ try {
75+ const res = await Vue . prototype . axios ( {
76+ url : `${ api } /${ config . api . endPoints . auth } /reset` ,
77+ data : params ,
78+ method : 'POST' ,
79+ } ) ;
80+ localStorage . setItem ( `${ config . cookie . prefix } UserRoles` , res . data . user . roles ) ;
81+ localStorage . setItem ( `${ config . cookie . prefix } CookieExpire` , res . data . tokenExpiresIn ) ;
82+ commit ( 'auth_success' , res . data ) ;
83+ dispatch ( 'refreshNav' ) ;
84+ } catch ( err ) {
85+ localStorage . removeItem ( 'token' ) ;
86+ commit ( 'auth_error' , err ) ;
87+ }
6088 } ,
6189} ;
6290
6391/**
6492 * Mutation: change state in a Vuex store is by committing a mutation
6593 */
6694const mutations = {
67- auth_request ( state ) {
68- state . status = 'loading' ;
69- } ,
7095 auth_success ( state , data ) {
71- state . status = 'success' ;
7296 state . cookieExpire = data . tokenExpiresIn ;
7397 state . user = data . user ;
7498 } ,
75- auth_error ( state ) {
76- state . status = 'error' ;
99+ auth_error ( state , err ) {
100+ console . log ( err ) ;
77101 } ,
78102 auth_logout ( state ) {
79- state . status = '' ;
80103 state . cookieExpire = 0 ;
81104 } ,
105+ forgot_success ( state , data ) {
106+ state . mail . status = data . data . status ;
107+ state . mail . message = data . message ;
108+ } ,
109+ reset_success ( state , data ) {
110+ console . log ( data ) ;
111+ } ,
82112} ;
83113
84114/**
85115 * State
86116 */
87117const state = {
88- status : '' ,
89118 cookieExpire : localStorage . getItem ( `${ config . cookie . prefix } CookieExpire` ) || 0 ,
90119 user : { } ,
120+ mail : {
121+ status : false ,
122+ message : '' ,
123+ } ,
91124} ;
92125
93126/**
0 commit comments