src/app/shared/login/login.component.ts

Implements

OnInit OnDestroy

Metadata

Relationships

Used by

Depends on

Index

Properties
Methods

Constructor

constructor(sasService: SasService, loggerService: LoggerService)
Parameters :
Name Type Optional
sasService SasService No
loggerService LoggerService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
Public submit
submit()
Returns : void

Properties

Private _subscription
Type : Subscription
Default value : new Subscription()
Public alertClosed
Type : boolean
Default value : true
Public data
Type : User
Default value : { user: null, pass: null }
Public errorMsg
Type : string | undefined
Public isActive
Type : boolean | undefined
Public loading
Type : boolean
Default value : false
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core'
import { LoggerService } from '../../services/logger.service'
import { Subscription } from 'rxjs'

import { SasService } from '../../services/sas.service'

interface User {
  user: string | null
  pass: string | null
}

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss'],
  encapsulation: ViewEncapsulation.None,
  standalone: false
})
export class LoginComponent implements OnInit, OnDestroy {
  private _subscription: Subscription = new Subscription()
  public isActive: boolean | undefined
  public loading: boolean = false
  public alertClosed: boolean = true
  public errorMsg: string | undefined
  public data: User = {
    user: null,
    pass: null
  }

  constructor(
    private sasService: SasService,
    private loggerService: LoggerService
  ) {}

  ngOnInit() {
    let sasjsConfig = this.sasService.getSasjsConfig()

    if (sasjsConfig.loginMechanism !== 'Redirected') {
      this._subscription = this.sasService.shouldLogin.subscribe(
        (shouldLogin) => {
          this.isActive = shouldLogin

          let bodyEl = document.querySelector('body')

          if (!bodyEl) return

          if (shouldLogin) {
            bodyEl.classList.add('should-login')
          } else {
            bodyEl.classList.remove('should-login')
          }
        }
      )
    }
  }

  ngOnDestroy() {
    this._subscription.unsubscribe()
  }

  public submit() {
    if (this.loading) {
      return
    }

    this.loading = true

    if (this.data.user && this.data.pass) {
      this.sasService.login(this.data.user, this.data.pass).then(
        (isLoggedIn: any) => {
          this.loading = false

          if (!isLoggedIn) {
            this.errorMsg = 'Username or password invalid'
            this.alertClosed = false
          }
        },
        (err: any) => {
          this.loggerService.log(err)

          this.loading = false
          this.errorMsg = err
          this.alertClosed = false
        }
      )
    }
  }
}
<div class="login-sidebar-wrapper" [class.active]="isActive">
  <div class="login-sidebar sideBarProps">
    <!--img src="images/data_controller.png" alt=""-->
    <img
      class="login-logo"
      src="images/datacontroller.svg"
      alt="datacontroller logo"
    />

    <form class="login" (ngSubmit)="submit()">
      <label class="title">
        <h3 class="welcome">Welcome to</h3>
        Data Controller
        <h4 class="hint">Capture, Review, and Approve</h4>
      </label>
      <div class="login-group">
        <input
          clrInput
          [(ngModel)]="data.user"
          name="user"
          class="username"
          type="text"
          placeholder="Username"
        />
        <input
          clrInput
          [(ngModel)]="data.pass"
          name="pass"
          class="password"
          type="password"
          placeholder="Password"
        />
        <clr-alert
          [clrAlertType]="'alert-danger'"
          [(clrAlertClosed)]="alertClosed"
        >
          <div clr-alert-item class="alert-item">
            <span class="alert-text">{{ errorMsg }}</span>
          </div>
        </clr-alert>
        <button
          [clrLoading]="loading"
          [disabled]="loading"
          type="submit"
          class="btn btn-sm btn-success"
        >
          Log in
        </button>
      </div>
    </form>
  </div>
  <div class="overlay"></div>
</div>

./login.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""