#216 done by using return-to URL mechanism

This commit is contained in:
Cindy Chang
2024-06-11 11:57:33 +08:00
parent 444b7d6975
commit aa1dbfabf2
4 changed files with 46 additions and 19 deletions

View File

@@ -5,7 +5,7 @@
<DspLogo /> <DspLogo />
</figure> </figure>
<div class="flex justify-between items-center" v-show="showMember"> <div class="flex justify-between items-center" v-show="showMember">
<button class="btn btn-sm btn-neutral mr-2" @click.prevent="logOutButton"> <button id="logout_btn" class="btn btn-sm btn-neutral mr-2" @click.prevent="logOutButton">
Logout Logout
</button> </button>
<!-- <figure> <!-- <figure>
@@ -56,9 +56,12 @@ export default {
// 傳給 Map通知 Sidebar 要關閉。 // 傳給 Map通知 Sidebar 要關閉。
this.$emitter.emit('leaveFilter', false); this.$emitter.emit('leaveFilter', false);
leaveFilter(false, this.allMapDataStore.addFilterId, false, this.logOut) leaveFilter(false, this.allMapDataStore.addFilterId, false, this.logOut)
} else if((this.$route.name === 'Conformance' || this.$route.name === 'CheckConformance') && (this.conformanceLogTempCheckId || this.conformanceFilterTempCheckId)) { } else if((this.$route.name === 'Conformance' || this.$route.name === 'CheckConformance')
&& (this.conformanceLogTempCheckId || this.conformanceFilterTempCheckId)) {
leaveConformance(false, this.conformanceStore.addConformanceCreateCheckId, false, this.logOut) leaveConformance(false, this.conformanceStore.addConformanceCreateCheckId, false, this.logOut)
} else this.logOut(); } else {
this.logOut();
}
}, },
}, },
mounted() { mounted() {

View File

@@ -1,4 +1,4 @@
import { createRouter, createWebHistory, createWebHashHistory } from "vue-router"; import { createRouter, createWebHistory, } from "vue-router";
import AuthContainer from '@/views/AuthContainer.vue'; import AuthContainer from '@/views/AuthContainer.vue';
import MainContainer from '@/views/MainContainer.vue'; import MainContainer from '@/views/MainContainer.vue';
import Login from '@/views/Login/index.vue'; import Login from '@/views/Login/index.vue';
@@ -120,14 +120,6 @@ const routes = [
} }
] ]
}, },
{
path: "/rule/:type/:fileId/conformance/:checkId",
name: "CheckConformance",
component: Conformance,
meta: {
file: {},
}
}
] ]
}, },
{ {

View File

@@ -14,6 +14,8 @@ export default defineStore('loginStore', {
}, },
isInvalid: false, isInvalid: false,
userData: {}, userData: {},
isLoggedIn: false,
rememberedReturnToUrl: "",
// expired: new Date().setMonth(6), // 設定 Refresh Token 的到期日為半年後 // expired: new Date().setMonth(6), // 設定 Refresh Token 的到期日為半年後
}), }),
actions: { actions: {
@@ -38,7 +40,18 @@ export default defineStore('loginStore', {
document.cookie = `luciaToken=${accessToken}`; document.cookie = `luciaToken=${accessToken}`;
// document.cookie = `luciaRefreshToken=${refreshToken};expires=${new Date(this.expired)};`; // document.cookie = `luciaRefreshToken=${refreshToken};expires=${new Date(this.expired)};`;
this.$router.push('/files'); this.isLoggedIn = true;
// 大部分的情況下,預設導向至 FILES 頁面
// 然而有一種情況是使用者在沒有登入的情況下貼上了某一個頁面的網址,
// 則在此情況下時,我們會在使用者稍後登入後,把使用者帶到剛才記住的 return-to 網址
if(this.rememberedReturnToUrl !== "") {
console.log('1111', );
window.location.href = this.rememberedReturnToUrl;
} else {
console.log('2222', );
this.$router.push('/login');
}
} catch(error) { } catch(error) {
this.isInvalid = true; this.isInvalid = true;
}; };
@@ -72,6 +85,9 @@ export default defineStore('loginStore', {
logOut() { logOut() {
delete axios.defaults.headers.common["Authorization"]; delete axios.defaults.headers.common["Authorization"];
document.cookie = 'luciaToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC;'; document.cookie = 'luciaToken=; expires=Thu, 01 Jan 1970 00:00:00 UTC;';
this.isLoggedIn = false;
this.$router.push('/login'); this.$router.push('/login');
}, },
/** /**
@@ -100,5 +116,8 @@ export default defineStore('loginStore', {
this.$router.push('/login'); this.$router.push('/login');
}; };
}, },
setRememberedReturnToUrl(returnToUrl){
this.rememberedReturnToUrl = returnToUrl
}
} }
}); });

View File

@@ -9,25 +9,33 @@
<span class="absolute flex bottom-1 left-0 items-center pl-2 pr-2 border-r border-neutral-300 h-[26px]"> <span class="absolute flex bottom-1 left-0 items-center pl-2 pr-2 border-r border-neutral-300 h-[26px]">
<IconMember class="h-5 w-5 fill-current"/> <IconMember class="h-5 w-5 fill-current"/>
</span> </span>
<input type="text" id="account" class="w-full border border-neutral-300 rounded py-1 pl-10 pr-2 focus:outline-none focus:border-primary focus:ring-1 " :class="{'border-danger':isInvalid}" required autofocus v-model.trim="auth.username" @change="changeHandler($event)"/> <input type="text" id="account" class="w-full border border-neutral-300 rounded py-1 pl-10 pr-2 focus:outline-none focus:border-primary focus:ring-1 "
:class="{'border-danger':isInvalid}" required autofocus v-model.trim="auth.username"
@change="changeHandler($event)"/>
</label> </label>
<label for="passwordt" class="relative block"> <label for="passwordt" class="relative block">
<p class="text-sm font-normal mb-2">Password</p> <p class="text-sm font-normal mb-2">Password</p>
<span class="absolute flex bottom-1 left-0 items-center pl-2 pr-2 border-r border-neutral-300 h-[26px]"> <span class="absolute flex bottom-1 left-0 items-center pl-2 pr-2 border-r border-neutral-300 h-[26px]">
<IconLockKey class="h-5 w-5 fill-current"/> <IconLockKey class="h-5 w-5 fill-current"/>
</span> </span>
<input :type="showPassword ? 'text' : 'password'" id="password" aria-describedby="password-addon" class="w-full border border-neutral-300 rounded py-1 pl-10 pr-2 focus:outline-none focus:border-primary focus:ring-1 " :class="{'border-danger':isInvalid}" required v-model.trim="auth.password" @change="changeHandler($event)"/> <input :type="showPassword ? 'text' : 'password'" id="password" aria-describedby="password-addon"
<span class="absolute bottom-2 right-4 inline-flex items-center cursor-pointer" v-show="auth.password" @click="showPassword = !showPassword"> class="w-full border border-neutral-300 rounded py-1 pl-10 pr-2 focus:outline-none focus:border-primary focus:ring-1 "
:class="{'border-danger':isInvalid}" required v-model.trim="auth.password" @change="changeHandler($event)"/>
<span class="absolute bottom-2 right-4 inline-flex items-center cursor-pointer" v-show="auth.password"
@click="showPassword = !showPassword">
<IconEyeOpen class="h-5 w-5" v-if="showPassword"/> <IconEyeOpen class="h-5 w-5" v-if="showPassword"/>
<IconEyeClose class="h-5 w-5" v-else/> <IconEyeClose class="h-5 w-5" v-else/>
</span> </span>
</label> </label>
<p class="my-4 text-danger"> <p class="my-4 text-danger">
<span v-show="isInvalid"> <span v-show="isInvalid">
<IconWarnTriangle class="h-4 w-5 mx-2 mb-[2px] inline-block text-danger"/>Incorrect account or password. <IconWarnTriangle class="h-4 w-5 mx-2 mb-[2px] inline-block text-danger"/>
Incorrect account or password.
</span> </span>
</p> </p>
<button type="submit" class="w-full btn btn-lg" :class="this.isDisabled ? 'btn-disable' : 'btn-c-primary'" :disabled="isDisabledButton"> <button id="login_btn_main_btn" type="submit" class="w-full btn btn-lg"
:class="this.isDisabled ? 'btn-disable' : 'btn-c-primary'"
:disabled="isDisabledButton">
Log in Log in
</button> </button>
</form> </form>
@@ -37,7 +45,7 @@
</template> </template>
<script> <script>
import { storeToRefs } from 'pinia'; import { storeToRefs, mapActions } from 'pinia';
import loginStore from '@/stores/login.js'; import loginStore from '@/stores/login.js';
import IconMember from '@/components/icons/IconMember.vue'; import IconMember from '@/components/icons/IconMember.vue';
import IconLockKey from '@/components/icons/IconLockKey.vue'; import IconLockKey from '@/components/icons/IconLockKey.vue';
@@ -93,6 +101,11 @@ export default {
this.isInvalid = false; this.isInvalid = false;
} }
}, },
...mapActions(loginStore, ['setRememberedReturnToUrl']),
},
created() {
// 考慮到使用者可能在未登入的情況下貼入一個頁面網址連結過來瀏覽器
this.setRememberedReturnToUrl(this.$route.query['return-to']);
}, },
}; };
</script> </script>