From 5f0d1e11398977276f166fd35ae910a3dc7cc21d Mon Sep 17 00:00:00 2001
From: LeeYongJae <sdc5678@ajou.ac.kr>
Date: Thu, 5 Dec 2019 21:44:10 +0900
Subject: [PATCH] Login with session2

---
 frontend/src/App.vue                     | 48 +++++++++++-------------
 frontend/src/components/login/Login.vue  |  8 ++--
 frontend/src/components/login/Logout.vue |  2 +
 3 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index ff7e975..8c4c635 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -6,15 +6,13 @@
           <span class="md-title">MajorBook</span>
         </div>
 
-        <div style="flex:1">
-          <div align="right">
-            <div v-if="!checkLoggedIn">
-              <Login />
-              <SignUp />
-            </div>
-            <div v-if="checkLoggedIn">
-              <Logout />
-            </div>
+        <div style="flex:1; height:20px" align="right">
+          <div v-if="isLoggedIn === false">
+            <Login />
+            <SignUp />
+          </div>
+          <div v-else>
+            <Logout />
           </div>
         </div>
 
@@ -22,11 +20,7 @@
           <md-tabs class="md-primary" style="margin: auto; height: 30px">
             <md-tab id="tab-home" md-label="Home" to="/home"></md-tab>
             <md-tab id="tab-profile" md-label="Profile" to="/profile"></md-tab>
-            <md-tab
-              id="tab-list"
-              md-label="전공서적보기"
-              to="/BookSearchPage"
-            ></md-tab>
+            <md-tab id="tab-list" md-label="전공서적보기" to="/BookSearchPage"></md-tab>
           </md-tabs>
         </div>
       </md-app-toolbar>
@@ -63,25 +57,25 @@ export default {
   },
   methods: {
     checkSession() {
-      this.$http.get("/api/login/checkSession").then(function(response) {
-        //console.log(response.data);
+      this.$http.get("/api/login/checkSession").then(response => {
+        console.log(response.data);
         if (response.data === true) {
-          return true;
+          return (this.isLoggedIn = true);
         } else {
-          return false;
+          return (this.isLoggedIn = false);
         }
       });
     }
-  },
-  computed: {
-    checkLoggedIn() {
-      console.log(this.checkSession());
-      if (this.checkSession() === true) {
-        return true;
-      }
-      return false;
-    }
   }
+  // computed: {
+  //   checkLoggedIn() {
+  //     console.log(this.checkSession());
+  //     if (this.checkSession() === true) {
+  //       return true;
+  //     }
+  //     return false;
+  //   }
+  // }
 };
 </script>
 
diff --git a/frontend/src/components/login/Login.vue b/frontend/src/components/login/Login.vue
index 4ace51f..9d27c96 100644
--- a/frontend/src/components/login/Login.vue
+++ b/frontend/src/components/login/Login.vue
@@ -13,10 +13,8 @@
         <md-input v-model="user.password" type="password" />
       </md-field>
 
-      <md-button class="md-primary" v-on:click="login">Login</md-button>
-      <md-button class="md-primary" v-on:click="active = false"
-        >Close</md-button
-      >
+      <md-button class="md-raised md-primary" v-on:click="login">Login</md-button>
+      <md-button class="md-primary" v-on:click="active = false">Close</md-button>
     </md-dialog>
   </div>
 </template>
@@ -27,6 +25,7 @@ import VueMaterial from "vue-material";
 import "vue-material/dist/vue-material.min.css";
 import "vue-material/dist/theme/default.css";
 Vue.use(VueMaterial);
+
 export default {
   data: function() {
     return {
@@ -50,6 +49,7 @@ export default {
             alert("success login");
             //this.$router.push("Logout");
             this.active = false;
+            location.reload();
           },
           error => {
             // error 를 보여줌
diff --git a/frontend/src/components/login/Logout.vue b/frontend/src/components/login/Logout.vue
index a76e5d2..025fa9c 100644
--- a/frontend/src/components/login/Logout.vue
+++ b/frontend/src/components/login/Logout.vue
@@ -20,7 +20,9 @@ export default {
       console.log("Logout start");
       this.$http.get("/api/login/logout").then(response => {
         if (response) {
+          alert("success logout");
           //this.$router.push("home");
+          location.reload();
         }
       });
     }
-- 
GitLab