Browse Source

登入Remember Me功能增加時效

Dev
Janie 2 years ago
parent
commit
9f29fdc01f
  1. 3
      FrontEnd/pages/user/editPersonalInfo.vue
  2. 38
      FrontEnd/pages/user/index.vue

3
FrontEnd/pages/user/editPersonalInfo.vue

@ -303,7 +303,6 @@ export default {
this.yearOptions = Array.from(new Array(103), (val, index) =>
(index + 1920).toString()
);
console.log(this.yearOptions);
this.monthOptions = Array.from(new Array(13), (val, index) => {
if (index < 10 && index > 0) {
return "0" + index.toString();
@ -398,7 +397,7 @@ export default {
`/trending/api/Members/Info`
)
.then((response) => {
console.log(response);
//console.log(response);
if(response && response.data && response.data.DATA && response.data.DATA.rel){
let data = response.data.DATA.rel
if(data){

38
FrontEnd/pages/user/index.vue

@ -176,6 +176,7 @@
},
deleteDialog: false,
dialog: false,
expireTime: new Date(),
}
},
watch: {
@ -192,7 +193,10 @@
},
},
created(){
if(this.$auth.$storage.getUniversal('userAccount') && this.$auth.$storage.getUniversal('userPassword')){
this.checkExpireTime();
}
},
mounted(){
if(this.$auth.$storage.getUniversal('userAccount') && this.$auth.$storage.getUniversal('userPassword')){
@ -236,6 +240,9 @@
that.$auth.$storage.setUniversal('authtoken', authtoken);
that.$auth.loggedIn ? that.$router.push({path: that.$auth.$storage.getUniversal('userBeforePath')}) : that.$auth.redirect('login');
}
}else if(response.data.STATUSCODE==200 && this.remember == true){
}else if(response.data.STATUSCODE==500){
that.$auth.redirect('login');
}else if(response.data.STATUSCODE==401){
@ -299,6 +306,35 @@
this.valid = false;
}
},
checkExpireTime(){
console.log("給我時間");
console.log("帳號:" + this.$auth.$storage.getUniversal('userAccount'));
this.$axios
.get(`/trending/api/System/RememberMe?Account=${this.$auth.$storage.getUniversal('userAccount')}`)
.then((response) => {
//console.log(response);
const data = response.data.DATA.authtoken;
this.expireTime = new Date(data.ExpireTime);
const now = new Date(Date.now());
const saveTime = this.expireTime - now;
if(saveTime >= 0){
const hour = saveTime / (60 * 60 * 1000);
if(hour == 0){
this.$auth.$storage.removeUniversal('userPassword');
this.$auth.$storage.removeUniversal('userAccount');
}
}else{
this.$auth.$storage.removeUniversal('userPassword');
this.$auth.$storage.removeUniversal('userAccount');
}
})
.catch((error) => {
console.log(error);
});
}
},
beforeUnmount() {
if(this.timer!=null){

Loading…
Cancel
Save