Files
clients/libs/auth/src/angular/login/login.component.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

645 lines
23 KiB
TypeScript
Raw Normal View History

[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { CommonModule } from "@angular/common";
import { Component, ElementRef, NgZone, OnDestroy, OnInit, ViewChild } from "@angular/core";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { FormBuilder, FormControl, ReactiveFormsModule, Validators } from "@angular/forms";
import { ActivatedRoute, Router, RouterModule } from "@angular/router";
import { firstValueFrom, Subject, take, takeUntil } from "rxjs";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { JslibModule } from "@bitwarden/angular/jslib.module";
import {
LoginEmailServiceAbstraction,
LoginStrategyServiceAbstraction,
LoginSuccessHandlerService,
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
PasswordLoginCredentials,
} from "@bitwarden/auth/common";
import { InternalPolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
import { PolicyData } from "@bitwarden/common/admin-console/models/data/policy.data";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { MasterPasswordPolicyOptions } from "@bitwarden/common/admin-console/models/domain/master-password-policy-options";
import { Policy } from "@bitwarden/common/admin-console/models/domain/policy";
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
import { AuthResult } from "@bitwarden/common/auth/models/domain/auth-result";
import { ClientType, HttpStatusCode } from "@bitwarden/common/enums";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { AppIdService } from "@bitwarden/common/platform/abstractions/app-id.service";
import { BroadcasterService } from "@bitwarden/common/platform/abstractions/broadcaster.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { ValidationService } from "@bitwarden/common/platform/abstractions/validation.service";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { PasswordStrengthServiceAbstraction } from "@bitwarden/common/tools/password-strength";
import { UserId } from "@bitwarden/common/types/guid";
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
// eslint-disable-next-line no-restricted-imports
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
import {
AsyncActionsModule,
ButtonModule,
CheckboxModule,
FormFieldModule,
IconButtonModule,
LinkModule,
ToastService,
} from "@bitwarden/components";
import { AnonLayoutWrapperDataService } from "../anon-layout/anon-layout-wrapper-data.service";
import { VaultIcon, WaveIcon } from "../icons";
import { LoginComponentService, PasswordPolicies } from "./login-component.service";
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
const BroadcasterSubscriptionId = "LoginComponent";
// FIXME: update to use a const object instead of a typescript enum
// eslint-disable-next-line @bitwarden/platform/no-enums
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
export enum LoginUiState {
EMAIL_ENTRY = "EmailEntry",
MASTER_PASSWORD_ENTRY = "MasterPasswordEntry",
}
@Component({
standalone: true,
templateUrl: "./login.component.html",
imports: [
AsyncActionsModule,
ButtonModule,
CheckboxModule,
CommonModule,
FormFieldModule,
IconButtonModule,
LinkModule,
JslibModule,
ReactiveFormsModule,
RouterModule,
],
})
export class LoginComponent implements OnInit, OnDestroy {
@ViewChild("masterPasswordInputRef") masterPasswordInputRef: ElementRef | undefined;
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
private destroy$ = new Subject<void>();
readonly Icons = { WaveIcon, VaultIcon };
clientType: ClientType;
ClientType = ClientType;
LoginUiState = LoginUiState;
isKnownDevice = false;
loginUiState: LoginUiState = LoginUiState.EMAIL_ENTRY;
formGroup = this.formBuilder.group(
{
email: ["", [Validators.required, Validators.email]],
masterPassword: [
"",
[Validators.required, Validators.minLength(Utils.originalMinimumPasswordLength)],
],
rememberEmail: [false],
},
{ updateOn: "submit" },
);
get emailFormControl(): FormControl<string | null> {
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
return this.formGroup.controls.email;
}
// Desktop properties
deferFocus: boolean | null = null;
constructor(
private activatedRoute: ActivatedRoute,
private anonLayoutWrapperDataService: AnonLayoutWrapperDataService,
private appIdService: AppIdService,
private broadcasterService: BroadcasterService,
private devicesApiService: DevicesApiServiceAbstraction,
private formBuilder: FormBuilder,
private i18nService: I18nService,
private loginEmailService: LoginEmailServiceAbstraction,
private loginComponentService: LoginComponentService,
private loginStrategyService: LoginStrategyServiceAbstraction,
private messagingService: MessagingService,
private ngZone: NgZone,
private passwordStrengthService: PasswordStrengthServiceAbstraction,
private platformUtilsService: PlatformUtilsService,
private policyService: InternalPolicyService,
private router: Router,
private toastService: ToastService,
private logService: LogService,
private validationService: ValidationService,
private loginSuccessHandlerService: LoginSuccessHandlerService,
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
) {
this.clientType = this.platformUtilsService.getClientType();
}
async ngOnInit(): Promise<void> {
// Add popstate listener to listen for browser back button clicks
window.addEventListener("popstate", this.handlePopState);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
await this.defaultOnInit();
if (this.clientType === ClientType.Desktop) {
await this.desktopOnInit();
}
}
ngOnDestroy(): void {
// Remove popstate listener
window.removeEventListener("popstate", this.handlePopState);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
if (this.clientType === ClientType.Desktop) {
// TODO: refactor to not use deprecated broadcaster service.
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
}
this.destroy$.next();
this.destroy$.complete();
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
private async defaultOnInit(): Promise<void> {
let paramEmailIsSet = false;
const params = await firstValueFrom(this.activatedRoute.queryParams);
if (params) {
const qParamsEmail = params.email;
// If there is an email in the query params, set that email as the form field value
if (qParamsEmail != null && qParamsEmail.indexOf("@") > -1) {
this.formGroup.controls.email.setValue(qParamsEmail);
paramEmailIsSet = true;
}
}
// If there are no params or no email in the query params, loadEmailSettings from state
if (!paramEmailIsSet) {
await this.loadRememberedEmail();
}
// Check to see if the device is known so that we can show the Login with Device option
if (this.emailFormControl.value) {
await this.getKnownDevice(this.emailFormControl.value);
}
// Backup check to handle unknown case where activatedRoute is not available
// This shouldn't happen under normal circumstances
if (!this.activatedRoute) {
await this.loadRememberedEmail();
}
}
private async desktopOnInit(): Promise<void> {
// TODO: refactor to not use deprecated broadcaster service.
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
this.ngZone.run(() => {
switch (message.command) {
case "windowIsFocused":
if (this.deferFocus === null) {
this.deferFocus = !message.windowIsFocused;
if (!this.deferFocus) {
this.focusInput();
}
} else if (this.deferFocus && message.windowIsFocused) {
this.focusInput();
this.deferFocus = false;
}
break;
default:
}
});
});
this.messagingService.send("getWindowIsFocused");
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
submit = async (): Promise<void> => {
if (this.clientType === ClientType.Desktop) {
if (this.loginUiState !== LoginUiState.MASTER_PASSWORD_ENTRY) {
return;
}
}
const { email, masterPassword } = this.formGroup.value;
this.formGroup.markAllAsTouched();
if (this.formGroup.invalid) {
return;
}
if (!email || !masterPassword) {
this.logService.error("Email and master password are required");
return;
}
const credentials = new PasswordLoginCredentials(email, masterPassword);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
try {
const authResult = await this.loginStrategyService.logIn(credentials);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
await this.handleAuthResult(authResult);
} catch (error) {
this.logService.error(error);
this.handleSubmitError(error);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
};
/**
* Handles the error from the submit function.
*
* @param error The error object.
*/
private handleSubmitError(error: unknown) {
// Handle error responses
if (error instanceof ErrorResponse) {
switch (error.statusCode) {
case HttpStatusCode.BadRequest: {
if (error.message.toLowerCase().includes("username or password is incorrect")) {
this.formGroup.controls.masterPassword.setErrors({
error: {
message: this.i18nService.t("invalidMasterPassword"),
},
});
} else {
// Allow other 400 responses to be handled by toast
this.validationService.showError(error);
}
break;
}
default: {
// Allow all other error codes to be handled by toast
this.validationService.showError(error);
}
}
} else {
// Allow all other errors to be handled by toast
this.validationService.showError(error);
}
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
/**
* Handles the result of the authentication process.
*
* @param authResult
* @returns A simple `return` statement for each conditional check.
* If you update this method, do not forget to add a `return`
* to each if-condition block where necessary to stop code execution.
*/
private async handleAuthResult(authResult: AuthResult): Promise<void> {
if (authResult.requiresEncryptionKeyMigration) {
/* Legacy accounts used the master key to encrypt data.
This is now unsupported and requires a downgraded client */
this.toastService.showToast({
variant: "error",
title: this.i18nService.t("errorOccured"),
message: this.i18nService.t("legacyEncryptionUnsupported"),
});
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
return;
}
if (authResult.requiresTwoFactor) {
await this.router.navigate(["2fa"]);
return;
}
// Redirect to device verification if this is an unknown device
if (authResult.requiresDeviceVerification) {
await this.router.navigate(["device-verification"]);
return;
}
// User logged in successfully so execute side effects
await this.loginSuccessHandlerService.run(authResult.userId);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
// Determine where to send the user next
// The AuthGuard will handle routing to update-temp-password based on state
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
// TODO: PM-18269 - evaluate if we can combine this with the
// password evaluation done in the password login strategy.
// If there's an existing org invite, use it to get the org's password policies
// so we can evaluate the MP against the org policies
if (this.loginComponentService.getOrgPoliciesFromOrgInvite) {
const orgPolicies: PasswordPolicies | null =
await this.loginComponentService.getOrgPoliciesFromOrgInvite();
if (orgPolicies) {
// Since we have retrieved the policies, we can go ahead and set them into state for future use
// e.g., the update-password page currently only references state for policy data and
// doesn't fallback to pulling them from the server like it should if they are null.
await this.setPoliciesIntoState(authResult.userId, orgPolicies.policies);
const isPasswordChangeRequired = await this.isPasswordChangeRequiredByOrgPolicy(
orgPolicies.enforcedPasswordPolicyOptions,
);
if (isPasswordChangeRequired) {
await this.router.navigate(["update-password"]);
return;
}
}
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
if (this.clientType === ClientType.Browser) {
await this.router.navigate(["/tabs/vault"]);
} else {
await this.router.navigate(["vault"]);
}
}
/**
* Checks if the master password meets the enforced policy requirements
* and if the user is required to change their password.
*/
private async isPasswordChangeRequiredByOrgPolicy(
enforcedPasswordPolicyOptions: MasterPasswordPolicyOptions,
): Promise<boolean> {
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
try {
if (enforcedPasswordPolicyOptions == undefined) {
return false;
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
// Note: we deliberately do not check enforcedPasswordPolicyOptions.enforceOnLogin
// as existing users who are logging in after getting an org invite should
// always be forced to set a password that meets the org's policy.
// Org Invite -> Registration also works this way for new BW users as well.
const masterPassword = this.formGroup.controls.masterPassword.value;
// Return false if masterPassword is null/undefined since this is only evaluated after successful login
if (!masterPassword) {
return false;
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
const passwordStrength = this.passwordStrengthService.getPasswordStrength(
masterPassword,
this.formGroup.value.email ?? undefined,
)?.score;
return !this.policyService.evaluateMasterPassword(
passwordStrength,
masterPassword,
enforcedPasswordPolicyOptions,
);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
} catch (e) {
// Do not prevent unlock if there is an error evaluating policies
this.logService.error(e);
return false;
}
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
private async setPoliciesIntoState(userId: UserId, policies: Policy[]): Promise<void> {
const policiesData: { [id: string]: PolicyData } = {};
policies.map((p) => (policiesData[p.id] = PolicyData.fromPolicy(p)));
await this.policyService.replace(policiesData, userId);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
protected async startAuthRequestLogin(): Promise<void> {
this.formGroup.get("masterPassword")?.clearValidators();
this.formGroup.get("masterPassword")?.updateValueAndValidity();
if (!this.formGroup.valid) {
return;
}
await this.router.navigate(["/login-with-device"]);
}
protected async toggleLoginUiState(value: LoginUiState): Promise<void> {
this.loginUiState = value;
if (this.loginUiState === LoginUiState.EMAIL_ENTRY) {
this.loginComponentService.showBackButton(false);
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageTitle: { key: "logInToBitwarden" },
pageIcon: this.Icons.VaultIcon,
pageSubtitle: null, // remove subtitle when going back to email entry
});
// Reset master password only when going from validated to not validated so that autofill can work properly
this.formGroup.controls.masterPassword.reset();
// Reset known device state when going back to email entry if it is supported
this.isKnownDevice = false;
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
} else if (this.loginUiState === LoginUiState.MASTER_PASSWORD_ENTRY) {
this.loginComponentService.showBackButton(true);
this.anonLayoutWrapperDataService.setAnonLayoutWrapperData({
pageTitle: { key: "welcomeBack" },
pageSubtitle: this.emailFormControl.value,
pageIcon: this.Icons.WaveIcon,
});
// Mark MP as untouched so that, when users enter email and hit enter, the MP field doesn't load with validation errors
this.formGroup.controls.masterPassword.markAsUntouched();
// When email is validated, focus on master password after waiting for input to be rendered
if (this.ngZone.isStable) {
this.masterPasswordInputRef?.nativeElement?.focus();
} else {
this.ngZone.onStable.pipe(take(1), takeUntil(this.destroy$)).subscribe(() => {
this.masterPasswordInputRef?.nativeElement?.focus();
});
}
// Check to see if the device is known so we can show the Login with Device option
const email = this.emailFormControl.value;
if (email) {
await this.getKnownDevice(email);
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
}
isLoginWithPasskeySupported() {
return this.loginComponentService.isLoginWithPasskeySupported();
}
protected async goToHint(): Promise<void> {
await this.router.navigateByUrl("/hint");
}
/**
* Continue button clicked (or enter key pressed).
* Adds the login url to the browser's history so that the back button can be used to go back to the email entry state.
* Needs to be separate from the continue() function because that can be triggered by the browser's forward button.
*/
protected async continuePressed() {
// Add a new entry to the browser's history so that there is a history entry to go back to
history.pushState({}, "", window.location.href);
await this.continue();
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
/**
* Continue to the master password entry state (only if email is validated)
*/
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
protected async continue(): Promise<void> {
const isEmailValid = this.validateEmail();
if (isEmailValid) {
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
await this.toggleLoginUiState(LoginUiState.MASTER_PASSWORD_ENTRY);
}
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
/**
* Handle the Login with Passkey button click.
* We need a handler here in order to persist the remember email selection to state before routing.
* @param event - The event object.
*/
async handleLoginWithPasskeyClick() {
await this.router.navigate(["/login-with-passkey"]);
}
/**
* Handle the SSO button click.
* @param event - The event object.
*/
async handleSsoClick() {
// Make sure the email is valid
const isEmailValid = this.validateEmail();
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
if (!isEmailValid) {
return;
}
// Make sure the email is not empty, for type safety
const email = this.formGroup.value.email;
if (!email) {
this.logService.error("Email is required for SSO");
return;
}
// Send the user to SSO, either through routing or through redirecting to the web app
await this.loginComponentService.redirectToSsoLogin(email);
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
/**
* Call to check if the device is known.
* Known means that the user has logged in with this device before.
* @param email - The user's email
*/
private async getKnownDevice(email: string): Promise<void> {
if (!email) {
this.isKnownDevice = false;
return;
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
try {
const deviceIdentifier = await this.appIdService.getAppId();
this.isKnownDevice = await this.devicesApiService.getKnownDevice(email, deviceIdentifier);
// FIXME: Remove when updating file. Eslint update
// eslint-disable-next-line @typescript-eslint/no-unused-vars
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
} catch (e) {
this.isKnownDevice = false;
}
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
/**
* Check to see if the user has remembered an email on the current device.
* If so, set the email in the form field and set rememberEmail to true. If not, set rememberEmail to false.
*/
private async loadRememberedEmail(): Promise<void> {
const storedEmail = await firstValueFrom(this.loginEmailService.rememberedEmail$);
if (storedEmail) {
this.formGroup.controls.email.setValue(storedEmail);
this.formGroup.controls.rememberEmail.setValue(true);
// If we load an email into the form, we need to initialize it for the login process as well
// so that other login components can use it.
// We do this here as it's possible that a user doesn't edit the email field before submitting.
await this.loginEmailService.setLoginEmail(storedEmail);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
} else {
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
this.formGroup.controls.rememberEmail.setValue(false);
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}
}
private focusInput() {
document
.getElementById(
this.emailFormControl.value == null || this.emailFormControl.value === ""
? "email"
: "masterPassword",
)
?.focus();
}
/**
* Helper function to determine if the back button should be shown.
* @returns true if the back button should be shown.
*/
protected shouldShowBackButton(): boolean {
return (
this.loginUiState === LoginUiState.MASTER_PASSWORD_ENTRY &&
this.clientType !== ClientType.Browser
);
}
/**
* Handle the back button click to transition back to the email entry state.
*/
protected async backButtonClicked() {
history.back();
}
/**
* Handle the popstate event to transition back to the email entry state when the back button is clicked.
* Also handles the case where the user clicks the forward button.
* @param event - The popstate event.
*/
private handlePopState = async (event: PopStateEvent) => {
if (this.loginUiState === LoginUiState.MASTER_PASSWORD_ENTRY) {
// Prevent default navigation when the browser's back button is clicked
event.preventDefault();
// Transition back to email entry state
void this.toggleLoginUiState(LoginUiState.EMAIL_ENTRY);
} else if (this.loginUiState === LoginUiState.EMAIL_ENTRY) {
// Prevent default navigation when the browser's forward button is clicked
event.preventDefault();
// Continue to the master password entry state
await this.continue();
}
};
/**
* Validates the email and displays any validation errors.
* @returns true if the email is valid, false otherwise.
*/
protected validateEmail(): boolean {
this.formGroup.controls.email.markAsTouched();
this.formGroup.controls.email.updateValueAndValidity({ onlySelf: true, emitEvent: true });
return this.formGroup.controls.email.valid;
}
/**
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
* Persist the entered email address and the user's choice to remember it to state.
*/
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
private async persistEmailIfValid(): Promise<void> {
if (this.formGroup.controls.email.valid) {
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
const email = this.formGroup.value.email;
const rememberEmail = this.formGroup.value.rememberEmail ?? false;
if (!email) {
return;
}
await this.loginEmailService.setLoginEmail(email);
await this.loginEmailService.setRememberedEmailChoice(email, rememberEmail);
} else {
await this.loginEmailService.clearLoginEmail();
await this.loginEmailService.clearRememberedEmail();
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
/**
* Set the email value from the input field and persists to state if valid.
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
* We only update the form controls onSubmit instead of onBlur because we don't want to show validation errors until
* the user submits. This is because currently our validation errors are shown below the input fields, and
* displaying them causes the screen to "jump".
* @param event The event object from the input field.
*/
async onEmailInput(event: Event) {
const emailInput = event.target as HTMLInputElement;
this.formGroup.controls.email.setValue(emailInput.value);
await this.persistEmailIfValid();
}
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
/**
* Set the Remember Email value from the input field and persists to state if valid.
fix(login): [PM-11502] Support Remember Email option consistently * Moved saving of SSO email outside of browser/desktop code * Clarified comments. * Tests * Refactored login component services to manage state * Fixed input on login component * Fixed tests * Linting * Moved web setting in state into web override * updated tests * Fixed typing. * Fixed type safety issues. * Added comments and renamed for clarity. * Removed method parameters that weren't used * Added clarifying comments * Added more comments. * Removed test that is not necessary on base * Test cleanup * More comments. * Linting * Fixed test. * Fixed base URL * Fixed typechecking. * Type checking * Moved setting of email state to default service * Added comments. * Consolidated SSO URL formatting * Updated comment * Fixed reference. * Fixed missing parameter. * Initialized service. * Added comments * Added initialization of new service * Made email optional due to CLI. * Fixed comment on handleSsoClick. * Added SSO email persistence to v1 component. * Updated login email service. * Updated setting of remember me * Removed unnecessary input checking and rearranged functions * Fixed name * Added handling of Remember Email to old component for passkey click * Updated v1 component to persist the email on Continue click * Fix merge conflicts. * Merge conflicts in login component. * Persisted login email on v1 browser component. * Merge conflicts * fix(snap) [PM-17464][PM-17463][PM-15587] Allow Snap to use custom callback protocol * Removed Snap from custom protocol workaround * Fixed tests. * Updated case numbers on test * Resolved PR feedback. * PM-11502 - LoginEmailSvcAbstraction - mark methods as abstract to satisfy strict ts. * Removed test * Changed to persist on leaving fields instead of button click. * Fixed type checking. --------- Co-authored-by: Bernd Schoolmann <mail@quexten.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2025-04-10 18:58:49 -04:00
* We only update the form controls onSubmit instead of onBlur because we don't want to show validation errors until
* the user submits. This is because currently our validation errors are shown below the input fields, and
* displaying them causes the screen to "jump".
* @param event The event object from the input field.
*/
async onRememberEmailInput(event: Event) {
const rememberEmailInput = event.target as HTMLInputElement;
this.formGroup.controls.rememberEmail.setValue(rememberEmailInput.checked);
await this.persistEmailIfValid();
}
[PM-8111] Browser Refresh: LoginComponent (#10856) * setup new LoginComponent files in libs/auth * update pageTitle * handle loading email settings * setup web-login.service.ts * implement web onInit * fill out webOnInit * refactor getOrgPolicies call * update import * add validateEmail logic * handle registerRoute * add showPasswordless flag * handle captcha * handle startAuthRequestLogin() * add handleMigrateEncryptionKey to default and web service * handle submit routing (web) * fix typo * incorporate loginEmailService changes * minor updates to comments for clarity * create a defaultOnInit() * update defaultOnInit() * handle master password input focus * handle post-login routing on Browser/Desktop * handle browser/desktop syncService * handle browser ngOnInit * handle browser routing and basic browser template * setup desktop router * add template for desktop first UI state: email entry * rename 'response' to 'authResult' * refactor handleMigrateEncryptionKey() * refactor captcha methods and add return types * refactor submit logic * refactor submit logic further to use if statements with returns instead of if...else if...else * remove toast error on invalid form for Browser/Desktop * refactor to handleAuthResult() method * refactor webOnInit * add comment to revisit ngOnInit logic * refactor handlCaptchaRequired() * create a LoginSecondaryContentComponent for AnonLayout use * minor formatting for consistency * add clarifying comment to handleAuthResult() * minor refactor to use destructuring * setup desktopOnInit() * add continue() method * handle desktop ngOnDestroy() * add clarifying comment regarding secondary content * fill out desktop template and submit() * add descriptive comment to top of HTML file * refactor to use a uiState enum for UI states * handle oss-routing swap * handle registerRoute$ in secondary content * web template modifications * change email validation to only run on submit (or when clicking continue button) * add dynamic anon-layout wrapper data * remove static element ref * desktop HTML template updates * remove 'showPassword' property b/c now handled by bitPasswordInputToggle * Extension: setup EmailEntry state UI * Extension: setup MasterPasswordEntry state UI * ensure full sync happens on all clients before navigation * update icon stroke color * change old components to V1 * remove 'V2' from new component * update captcha iframe on all clients * add browser redirect from /home to /login with FF on * add todo comment regarding browser template * add launchSsoBrowser to extension template * move extension launchSsoBrowserWindow() to extension service * cleanup & comments * add launchSsoBrowserWindow() to default service * setup launchSsoBrowserWindow() for Desktop * refactor to use toastService * remove unnecessary service injection * rename LoginService to LoginComponentService to avoid confusion with the LoginStrategyService * add jsdocs to LoginComponentService * rename loginService prop to loginComponentService * Add vault icon to anon layout. * Prevent email address validation on blur. * Fix comment typo. * Prefill email field when "create account" is clicked. * Use factory function to provide LoginEmailService. * Add test for RegisterFormComponent. * Remove back button todo. * Consolidate clearing loginEmailService values and routing * Remove unnecessary navigation. * Fix client navigation after login. * Consolidate login templates. * Break up LoginComponent into client-specific services. * Rename login.component to login-v1.component * Rename login.component to login-v1.component * Revert "Rename login.component to login-v1.component" This reverts commit 9a277d6ca5eb0c7b5337204f61caf259e269e61b. * Revert "Rename login.component to login-v1.component" This reverts commit 588a7af906da56ec52be03c993e1a1077a27bf61. * Rename login.component to login-v1.component except browser. * Comment out debug code. * Remove debug code. * Rename login.component to login-v1.component for browser. * Add login-with-passkey route to desktop. * Set feature flag to false. * Fix linting errors. * Populate email on registration start form. * Implement email population on all clients add add safeProviders. * Remove comment re. passing email to registration. * Add unauthUiRefreshRedirect utility function. * Add transparent border. * Merge main and add satisfies RouteDataProperties * PM-8111 - Extension - AppRoutingModule - Home route now redirects conditionally based on unauthenticated ui refresh feature flag. * PM-8111 - New Login Comp + Login Comp Svc - (1) Refactor naming and returns of getShowPasswordlessFlag to isLoginViaAuthRequestSupported (2) Replace showPasswordless with better composed variable names. * PM-8111 - TODO cleanup * PM-8111 - (1) Cleanup DefaultLoginComponentService (2) Sso Connector now checks client id property instead of reading it from state * PM-8111 - Two TODO cleanups * Remove specific client services. * Add isLoginWithPasskeySupported function to reduce client type checking in template. * Add styles missing from Browser to Create Account link. * Confirmed inline form errors working and removing todo comments. * Convert refactoring todo-rr-bw to standard todos. * Add login component services tests. * Cleanup formatting and remove unused provider. * Add comment to explain call to setLoginEmail. * Rearrange imports to fix lint error. * Adjust styles for password hint link. * Address PR feedback: use strict comparison. * Ensure Login with Passkey button is shown by setting clientType. * Update "continue" button from "submit" to "button" type. * Ensure Passkey login available for web and desktop. * Validate email on enter keypress. * Use click event to trigger goToHint. * Restructure handAuthResult to ensure we redirect to vault. * Add await to saveEmailSettings function. * Directly set clientType in individual login component services. * Get clientType via service. * Add back button. * Remove hardcoded colors from Vault Icon * Removing register component changes. * Removing register component changes. * Ensure isLoginWithPasskeySupported is only returns true for web client. * Remove Web/Desktop comment from html template * Update Storybook with initialLoginEmail * Fix translation error * Add test for unauthUiRefreshRedirect. * Rename goAfterLogIn to evaluatePassword and borrow logic from lock component. * Add DefaultLoginComponent tests. * Integrate changes to translations. * Simplify ngOnInit: remove webOnInit and move getLoginWithDevice to defaultOnInit I couldn't find any usages of qParams.org or qParams.sponsorshipToken on QA (signing up for family membership, creating organization, manually modifying query params), so I think these are safe to remove. * Fix translations. * Clean up and flush out register form tests. * Update variable name. * Remove unused enforcedPasswordPolicyOptions property. * Run prettier. * Add back safeProviders for LoginEmailService * Remove duplicate import. * Update v1 web login title. * Adjust overlay position of EnvironmentSelectorComponent for new layout. Since the switcher is located at the bottom of the screen we need to position it up above the trigger button so that it is not cut off. * Add new wave icon * Only send email in query parameters if set. * Remove test/debug code. * Replace loggedEmail with this.emailFormControl.value. * Move getLoginWithDevice call to loadEmailSettings. * Replace loggedEmail with this.emailFormControl.value. * Add todo comment re. inline errors. * Remove unused setPreviousUrl function. * Remove height / width from vault icon svg. * Use continue method unanimously * WIP remove validated email& display extension back button * Simplify getting query params * Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject * Simplify validateEmail method * Hide back button on init * Revert "Hide back button on init" This reverts commit e8de5e2bfcdcad8fab18ffcfb7b83ae748424d33. * Revert "Simplify validateEmail method" This reverts commit c9141a1cb57049890093e6b0e2f9c650492fe170. * Revert "Rework ExtensionAnonLayoutWrapperDataService to use BehaviorSubject" This reverts commit 8889ed3d3ccc0f93f0ebedcd621995ebd9d622c8. * simplify validateEmail method * Add primary / accent colors to wave icon * Remove debug code * PM-8111 - Tweak ShowBackButton to work * PM-8111 - LoginCompService - finish removal of setPreviousUrl from implementations. * PM-8111 - (1) Remove overriden default logo in anon layout (2) Update routing modules to have proper default login logo (3) LoginComp - update toggleLoginUiState to include logic to swap the icon back and forth as user navigates. * PM-8111 - LoginComp - on UI state change from MP entry to email entry, remove subtitle (this isn't supported yet, but it will be) * PM-8111 - LoginComp - Simplify toggleLoginUiState * PM-8111 - LoginComponent - Add known device logic into UI state change handler * PM-8111 - LoginComp - (1) Refactor name of getLoginWithDevice to be more accurate as getKnownDevice (2) Refactor calls to getKnownDevice to only occur if loginViaAuthRequestSupported * PM-8111 - LoginComp - add getKnownDevice docs * PM-8111 - LoginComponent - tweak docs * PM-8111 - LoginComp - Continue() - remove toast as the validation on submit logic currently shows validation errors - toast is extra and not needed. * Add isLoginViaAuthRequestSupported for DesktopLoginComponentService * Remove validating email on init * PM-8111 - ExtensionLoginComponentService - add tests for showBackButton * PM-8111 - style tweaks * PM-8111 - Extension - Refactor Overlay position to include extension default const to avoid repetition. * PM-8111 - Desktop AppRouting Module - remove login with passkey route as it isn't supported on desktop. * PM-8111 - Desktop - add default overlay position const * PM-8111 - DesktopLoginCompSvc - tests were not actually testing super method calls + finish testing launchSsoBrowserWindow * PM-8111 - Desktop Main.ts - remove dev test code * PM-8111 - WebLoginCompSvcTests - add success test cases for getOrgPolicies * PM-8111 - Remove duplicate translation keys * PM-8111 - DefaultLoginComponentSvcTests - add missing test * PM-8111 - DefaultLoginComponentServiceTests - add describes * PM-8111 - LoginSecondaryContentComponent - Add missing bitLink * Update to test both browser and desktop * Remove registration form test * Remove aliasing CryptoFunctionService and PlatformUtilsService as abstractions * Remove aliasing PlatformUtilsService and CryptoFunctionService as abstractions --------- Co-authored-by: Alec Rippberger <alec@livefront.com> Co-authored-by: Jared Snider <jsnider@bitwarden.com> Co-authored-by: Alec Rippberger <127791530+alec-livefront@users.noreply.github.com> Co-authored-by: Jared Snider <116684653+JaredSnider-Bitwarden@users.noreply.github.com>
2024-10-24 12:53:34 -07:00
}