mirror of
https://gitee.com/dromara/MaxKey.git
synced 2026-05-14 12:32:09 +08:00
Logout optimize
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
/*
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
|
||||
import { SettingsService, User } from '@delon/theme';
|
||||
import { environment } from '@env/environment';
|
||||
|
||||
@Component({
|
||||
selector: 'header-user',
|
||||
@@ -74,10 +74,11 @@ export class HeaderUserComponent {
|
||||
return this.settings.user;
|
||||
}
|
||||
|
||||
constructor(private settings: SettingsService, private router: Router, @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) {}
|
||||
constructor(private settings: SettingsService, private router: Router, @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService) { }
|
||||
|
||||
logout(): void {
|
||||
this.tokenService.clear();
|
||||
this.router.navigateByUrl(this.tokenService.login_url!);
|
||||
//this.tokenService.clear();
|
||||
//this.router.navigateByUrl(this.tokenService.login_url!);
|
||||
window.location.href = `${environment.api.baseUrl}force/logout`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Inject, Optional, Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { ReuseTabService } from '@delon/abc/reuse-tab';
|
||||
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
|
||||
import { SettingsService } from '@delon/theme';
|
||||
|
||||
import { AuthnService } from '../../service/authn.service';
|
||||
import { SocialsProviderService } from '../../service/socials-provider.service';
|
||||
import { CONSTS } from '../../shared/consts';
|
||||
|
||||
@Component({
|
||||
selector: 'app-logout',
|
||||
template: ``
|
||||
})
|
||||
export class LogoutComponent implements OnInit {
|
||||
redirect_uri = '';
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private settingsService: SettingsService,
|
||||
private authnService: AuthnService,
|
||||
@Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
|
||||
@Optional()
|
||||
@Inject(ReuseTabService)
|
||||
private reuseTabService: ReuseTabService,
|
||||
private route: ActivatedRoute
|
||||
) { }
|
||||
|
||||
ngOnInit(): void {
|
||||
this.redirect_uri = this.route.snapshot.params[CONSTS.REDIRECT_URI];
|
||||
this.authnService.logout();
|
||||
this.tokenService.clear();
|
||||
if (this.redirect_uri == null || this.redirect_uri == '') {
|
||||
this.router.navigateByUrl(this.tokenService.login_url!);
|
||||
} else {
|
||||
this.router.navigateByUrl(this.redirect_uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import { ForgotComponent } from './forgot/forgot.component';
|
||||
import { JwtAuthComponent } from './jwt-auth.component';
|
||||
import { UserLockComponent } from './lock/lock.component';
|
||||
import { UserLoginComponent } from './login/login.component';
|
||||
import { LogoutComponent } from './logout.component';
|
||||
import { UserRegisterResultComponent } from './register-result/register-result.component';
|
||||
import { UserRegisterComponent } from './register/register.component';
|
||||
|
||||
@@ -61,7 +62,8 @@ const routes: Routes = [
|
||||
},
|
||||
// 单页不包裹Layout
|
||||
{ path: 'passport/callback/:provider', component: CallbackComponent },
|
||||
{ path: 'passport/jwt/auth', component: JwtAuthComponent }
|
||||
{ path: 'passport/jwt/auth', component: JwtAuthComponent },
|
||||
{ path: 'passport/logout', component: LogoutComponent }
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
|
||||
@@ -61,6 +61,12 @@ export class AuthnService {
|
||||
return this.http.post('/login/signin?_allow_anonymous=true', authParam);
|
||||
}
|
||||
|
||||
//退出
|
||||
logout() {
|
||||
this.cookieService.delete(CONSTS.CONGRESS);
|
||||
return this.http.get('/login/logout');
|
||||
}
|
||||
|
||||
congress(authParam: any) {
|
||||
return this.http.post('/login/congress?_allow_anonymous=true', authParam);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ export const environment = {
|
||||
production: false,
|
||||
useHash: true,
|
||||
api: {
|
||||
baseUrl: 'http://sso.maxkey.top:9527/sign',
|
||||
baseUrl: 'http://sso.maxkey.top:9527/sign/',
|
||||
refreshTokenEnabled: true,
|
||||
refreshTokenType: 're-request'
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user