瀏覽代碼

Alert message for incorrect login credentials

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

+ 20
- 11
src/components/user/loginPage.vue 查看文件

8
             <h4>Login</h4>
8
             <h4>Login</h4>
9
             <br />
9
             <br />
10
           </div>
10
           </div>
11
-          <!--<alert :text="'Login successful'" :type="'SUCCESS'" />
12
-          <alert :text="'User does not exist, please register'" :type="'ERROR'" />
13
-          <alert :text="'Username is incorrect'" :type="'WARNING'" />
14
-          <alert :text="'Password is incorrect'" :type="'WARNING'" />
15
-          <alert :text="'Caps Lock is on'" :type="'INFO'" />-->
11
+          <div v-if="this.$store.state.authentication.status === 'error'">
12
+            <alert
13
+              :text="'User doesn\'t exist or Username and Password is incorrect'"
14
+              :type="'ERROR'"
15
+            />
16
+          </div>
16
           <div class="row">
17
           <div class="row">
17
             <div class="col-md-11" style="margin-bottom: 1em">
18
             <div class="col-md-11" style="margin-bottom: 1em">
18
               <div class="input-group mb-3">
19
               <div class="input-group mb-3">
81
         <div class="form">
82
         <div class="form">
82
           <h5>Trouble signing in?</h5>
83
           <h5>Trouble signing in?</h5>
83
           <div>
84
           <div>
84
-            <!--<alert :text="'Username & password request email sent'" :type="'SUCCESS'" />-->
85
+            <!-- <alert :text="'Username & password request email sent'" :type="'SUCCESS'" /> -->
85
             <div class="row">
86
             <div class="row">
86
               <div class="input-group-prepend">
87
               <div class="input-group-prepend">
87
                 <span class="input-group-text">
88
                 <span class="input-group-text">
103
 
104
 
104
 <script>
105
 <script>
105
 import { mapActions, mapState } from 'vuex';
106
 import { mapActions, mapState } from 'vuex';
106
-// import alert from '../shared/alert.vue';
107
+import alert from '../shared/alert.vue';
107
 
108
 
108
 export default {
109
 export default {
109
   name: 'Login',
110
   name: 'Login',
110
   components: {
111
   components: {
111
-    // alert,
112
+    alert,
112
   },
113
   },
113
   data() {
114
   data() {
114
     return {
115
     return {
131
   methods: {
132
   methods: {
132
     ...mapActions('authentication', ['login']),
133
     ...mapActions('authentication', ['login']),
133
     Login() {
134
     Login() {
134
-      this.login({ username: this.username, password: this.password })
135
-        .then(() => this.router.push('/'))
136
-        .catch(err => console.log(err));
135
+      this.login({ username: this.username, password: this.password }).then(
136
+        () => {
137
+          if (this.$store.state.authentication.status === 'error') {
138
+            this.$router.push('/user/login');
139
+          }
140
+        },
141
+      );
142
+      // .catch((err) => {
143
+      //   this.alertmes = true;
144
+      //   console.log(err);
145
+      // });
137
       this.$router.push('/about/us');
146
       this.$router.push('/about/us');
138
     },
147
     },
139
     togglePassword() {
148
     togglePassword() {

+ 2
- 1
src/store/modules/user/authentication.js 查看文件

49
             commit('auth_success', resp.data.token, resp.data);
49
             commit('auth_success', resp.data.token, resp.data);
50
           })
50
           })
51
           .catch((err) => {
51
           .catch((err) => {
52
-            commit('auth_error');
52
+            // commit('auth_error');
53
             sessionStorage.removeItem('token');
53
             sessionStorage.removeItem('token');
54
             sessionStorage.removeItem('username');
54
             sessionStorage.removeItem('username');
55
             sessionStorage.removeItem('name');
55
             sessionStorage.removeItem('name');
56
             reject(err);
56
             reject(err);
57
+            commit('auth_error', err.data);
57
           });
58
           });
58
       });
59
       });
59
     },
60
     },

Loading…
取消
儲存