File

src/app/auth/containers/login/login.component.ts

Implements

OnInit

Metadata

selector app-login
templateUrl ./login.component.html

Index

Properties
Methods

Constructor

constructor(authService: AuthService, activatedRoute: ActivatedRoute, router: Router)
Parameters :
Name Type Optional
authService AuthService No
activatedRoute ActivatedRoute No
router Router No

Methods

login
login()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

__
Default value : strings
loading
Default value : false
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {first} from 'rxjs/operators';
import {AuthService} from '@app/auth/services/auth.service';
import {Roles} from '@app/auth/enums/roles.enum';
import strings from '@i18n/strings.json';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
})

export class LoginComponent implements OnInit {

  __ = strings;

  loading = false;

  constructor(
    private authService: AuthService,
    private activatedRoute: ActivatedRoute,
    private router: Router
  ) {}

  ngOnInit() {
    this.activatedRoute.queryParams.pipe(first()).subscribe(params => {
      const {code} = params;
      let {returnUrl} = params;

      if (returnUrl) {
        localStorage.setItem('returnUrl', returnUrl);
      }

      if (code) {
        this.loading = true;
        this.authService.processLogin(code).pipe(first())
          .subscribe(
            () => {
              const currentUser = this.authService.currentDecodedUserValue;
              returnUrl = localStorage.getItem('returnUrl');
              if (returnUrl) {
                this.router.navigateByUrl(returnUrl);
              } else {
                if (currentUser.role !== Roles.SYSTEM_ADMIN) {
                  this.router.navigateByUrl('projects');
                } else {
                  this.router.navigateByUrl('global-clients');
                }
              }
            },
            error => {
              console.log(error);
              this.loading = false;
            }
          );
      }
    });
  }

  login() {
    this.loading = true;
    this.authService.authorize();
  }
}
<div class="py-5">
  <div class="row">
    <div class="col text-center">
      <h1 class="text-center">{{__.login}}</h1>
    </div>
  </div>
  <div class="row" *ngIf="loading">
    <div class="col text-center">
      <h2 class="text-center">{{__.loading}}</h2>
    </div>
  </div>
  <div class="row">
    <div class="col-md-4 text-center mx-auto" *ngIf="!loading">
      <button class="btn btn-outline-primary btn-block" (click)="login()">{{__.loginWithManagementPortalAdmin}}</button>
    </div>
  </div>
</div>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""