mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 20:50:14 +08:00
rememberme
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const CONSTS = {
|
||||
CONGRESS: 'congress',
|
||||
REDIRECT_URI: 'redirect_uri',
|
||||
REMEMBER: 'remember'
|
||||
REMEMBER: 'remember_me'
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user