-
Notifications
You must be signed in to change notification settings - Fork 1
Port Personal Two-Factor Setup to Angular #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nllong
wants to merge
7
commits into
main
Choose a base branch
from
port-personal-two-factor-setup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb7aaa4
Port Personal Two-Factor Setup page to Angular
nllong 29f227b
Potential fix for pull request finding
kflemin 267ecc5
Potential fix for pull request finding
kflemin 17cd72a
Merge branch 'main' into port-personal-two-factor-setup
kflemin 5be4108
Show server-side verification error inline on form control
Copilot 5fc9e85
update translations
kflemin 355207f
wire up 2fa check during login
kflemin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from './two-factor.service' | ||
| export * from './two-factor.types' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import type { HttpErrorResponse } from '@angular/common/http' | ||
| import { HttpClient } from '@angular/common/http' | ||
| import { inject, Injectable } from '@angular/core' | ||
| import type { Observable } from 'rxjs' | ||
| import { catchError } from 'rxjs' | ||
| import { ErrorService } from '@seed/services' | ||
| import type { | ||
| GenerateTwoFactorQrCodeResponse, | ||
| ResendTwoFactorTokenEmailResponse, | ||
| SetTwoFactorMethodResponse, | ||
| TwoFactorMethods, | ||
| VerifyTwoFactorCodeResponse, | ||
| } from './two-factor.types' | ||
|
|
||
| @Injectable({ providedIn: 'root' }) | ||
| export class TwoFactorService { | ||
| private _httpClient = inject(HttpClient) | ||
| private _errorService = inject(ErrorService) | ||
|
|
||
| /** | ||
| * Sets the current user's two-factor method. When enabling the token method for the first | ||
| * time, the response includes a `qr_code` to be verified before the change takes effect. | ||
| */ | ||
| setMethod(orgId: number, userEmail: string, methods: TwoFactorMethods): Observable<SetTwoFactorMethodResponse> { | ||
| const url = '/api/v3/two_factor/set_method/' | ||
| const params = { organization_id: orgId } | ||
| return this._httpClient.post<SetTwoFactorMethodResponse>(url, { user_email: userEmail, methods }, { params }).pipe( | ||
| catchError((error: HttpErrorResponse) => this._errorService.handleError(error, 'Error updating two-factor method')), | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Sends a new two-factor email token to the user (email method only). | ||
| */ | ||
| resendTokenEmail(orgId: number, userEmail: string): Observable<ResendTwoFactorTokenEmailResponse> { | ||
| const url = '/api/v3/two_factor/resend_token_email/' | ||
| const params = { organization_id: orgId } | ||
| return this._httpClient.post<ResendTwoFactorTokenEmailResponse>(url, { user_email: userEmail }, { params }).pipe( | ||
| catchError((error: HttpErrorResponse) => this._errorService.handleError(error, 'Error resending token email')), | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Generates a new QR code to be scanned by an authenticator app before verifying the token method. | ||
| */ | ||
| generateQrCode(orgId: number, userEmail: string): Observable<GenerateTwoFactorQrCodeResponse> { | ||
| const url = '/api/v3/two_factor/generate_qr_code/' | ||
| const params = { organization_id: orgId } | ||
| return this._httpClient.post<GenerateTwoFactorQrCodeResponse>(url, { user_email: userEmail }, { params }).pipe( | ||
| catchError((error: HttpErrorResponse) => this._errorService.handleError(error, 'Error generating QR code')), | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Verifies a 6-digit authenticator app code against the session's pending QR code secret. | ||
| */ | ||
| verifyCode(orgId: number, userEmail: string, code: string): Observable<VerifyTwoFactorCodeResponse> { | ||
| const url = '/api/v3/two_factor/verify_code/' | ||
| const params = { organization_id: orgId } | ||
| return this._httpClient.post<VerifyTwoFactorCodeResponse>(url, { user_email: userEmail, code }, { params }).pipe( | ||
| catchError((error: HttpErrorResponse) => this._errorService.handleError(error, 'Error verifying code')), | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| export type TwoFactorMethod = 'disabled' | 'email' | 'token' | ||
|
|
||
| export type TwoFactorMethods = { | ||
| disabled: boolean; | ||
| email: boolean; | ||
| token: boolean; | ||
| } | ||
|
|
||
| export type SetTwoFactorMethodResponse = { | ||
| status?: string; | ||
| message?: string; | ||
| methods?: TwoFactorMethods; | ||
| qr_code?: string; | ||
| } | ||
|
|
||
| export type ResendTwoFactorTokenEmailResponse = { | ||
| message: string; | ||
| } | ||
|
|
||
| export type GenerateTwoFactorQrCodeResponse = { | ||
| qr_code: string; | ||
| } | ||
|
|
||
| export type VerifyTwoFactorCodeResponse = { | ||
| success?: boolean; | ||
| error?: string; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/app/modules/profile/two-factor/modal/qr-code-modal.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| <div *transloco="let t"> | ||
| <seed-modal-header [close]="close.bind(this)" [title]="t('Authenticator QR Code')" titleIcon="fa-solid:qrcode"></seed-modal-header> | ||
|
|
||
| <div class="flex flex-col gap-4"> | ||
| <p class="text-sm"> | ||
| <strong>{{ t('Important') }}</strong> - | ||
| {{ | ||
| t( | ||
| 'Scan the QR code below using your authenticator app of choice (ex: Google Authenticator, Microsoft Authenticator, Authy, etc...)' | ||
| ) | ||
| }} | ||
| </p> | ||
|
|
||
| <div class="flex justify-center"> | ||
| <img class="h-48 w-48" [src]="qrCodeImg" alt="QR Code" /> | ||
| </div> | ||
|
|
||
| <form class="flex flex-wrap items-end gap-4" [formGroup]="codeForm" (ngSubmit)="verify()"> | ||
| <mat-form-field class="flex-auto"> | ||
| <mat-label>{{ t('Verification Code') }}</mat-label> | ||
| <input matInput formControlName="code" inputmode="numeric" maxlength="6" autocomplete="one-time-code" /> | ||
| @if (codeForm.controls.code.hasError('required')) { | ||
| <mat-error>{{ t('Verification Code') }} {{ t('Required') }}</mat-error> | ||
| } @else if (codeForm.controls.code.hasError('pattern')) { | ||
| <mat-error>{{ t('Enter the 6-digit code from your authenticator app') }}</mat-error> | ||
| } | ||
| </mat-form-field> | ||
| <button [disabled]="codeForm.invalid || verifying" mat-flat-button color="primary" type="submit"> | ||
| @if (verifying) { | ||
| <mat-progress-spinner class="align-middle mr-2 inline-block" diameter="18" mode="indeterminate"></mat-progress-spinner> | ||
| } | ||
| <span>{{ t('Verify') }}</span> | ||
| </button> | ||
| </form> | ||
|
|
||
| <p class="text-secondary text-sm"> | ||
| {{ t('If you are unable to scan the QR code, select a different method below.') }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="mt-6 flex flex-wrap justify-end gap-2"> | ||
| <mat-dialog-actions> | ||
| <button [disabled]="regenerating" (click)="regenerate()" mat-stroked-button>{{ t('Re-Generate Token') }}</button> | ||
| </mat-dialog-actions> | ||
| <mat-dialog-actions> | ||
| <button (click)="close(false)" mat-stroked-button>{{ t('Select a Different Method') }}</button> | ||
| </mat-dialog-actions> | ||
| <mat-dialog-actions> | ||
| <button (click)="close(false)" mat-raised-button color="warn">{{ t('Cancel') }}</button> | ||
| </mat-dialog-actions> | ||
| </div> | ||
| </div> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.