rememberme

This commit is contained in:
MaxKey
2022-04-29 11:58:05 +08:00
parent 8db33b0e8d
commit 5f0f1fa7e0
16 changed files with 550 additions and 72 deletions

View File

@@ -79,27 +79,31 @@ export class UserLoginComponent implements OnInit, OnDestroy {
this.congressLogin(this.route.snapshot.queryParams[CONSTS.CONGRESS]);
}
if (localStorage.getItem(CONSTS.REMEMBER) && localStorage.getItem(CONSTS.REMEMBER)?.endsWith('true')) {
this.authenticationService.navigate({});
//auto auth
} else {
//init socials,state
this.authenticationService.clear();
this.authenticationService
.get({})
.pipe(
finalize(() => {
this.loading = false;
this.cdr.detectChanges();
})
)
.subscribe(res => {
this.loading = true;
if (res.code !== 0) {
this.error = res.msg;
} else {
//init socials,state
this.authenticationService.clear();
this.authenticationService
.get({ remember_me: localStorage.getItem(CONSTS.REMEMBER) })
.pipe(
finalize(() => {
this.loading = false;
this.cdr.detectChanges();
})
)
.subscribe(res => {
this.loading = true;
if (res.code !== 0) {
this.error = res.msg;
} else {
// 清空路由复用信息
//console.log(res.data);
//REMEMBER ME
if (res.data.token) {
// 清空路由复用信息
console.log(res.data);
this.reuseTabService.clear();
// 设置用户Token信息
this.authenticationService.auth(res.data);
this.authenticationService.navigate({});
} else {
this.socials = res.data.socials;
this.state = res.data.state;
this.captchaType = res.data.captchaType;
@@ -109,8 +113,8 @@ export class UserLoginComponent implements OnInit, OnDestroy {
this.cdr.detectChanges();
});
}
});
}
}
});
this.cdr.detectChanges();
}
@@ -156,6 +160,11 @@ export class UserLoginComponent implements OnInit, OnDestroy {
get otpCaptcha(): AbstractControl {
return this.form.get('otpCaptcha')!;
}
get remember(): AbstractControl {
return this.form.get('remember')!;
}
// #endregion
// #region get captcha
@@ -224,7 +233,8 @@ export class UserLoginComponent implements OnInit, OnDestroy {
password: this.password.value,
captcha: this.captcha.value,
mobile: this.mobile.value,
otpCaptcha: this.otpCaptcha.value
otpCaptcha: this.otpCaptcha.value,
remeberMe: this.remember.value
})
.pipe(
finalize(() => {

View File

@@ -47,6 +47,7 @@ export class AuthenticationService {
clear() {
this.tokenService.clear();
localStorage.setItem(CONSTS.REMEMBER, '');
}
clearUser() {
@@ -73,7 +74,9 @@ export class AuthenticationService {
this.cookieService.set(CONSTS.CONGRESS, authJwt.token);
this.cookieService.set(CONSTS.CONGRESS, authJwt.ticket, { domain: subHostName });
if (authJwt.remeberMe) {
localStorage.setItem(CONSTS.REMEMBER, authJwt.remeberMe);
}
this.settingsService.setUser(user);
this.tokenService.set(authJwt);
this.tokenService.get()?.expired;

View File

@@ -1,5 +1,5 @@
export const CONSTS = {
CONGRESS: 'congress',
REDIRECT_URI: 'redirect_uri',
REMEMBER: 'remember'
REMEMBER: 'remember_me'
};