mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
CL-1072 initial commit (#24648)
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
@switch (viewState()) {
|
||||
@case ("auth") {
|
||||
<app-send-auth [id]="id" [key]="key" (accessGranted)="onAccessGranted($event)"></app-send-auth>
|
||||
<app-send-auth
|
||||
[id]="id()"
|
||||
[key]="key()"
|
||||
(accessGranted)="onAccessGranted($event)"
|
||||
></app-send-auth>
|
||||
}
|
||||
@case ("view") {
|
||||
<app-send-view
|
||||
[id]="id"
|
||||
[key]="key"
|
||||
[accessToken]="sendAccessToken"
|
||||
[id]="id()"
|
||||
[key]="key()"
|
||||
[accessToken]="sendAccessToken()"
|
||||
(authRequired)="onAuthRequired()"
|
||||
></app-send-view>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-1062): `OnPush` components should not use mutable properties
|
||||
/* eslint-disable @bitwarden/components/enforce-readonly-angular-properties */
|
||||
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, signal } from "@angular/core";
|
||||
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
|
||||
import { ActivatedRoute } from "@angular/router";
|
||||
@@ -27,25 +25,25 @@ type SendViewState = (typeof SendViewState)[keyof typeof SendViewState];
|
||||
})
|
||||
export class AccessComponent implements OnInit {
|
||||
readonly viewState = signal<SendViewState | null>(SendViewState.Auth);
|
||||
id: string;
|
||||
key: string;
|
||||
readonly id = signal<string>("");
|
||||
readonly key = signal<string>("");
|
||||
|
||||
sendAccessToken: SendAccessToken | null = null;
|
||||
readonly sendAccessToken = signal<SendAccessToken | null>(null);
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private destroyRef: DestroyRef,
|
||||
private readonly route: ActivatedRoute,
|
||||
private readonly destroyRef: DestroyRef,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.params.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((params) => {
|
||||
this.id = params.sendId;
|
||||
this.key = params.key;
|
||||
this.id.set(params.sendId);
|
||||
this.key.set(params.key);
|
||||
|
||||
// when pasting sequential Send URLs into the browser,
|
||||
// Angular reuses the SendAuthComponent instance
|
||||
// Reset state so child components are recreated with fresh data
|
||||
this.sendAccessToken = null;
|
||||
this.sendAccessToken.set(null);
|
||||
|
||||
// Temporarily set viewState to null to destroy the current child component,
|
||||
// then set it back to Auth on the next tick to recreate it with the new id/key.
|
||||
@@ -59,7 +57,7 @@ export class AccessComponent implements OnInit {
|
||||
}
|
||||
|
||||
onAccessGranted(event: { accessToken: SendAccessToken }) {
|
||||
this.sendAccessToken = event.accessToken;
|
||||
this.sendAccessToken.set(event.accessToken);
|
||||
this.viewState.set(SendViewState.View);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-1062): `OnPush` components should not use mutable properties
|
||||
/* eslint-disable @bitwarden/components/enforce-readonly-angular-properties */
|
||||
import { ChangeDetectionStrategy, Component, input } from "@angular/core";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
|
||||
@@ -31,15 +29,15 @@ export class SendAccessFileComponent {
|
||||
readonly accessToken = input<SendAccessToken | null>(null);
|
||||
|
||||
constructor(
|
||||
private i18nService: I18nService,
|
||||
private toastService: ToastService,
|
||||
private encryptService: EncryptService,
|
||||
private fileDownloadService: FileDownloadService,
|
||||
private sendApiService: SendApiService,
|
||||
private environmentService: EnvironmentService,
|
||||
private readonly i18nService: I18nService,
|
||||
private readonly toastService: ToastService,
|
||||
private readonly encryptService: EncryptService,
|
||||
private readonly fileDownloadService: FileDownloadService,
|
||||
private readonly sendApiService: SendApiService,
|
||||
private readonly environmentService: EnvironmentService,
|
||||
) {}
|
||||
|
||||
protected download = async () => {
|
||||
protected readonly download = async () => {
|
||||
const accessToken = this.accessToken();
|
||||
if (this.send() == null || this.decKey() == null || !accessToken) {
|
||||
return;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-1062): `OnPush` components should not use mutable properties
|
||||
/* eslint-disable @bitwarden/components/enforce-readonly-angular-properties */
|
||||
import { ChangeDetectionStrategy, Component, input, OnDestroy, OnInit } from "@angular/core";
|
||||
import { FormControl, FormGroup, Validators } from "@angular/forms";
|
||||
|
||||
@@ -15,14 +13,13 @@ import { SharedModule } from "../../../shared";
|
||||
})
|
||||
export class SendAccessPasswordComponent implements OnInit, OnDestroy {
|
||||
protected readonly formGroup = input.required<FormGroup>();
|
||||
protected password: FormControl;
|
||||
protected readonly password = new FormControl("", Validators.required);
|
||||
|
||||
readonly loading = input.required<boolean>();
|
||||
|
||||
constructor() {}
|
||||
|
||||
ngOnInit() {
|
||||
this.password = new FormControl("", Validators.required);
|
||||
this.formGroup().addControl("password", this.password);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-1062): `OnPush` components should not use mutable properties
|
||||
/* eslint-disable @bitwarden/components/enforce-readonly-angular-properties */
|
||||
import { ChangeDetectionStrategy, Component, input, OnInit, output, signal } from "@angular/core";
|
||||
import { FormBuilder } from "@angular/forms";
|
||||
import { firstValueFrom } from "rxjs";
|
||||
@@ -39,14 +37,14 @@ export class SendAuthComponent implements OnInit {
|
||||
protected readonly id = input.required<string>();
|
||||
protected readonly key = input.required<string>();
|
||||
|
||||
protected accessGranted = output<{
|
||||
protected readonly accessGranted = output<{
|
||||
accessToken: SendAccessToken;
|
||||
}>();
|
||||
|
||||
authType = AuthType;
|
||||
readonly authType = AuthType;
|
||||
|
||||
private expiredAuthAttempts = 0;
|
||||
private otpSubmitted = false;
|
||||
private readonly expiredAuthAttempts = signal(0);
|
||||
private readonly otpSubmitted = signal(false);
|
||||
|
||||
readonly loading = signal<boolean>(false);
|
||||
readonly error = signal<boolean>(false);
|
||||
@@ -54,15 +52,19 @@ export class SendAuthComponent implements OnInit {
|
||||
readonly sendAuthType = signal<AuthType>(AuthType.None);
|
||||
readonly enterOtp = signal<boolean>(false);
|
||||
|
||||
sendAccessForm = this.formBuilder.group<{ password?: string; email?: string; otp?: string }>({});
|
||||
readonly sendAccessForm = this.formBuilder.group<{
|
||||
password?: string;
|
||||
email?: string;
|
||||
otp?: string;
|
||||
}>({});
|
||||
|
||||
constructor(
|
||||
private cryptoFunctionService: CryptoFunctionService,
|
||||
private toastService: ToastService,
|
||||
private i18nService: I18nService,
|
||||
private formBuilder: FormBuilder,
|
||||
private sendTokenService: SendTokenService,
|
||||
private anonLayoutWrapperDataService: AnonLayoutWrapperDataService,
|
||||
private readonly cryptoFunctionService: CryptoFunctionService,
|
||||
private readonly toastService: ToastService,
|
||||
private readonly i18nService: I18nService,
|
||||
private readonly formBuilder: FormBuilder,
|
||||
private readonly sendTokenService: SendTokenService,
|
||||
private readonly anonLayoutWrapperDataService: AnonLayoutWrapperDataService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -82,7 +84,7 @@ export class SendAuthComponent implements OnInit {
|
||||
|
||||
onBackToEmail() {
|
||||
this.enterOtp.set(false);
|
||||
this.otpSubmitted = false;
|
||||
this.otpSubmitted.set(false);
|
||||
this.updatePageTitle();
|
||||
}
|
||||
|
||||
@@ -109,16 +111,16 @@ export class SendAuthComponent implements OnInit {
|
||||
: await firstValueFrom(this.sendTokenService.getSendAccessToken$(this.id(), sendAccessCreds));
|
||||
|
||||
if (response instanceof SendAccessToken) {
|
||||
this.expiredAuthAttempts = 0;
|
||||
this.expiredAuthAttempts.set(0);
|
||||
this.accessGranted.emit({ accessToken: response });
|
||||
} else if (response.kind === "expired") {
|
||||
if (this.expiredAuthAttempts > 2) {
|
||||
if (this.expiredAuthAttempts() > 2) {
|
||||
return;
|
||||
}
|
||||
this.expiredAuthAttempts++;
|
||||
this.expiredAuthAttempts.update((attempts) => attempts + 1);
|
||||
await this.getTokenWithRetry(sendAccessCreds);
|
||||
} else if (response.kind === "expected_server") {
|
||||
this.expiredAuthAttempts = 0;
|
||||
this.expiredAuthAttempts.set(0);
|
||||
if (emailRequired(response.error)) {
|
||||
this.sendAuthType.set(AuthType.Email);
|
||||
this.updatePageTitle();
|
||||
@@ -130,14 +132,14 @@ export class SendAuthComponent implements OnInit {
|
||||
message: this.i18nService.t("codeResent"),
|
||||
});
|
||||
} else {
|
||||
if (this.otpSubmitted) {
|
||||
if (this.otpSubmitted()) {
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
title: undefined,
|
||||
message: this.i18nService.t("invalidVerificationCode"),
|
||||
});
|
||||
}
|
||||
this.otpSubmitted = true;
|
||||
this.otpSubmitted.set(true);
|
||||
}
|
||||
this.enterOtp.set(true);
|
||||
this.updatePageTitle();
|
||||
@@ -160,7 +162,7 @@ export class SendAuthComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this.expiredAuthAttempts = 0;
|
||||
this.expiredAuthAttempts.set(0);
|
||||
this.error.set(true);
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
@case (sendType.File) {
|
||||
<app-send-access-file
|
||||
[send]="send()"
|
||||
[decKey]="decKey"
|
||||
[decKey]="decKey()"
|
||||
[accessToken]="accessToken()"
|
||||
></app-send-access-file>
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// FIXME(https://bitwarden.atlassian.net/browse/CL-1062): `OnPush` components should not use mutable properties
|
||||
/* eslint-disable @bitwarden/components/enforce-readonly-angular-properties */
|
||||
import {
|
||||
ChangeDetectionStrategy,
|
||||
Component,
|
||||
@@ -50,7 +48,7 @@ export class SendViewComponent implements OnInit {
|
||||
readonly key = input.required<string>();
|
||||
readonly accessToken = input<SendAccessToken | null>(null);
|
||||
|
||||
authRequired = output<void>();
|
||||
readonly authRequired = output<void>();
|
||||
|
||||
readonly send = signal<SendAccessView | null>(null);
|
||||
readonly expirationDate = computed<Date | null>(() => this.send()?.expirationDate ?? null);
|
||||
@@ -64,15 +62,15 @@ export class SendViewComponent implements OnInit {
|
||||
readonly unavailable = signal<boolean>(false);
|
||||
readonly error = signal<boolean>(false);
|
||||
|
||||
sendType = SendType;
|
||||
decKey!: SymmetricCryptoKey;
|
||||
readonly sendType = SendType;
|
||||
readonly decKey = signal<SymmetricCryptoKey | null>(null);
|
||||
|
||||
constructor(
|
||||
private sendApiService: SendApiService,
|
||||
private toastService: ToastService,
|
||||
private i18nService: I18nService,
|
||||
private layoutWrapperDataService: AnonLayoutWrapperDataService,
|
||||
private sendDecryptionService: SendDecryptionService,
|
||||
private readonly sendApiService: SendApiService,
|
||||
private readonly toastService: ToastService,
|
||||
private readonly i18nService: I18nService,
|
||||
private readonly layoutWrapperDataService: AnonLayoutWrapperDataService,
|
||||
private readonly sendDecryptionService: SendDecryptionService,
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -99,7 +97,7 @@ export class SendViewComponent implements OnInit {
|
||||
response,
|
||||
keyArray,
|
||||
);
|
||||
this.decKey = decKey;
|
||||
this.decKey.set(decKey);
|
||||
this.send.set(decSend);
|
||||
} catch (e) {
|
||||
this.send.set(null);
|
||||
|
||||
Reference in New Issue
Block a user