src/app/shared/login/login.component.ts
| encapsulation | ViewEncapsulation.None |
| selector | app-login |
| styleUrls | ./login.component.scss |
| templateUrl | ./login.component.html |
Properties |
|
Methods |
|
constructor(sasService: SasService, loggerService: LoggerService)
|
|||||||||
|
Defined in src/app/shared/login/login.component.ts:28
|
|||||||||
|
Parameters :
|
| ngOnDestroy |
ngOnDestroy()
|
|
Defined in src/app/shared/login/login.component.ts:57
|
|
Returns :
void
|
| ngOnInit |
ngOnInit()
|
|
Defined in src/app/shared/login/login.component.ts:35
|
|
Returns :
void
|
| Public submit |
submit()
|
|
Defined in src/app/shared/login/login.component.ts:61
|
|
Returns :
void
|
| Private _subscription |
Type : Subscription
|
Default value : new Subscription()
|
|
Defined in src/app/shared/login/login.component.ts:20
|
| Public alertClosed |
Type : boolean
|
Default value : true
|
|
Defined in src/app/shared/login/login.component.ts:23
|
| Public data |
Type : User
|
Default value : {
user: null,
pass: null
}
|
|
Defined in src/app/shared/login/login.component.ts:25
|
| Public errorMsg |
Type : string | undefined
|
|
Defined in src/app/shared/login/login.component.ts:24
|
| Public isActive |
Type : boolean | undefined
|
|
Defined in src/app/shared/login/login.component.ts:21
|
| Public loading |
Type : boolean
|
Default value : false
|
|
Defined in src/app/shared/login/login.component.ts:22
|
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