From 7460ad49c8466092f3847adeeb208e12457e718f Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Mon, 11 Dec 2017 00:05:56 +0100
Subject: [PATCH] Logout message on Login page after redirect #22

---
 frontend/src/components/Login.vue | 17 +++++++++++------
 frontend/src/router/index.js      |  7 +++++--
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/frontend/src/components/Login.vue b/frontend/src/components/Login.vue
index 021cb660..82381bde 100644
--- a/frontend/src/components/Login.vue
+++ b/frontend/src/components/Login.vue
@@ -26,7 +26,7 @@
                 type="password"
                 required
                 ></v-text-field>
-              <v-btn type="submit" color="primary">Access</v-btn>
+              <v-btn :loading="loading" type="submit" color="primary">Access</v-btn>
             </v-form>
           </v-flex>
         </v-layout>
@@ -35,7 +35,7 @@
 
 
 <script>
-  import {mapActions} from 'vuex'
+  import {mapActions, mapState} from 'vuex'
   export default {
     name: 'grady-login',
     data () {
@@ -44,9 +44,14 @@
           username: '',
           password: ''
         },
-        error: ''
+        loading: false
       }
     },
+    computed: {
+      ...mapState([
+        'error'
+      ])
+    },
     methods: {
       ...mapActions([
         'getJWTToken',
@@ -55,14 +60,14 @@
         'getJWTTimeDelta'
       ]),
       submit () {
+        this.loading = true
         this.getJWTToken(this.credentials).then(() => {
+          this.loading = false
           this.$router.push('/student/')
           this.getExamModule()
           this.getUserRole()
           this.getJWTTimeDelta()
-        }).catch(() => {
-          this.error = this.$store.state.error
-        })
+        }).catch(() => { this.loading = false })
       }
     }
   }
diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js
index 6569eb17..cbb0c55a 100644
--- a/frontend/src/router/index.js
+++ b/frontend/src/router/index.js
@@ -62,8 +62,11 @@ router.beforeEach((to, from, next) => {
     next()
   } else {
     const now = new Date()
-    if (now - store.state.logInTime > store.state.jwtTimeDelta * 1000) {
-      store.dispatch('logout').then(() => next('/'))
+    if (now - store.state.logInTime > store.state.jwtTimeDelta) {
+      store.dispatch('logout').then(() => {
+        store.commit('API_FAIL', 'You\'ve been logged out due to inactivity')
+        next('/')
+      })
     } else {
       store.dispatch('refreshJWTToken')
       next()
-- 
GitLab