trust-auth.component.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { Component, OnInit, Inject } from '@angular/core';
  17. import { ActivatedRoute, Router } from '@angular/router';
  18. import { ReuseTabService } from '@delon/abc/reuse-tab';
  19. import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
  20. import { SettingsService } from '@delon/theme';
  21. import { AuthnService } from '../../service/authn.service';
  22. @Component({
  23. selector: 'app-trust-auth',
  24. template: ``
  25. })
  26. export class TrustAuthComponent implements OnInit {
  27. ticket = '';
  28. constructor(
  29. private authnService: AuthnService,
  30. @Inject(ReuseTabService)
  31. private reuseTabService: ReuseTabService,
  32. private router: Router,
  33. private settingsSrv: SettingsService,
  34. private route: ActivatedRoute
  35. ) {}
  36. ngOnInit(): void {
  37. this.ticket = this.route.snapshot.queryParams['ticket'];
  38. this.authnService.trustAuth({ ticket: this.ticket }).subscribe(res => {
  39. if (res.code !== 0) {
  40. this.router.navigateByUrl('/passport/login');
  41. } else {
  42. // 清空路由复用信息
  43. this.reuseTabService.clear();
  44. // 设置用户Token信息
  45. this.authnService.auth(res.data);
  46. this.authnService.navigate({});
  47. }
  48. });
  49. }
  50. }