|
@@ -51,14 +51,12 @@
|
|
|
<li class="nav-item">
|
|
|
<a class="nav-link active btn-login" aria-current="page" href="login.html" set-lan="html:login">登入</a>
|
|
|
</li>
|
|
|
- <!--
|
|
|
<li class="nav-item">
|
|
|
- <a class="nav-link btn-userProfile" aria-current="page" href="user_profile.html" set-lan="html:user_profile">會員資料</a>
|
|
|
+ <a class="nav-link btn-userProfile" aria-current="page" href="user_profile2.html" set-lan="html:user_profile">會員資料</a>
|
|
|
</li>
|
|
|
<li class="nav-item">
|
|
|
<a class="nav-link btn-logout" aria-current="page" set-lan="html:logout">登出</a>
|
|
|
</li>
|
|
|
- -->
|
|
|
</ul>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -156,6 +154,48 @@
|
|
|
<script src="static/owl.carousel.min.js"></script>
|
|
|
<script type="text/javascript" src="static/lan.js"></script>
|
|
|
<script src="static/common.js"></script>
|
|
|
+ <script>
|
|
|
+ const btnLoginPage = document.querySelector('.btn-login');
|
|
|
+ const btnUserProfile = document.querySelector('.btn-userProfile');
|
|
|
+ const btnLogout = document.querySelector('.btn-logout');
|
|
|
+ function get_jwt_token(){
|
|
|
+ if(!document.cookie) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ jwt_raw = document.cookie.split(';').filter(s=>s.includes('jwt_token'))[0]
|
|
|
+ return jwt_raw.split('=')[1]
|
|
|
+ }
|
|
|
+ function checkRoute() {
|
|
|
+ let jwt_token = get_jwt_token();
|
|
|
+ if(jwt_token == undefined) {
|
|
|
+ btnLoginPage.style.display = 'block';
|
|
|
+ btnLogout.style.display = 'none';
|
|
|
+ btnUserProfile.style.display = 'none';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ axios({
|
|
|
+ method: 'post',
|
|
|
+ url: 'https://www.choozmo.com:8887/user_profile',
|
|
|
+ headers: {
|
|
|
+ 'accept': 'text/html',
|
|
|
+ 'Authorization': `Bearer ${jwt_token}`
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res.data);
|
|
|
+ if(res.status !== 200) {
|
|
|
+ btnLoginPage.style.display = 'block';
|
|
|
+ btnLogout.style.display = 'none';
|
|
|
+ btnUserProfile.style.display = 'none';
|
|
|
+ }
|
|
|
+ btnLoginPage.style.display = 'none';
|
|
|
+ btnLogout.style.display = 'block';
|
|
|
+ btnUserProfile.style.display = 'block';
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ checkRoute();
|
|
|
+ </script>
|
|
|
</body>
|
|
|
|
|
|
</html>
|