浏览代码

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,11 +8,12 @@
8 8
             <h4>Login</h4>
9 9
             <br />
10 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 17
           <div class="row">
17 18
             <div class="col-md-11" style="margin-bottom: 1em">
18 19
               <div class="input-group mb-3">
@@ -81,7 +82,7 @@
81 82
         <div class="form">
82 83
           <h5>Trouble signing in?</h5>
83 84
           <div>
84
-            <!--<alert :text="'Username & password request email sent'" :type="'SUCCESS'" />-->
85
+            <!-- <alert :text="'Username & password request email sent'" :type="'SUCCESS'" /> -->
85 86
             <div class="row">
86 87
               <div class="input-group-prepend">
87 88
                 <span class="input-group-text">
@@ -103,12 +104,12 @@
103 104
 
104 105
 <script>
105 106
 import { mapActions, mapState } from 'vuex';
106
-// import alert from '../shared/alert.vue';
107
+import alert from '../shared/alert.vue';
107 108
 
108 109
 export default {
109 110
   name: 'Login',
110 111
   components: {
111
-    // alert,
112
+    alert,
112 113
   },
113 114
   data() {
114 115
     return {
@@ -131,9 +132,17 @@ export default {
131 132
   methods: {
132 133
     ...mapActions('authentication', ['login']),
133 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 146
       this.$router.push('/about/us');
138 147
     },
139 148
     togglePassword() {

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

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

正在加载...
取消
保存