瀏覽代碼

Changed the pormise on the login

master
Lene Scholtz 5 年之前
父節點
當前提交
a45a9ddc96
共有 2 個文件被更改,包括 31 次插入30 次删除
  1. 9
    0
      src/components/user/loginPage.vue
  2. 22
    30
      src/store/modules/user/authentication.js

+ 9
- 0
src/components/user/loginPage.vue 查看文件

129
       } else this.troubleToggle = true;
129
       } else this.troubleToggle = true;
130
     },
130
     },
131
     Login() {
131
     Login() {
132
+      console.log(this.$store.state.authentication);
133
+
132
       this.login().then(() => {
134
       this.login().then(() => {
135
+        console.log('this');
136
+        console.log(this);
137
+        console.log(this.$store.state.authentication.status);
138
+
133
         if (this.$store.state.authentication.status === 'error') {
139
         if (this.$store.state.authentication.status === 'error') {
134
           this.$router.push('/user/login');
140
           this.$router.push('/user/login');
141
+        } else {
142
+          console.log('yippy tequila');
143
+          this.$router.push('/about/us');
135
         }
144
         }
136
       });
145
       });
137
     },
146
     },

+ 22
- 30
src/store/modules/user/authentication.js 查看文件

53
     authStatus: state => state.status,
53
     authStatus: state => state.status,
54
   },
54
   },
55
   actions: {
55
   actions: {
56
-    init({
57
-      commit,
58
-    }) {
56
+    init({ commit }) {
59
       if (!log.isLoggedIn() && log.tokenExpired) {
57
       if (!log.isLoggedIn() && log.tokenExpired) {
60
         log.clearValues();
58
         log.clearValues();
61
       } else log.updateTokenExpiry();
59
       } else log.updateTokenExpiry();
66
         agency: log.getJSONObject('agency'),
64
         agency: log.getJSONObject('agency'),
67
       });
65
       });
68
     },
66
     },
69
-    login({
70
-      commit,
71
-      state,
72
-    }) {
73
-      return new Promise((reject) => {
74
-        commit('auth_request');
75
-        const user = {
67
+    login({ commit, state }) {
68
+      axios({
69
+        url: '/api/register/authenticate',
70
+        data: {
76
           username: state.username,
71
           username: state.username,
77
           password: state.password,
72
           password: state.password,
78
-        };
79
-        axios({
80
-          url: '/api/register/authenticate',
81
-          data: user,
82
-          method: 'POST',
73
+        },
74
+        method: 'POST',
75
+      })
76
+        .then((resp) => {
77
+          log.clearValues();
78
+          log.setValues(resp.data);
79
+          console.log(resp.data);
80
+
81
+          commit('auth_success', resp.data);
83
         })
82
         })
84
-          .then((resp) => {
85
-            log.clearValues();
86
-            log.setValues(resp.data);
87
-            commit('auth_success', resp.data);
88
-          })
89
-          .catch((err) => {
90
-            commit('auth_error');
91
-            log.clearValues();
92
-            reject(err);
93
-            commit('auth_error', err.data);
94
-          });
95
-      });
83
+        .catch((err) => {
84
+          commit('auth_error');
85
+          log.clearValues();
86
+          // reject(err);
87
+          commit('auth_error', err.data);
88
+        });
89
+      /* }); */
96
     },
90
     },
97
-    logout({
98
-      commit,
99
-    }) {
91
+    logout({ commit }) {
100
       return new Promise(() => {
92
       return new Promise(() => {
101
         commit('logout');
93
         commit('logout');
102
         log.clearValues();
94
         log.clearValues();

Loading…
取消
儲存