14 changed files with 365 additions and 16 deletions
@ -0,0 +1,79 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 The Thingsboard Authors |
|||
|
|||
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. |
|||
|
|||
--> |
|||
<div class="tb-two-factor-auth-login-content mat-app-background tb-dark" fxLayout="row" fxLayoutAlign="center center" |
|||
style="width: 100%;"> |
|||
<mat-card fxFlex="initial" class="tb-two-factor-auth-login-card" > |
|||
<mat-card-title class="mat-headline" fxLayout="row" fxLayoutAlign="start center"> |
|||
<button mat-icon-button type="button" (click)="cancelLogin()"> |
|||
<mat-icon>chevron_left</mat-icon> |
|||
</button> |
|||
{{ 'login.verify-your-identity' | translate }} |
|||
</mat-card-title> |
|||
<mat-card-content> |
|||
<div class="providers-container tb-default" fxLayout="column" fxLayoutGap="8px" *ngIf="!selectedProvider"> |
|||
<p class="mat-body" translate>login.select-way-to-verify</p> |
|||
<ng-container *ngFor="let provider of allowProviders"> |
|||
<button type="button" mat-stroked-button class="provider" (click)="selectProvider(provider)"> |
|||
<mat-icon class="icon" svgIcon="{{ providersData.get(provider).icon }}"></mat-icon> |
|||
{{ providersData.get(provider).name | translate }} |
|||
</button> |
|||
</ng-container> |
|||
</div> |
|||
<form [formGroup]="verificationForm" (ngSubmit)="sendVerificationCode()" *ngIf="selectedProvider"> |
|||
<fieldset [disabled]="isLoading$ | async"> |
|||
<div tb-toast fxLayout="column"> |
|||
<p class="mat-body">{{ providerDescription }}</p> |
|||
<div fxLayout="row" class="code-block" fxLayoutGap="8px"> |
|||
<mat-form-field class="mat-block" fxFlex floatLabel="always" hideRequiredMarker> |
|||
<mat-label></mat-label> |
|||
<input matInput formControlName="verificationCode" |
|||
required maxlength="6" type="text" pattern="\d*" |
|||
placeholder="{{ 'security.2fa.dialog.verification-code' | translate }}"/> |
|||
<mat-error *ngIf="verificationForm.get('verificationCode').invalid"> |
|||
{{ 'security.2fa.dialog.verification-code-invalid' | translate }} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<div fxLayoutAlign="start center" *ngIf="selectedProvider !== twoFactorAuthProvider.TOTP"> |
|||
<button |
|||
mat-button |
|||
(click)="sendCode()" |
|||
type="button"> |
|||
{{ 'login.resend-code' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
<span style="height: 40px;"></span> |
|||
<div fxLayout="column" fxLayoutGap="8px"> |
|||
<button mat-raised-button |
|||
color="accent" |
|||
[disabled]="(isLoading$ | async) || verificationForm.invalid" |
|||
type="submit"> |
|||
{{ 'action.continue' | translate }} |
|||
</button> |
|||
<button mat-button |
|||
type="button" |
|||
(click)="selectProvider(null)"> |
|||
{{ 'login.try-another-way' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
</fieldset> |
|||
</form> |
|||
</mat-card-content> |
|||
</mat-card> |
|||
</div> |
|||
@ -0,0 +1,66 @@ |
|||
/** |
|||
* Copyright © 2016-2022 The Thingsboard Authors |
|||
* |
|||
* 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 '../../../../../scss/constants'; |
|||
|
|||
:host { |
|||
display: flex; |
|||
flex: 1 1 0; |
|||
.tb-two-factor-auth-login-content { |
|||
background-color: #eee; |
|||
.tb-two-factor-auth-login-card { |
|||
padding: 48px 48px 48px 16px; |
|||
|
|||
@media #{$mat-gt-xs} { |
|||
width: 450px !important; |
|||
} |
|||
|
|||
.mat-card-title{ |
|||
font: 500 28px / 36px Roboto, "Helvetica Neue", sans-serif; |
|||
} |
|||
|
|||
.mat-card-content { |
|||
margin-top: 44px; |
|||
margin-left: 40px; |
|||
} |
|||
|
|||
.mat-body { |
|||
letter-spacing: 0.25px; |
|||
line-height: 16px; |
|||
margin: 0; |
|||
} |
|||
|
|||
.code-block { |
|||
margin-top: 16px; |
|||
} |
|||
|
|||
.providers-container{ |
|||
padding: 0; |
|||
|
|||
.mat-body { |
|||
padding-bottom: 8px; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
::ng-deep{ |
|||
button.provider { |
|||
text-align: start; |
|||
&:not(.mat-button-disabled) { |
|||
border-color: rgba(255, 255, 255, .8); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,109 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 The Thingsboard Authors
|
|||
///
|
|||
/// 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 { Component, OnInit } from '@angular/core'; |
|||
import { AuthService } from '@core/auth/auth.service'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { PageComponent } from '@shared/components/page.component'; |
|||
import { FormBuilder, Validators } from '@angular/forms'; |
|||
import { TwoFactorAuthenticationService } from '@core/http/two-factor-authentication.service'; |
|||
import { |
|||
twoFactorAuthProvidersLoginData, |
|||
TwoFactorAuthProviderType, |
|||
TwoFaProviderInfo |
|||
} from '@shared/models/two-factor-auth.models'; |
|||
import { TranslateService } from '@ngx-translate/core'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-two-factor-auth-login', |
|||
templateUrl: './two-factor-auth-login.component.html', |
|||
styleUrls: ['./two-factor-auth-login.component.scss'] |
|||
}) |
|||
export class TwoFactorAuthLoginComponent extends PageComponent implements OnInit { |
|||
|
|||
private providersInfo: TwoFaProviderInfo[]; |
|||
|
|||
selectedProvider: TwoFactorAuthProviderType; |
|||
twoFactorAuthProvider = TwoFactorAuthProviderType; |
|||
allowProviders: TwoFactorAuthProviderType[] = []; |
|||
|
|||
providersData = twoFactorAuthProvidersLoginData; |
|||
providerDescription = ''; |
|||
|
|||
verificationForm = this.fb.group({ |
|||
verificationCode: ['', [ |
|||
Validators.required, |
|||
Validators.minLength(6), |
|||
Validators.maxLength(6), |
|||
Validators.pattern(/^\d*$/) |
|||
]] |
|||
}); |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
private twoFactorAuthService: TwoFactorAuthenticationService, |
|||
private authService: AuthService, |
|||
private translate: TranslateService, |
|||
private fb: FormBuilder) { |
|||
super(store); |
|||
} |
|||
|
|||
ngOnInit() { |
|||
this.providersInfo = this.authService.twoFactorAuthProviders; |
|||
Object.values(TwoFactorAuthProviderType).forEach(provider => { |
|||
const providerConfig = this.providersInfo.find(config => config.type === provider); |
|||
if (providerConfig) { |
|||
if (providerConfig.default) { |
|||
this.selectedProvider = providerConfig.type; |
|||
this.providerDescription = this.translate.instant(this.providersData.get(providerConfig.type).description, { |
|||
contact: providerConfig.contact |
|||
}); |
|||
} |
|||
this.allowProviders.push(providerConfig.type); |
|||
} |
|||
}); |
|||
if (this.selectedProvider !== TwoFactorAuthProviderType.TOTP) { |
|||
this.sendCode(); |
|||
} |
|||
} |
|||
|
|||
sendVerificationCode() { |
|||
if (this.verificationForm.valid && this.selectedProvider) { |
|||
this.authService.checkTwoFaVerificationCode(this.selectedProvider, this.verificationForm.get('verificationCode').value).subscribe( |
|||
() => {} |
|||
); |
|||
} |
|||
} |
|||
|
|||
selectProvider(type: TwoFactorAuthProviderType) { |
|||
this.selectedProvider = type; |
|||
const providerConfig = this.providersInfo.find(config => config.type === type); |
|||
this.providerDescription = this.translate.instant(this.providersData.get(providerConfig.type).description, { |
|||
contact: providerConfig.contact |
|||
}); |
|||
if (type !== TwoFactorAuthProviderType.TOTP && type !== null) { |
|||
this.sendCode(); |
|||
} |
|||
} |
|||
|
|||
sendCode() { |
|||
this.twoFactorAuthService.requestTwoFaVerificationCodeSend(this.selectedProvider).subscribe(() => {}); |
|||
} |
|||
|
|||
cancelLogin() { |
|||
this.authService.logout(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue