[bug] Default rememberEmail to true (#1429)

This commit is contained in:
Addison Beck 2022-02-02 11:20:15 -05:00 committed by GitHub
parent 8910430dfb
commit 8030da2ed5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 8 deletions

View File

@ -0,0 +1,10 @@
import { StateService as BaseStateService } from "jslib-common/abstractions/state.service";
import { StorageOptions } from "jslib-common/models/domain/storageOptions";
import { Account } from "src/models/account";
export abstract class StateService extends BaseStateService<Account> {
getRememberEmail: (options?: StorageOptions) => Promise<boolean>;
setRememberEmail: (value: boolean, options?: StorageOptions) => Promise<void>;
}

View File

@ -12,7 +12,8 @@ import { LogService } from "jslib-common/abstractions/log.service";
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service"; import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service"; import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
import { PolicyService } from "jslib-common/abstractions/policy.service"; import { PolicyService } from "jslib-common/abstractions/policy.service";
import { StateService } from "jslib-common/abstractions/state.service";
import { StateService } from "../../abstractions/state.service";
import { LoginComponent as BaseLoginComponent } from "jslib-angular/components/login.component"; import { LoginComponent as BaseLoginComponent } from "jslib-angular/components/login.component";
@ -30,7 +31,6 @@ export class LoginComponent extends BaseLoginComponent {
router: Router, router: Router,
i18nService: I18nService, i18nService: I18nService,
private route: ActivatedRoute, private route: ActivatedRoute,
stateService: StateService,
platformUtilsService: PlatformUtilsService, platformUtilsService: PlatformUtilsService,
environmentService: EnvironmentService, environmentService: EnvironmentService,
passwordGenerationService: PasswordGenerationService, passwordGenerationService: PasswordGenerationService,
@ -38,7 +38,8 @@ export class LoginComponent extends BaseLoginComponent {
private apiService: ApiService, private apiService: ApiService,
private policyService: PolicyService, private policyService: PolicyService,
logService: LogService, logService: LogService,
ngZone: NgZone ngZone: NgZone,
protected stateService: StateService
) { ) {
super( super(
authService, authService,
@ -78,6 +79,7 @@ export class LoginComponent extends BaseLoginComponent {
}); });
} }
await super.ngOnInit(); await super.ngOnInit();
this.rememberEmail = await this.stateService.getRememberEmail();
}); });
const invite = await this.stateService.getOrganizationInvitation(); const invite = await this.stateService.getOrganizationInvitation();
@ -115,4 +117,12 @@ export class LoginComponent extends BaseLoginComponent {
this.router.navigate([this.successRoute]); this.router.navigate([this.successRoute]);
} }
} }
async submit() {
await this.stateService.setRememberEmail(this.rememberEmail);
if (!this.rememberEmail) {
await this.stateService.setRememberedEmail(null);
}
await super.submit();
}
} }

View File

@ -7,6 +7,7 @@ import { I18nService } from "../../services/i18n.service";
import { MemoryStorageService } from "../../services/memoryStorage.service"; import { MemoryStorageService } from "../../services/memoryStorage.service";
import { PasswordRepromptService } from "../../services/passwordReprompt.service"; import { PasswordRepromptService } from "../../services/passwordReprompt.service";
import { StateService } from "../../services/state.service"; import { StateService } from "../../services/state.service";
import { StateMigrationService } from "../../services/stateMigration.service";
import { WebPlatformUtilsService } from "../../services/webPlatformUtils.service"; import { WebPlatformUtilsService } from "../../services/webPlatformUtils.service";
import { EventService } from "./event.service"; import { EventService } from "./event.service";
@ -24,7 +25,6 @@ import { ContainerService } from "jslib-common/services/container.service";
import { CryptoService } from "jslib-common/services/crypto.service"; import { CryptoService } from "jslib-common/services/crypto.service";
import { EventService as EventLoggingService } from "jslib-common/services/event.service"; import { EventService as EventLoggingService } from "jslib-common/services/event.service";
import { ImportService } from "jslib-common/services/import.service"; import { ImportService } from "jslib-common/services/import.service";
import { StateMigrationService } from "jslib-common/services/stateMigration.service";
import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service"; import { VaultTimeoutService } from "jslib-common/services/vaultTimeout.service";
import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.service"; import { ApiService as ApiServiceAbstraction } from "jslib-common/abstractions/api.service";
@ -46,7 +46,7 @@ import { MessagingService as MessagingServiceAbstraction } from "jslib-common/ab
import { NotificationsService as NotificationsServiceAbstraction } from "jslib-common/abstractions/notifications.service"; import { NotificationsService as NotificationsServiceAbstraction } from "jslib-common/abstractions/notifications.service";
import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "jslib-common/abstractions/passwordReprompt.service"; import { PasswordRepromptService as PasswordRepromptServiceAbstraction } from "jslib-common/abstractions/passwordReprompt.service";
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "jslib-common/abstractions/platformUtils.service"; import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "jslib-common/abstractions/platformUtils.service";
import { StateService as StateServiceAbstraction } from "jslib-common/abstractions/state.service"; import { StateService as BaseStateServiceAbstraction } from "jslib-common/abstractions/state.service";
import { StateMigrationService as StateMigrationServiceAbstraction } from "jslib-common/abstractions/stateMigration.service"; import { StateMigrationService as StateMigrationServiceAbstraction } from "jslib-common/abstractions/stateMigration.service";
import { StorageService as StorageServiceAbstraction } from "jslib-common/abstractions/storage.service"; import { StorageService as StorageServiceAbstraction } from "jslib-common/abstractions/storage.service";
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service"; import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "jslib-common/abstractions/vaultTimeout.service";
@ -59,6 +59,8 @@ import { GlobalState } from "../../models/globalState";
import { GlobalStateFactory } from "jslib-common/factories/globalStateFactory"; import { GlobalStateFactory } from "jslib-common/factories/globalStateFactory";
import { StateFactory } from "jslib-common/factories/stateFactory"; import { StateFactory } from "jslib-common/factories/stateFactory";
import { StateService as StateServiceAbstraction } from "../../abstractions/state.service";
export function initFactory( export function initFactory(
window: Window, window: Window,
environmentService: EnvironmentServiceAbstraction, environmentService: EnvironmentServiceAbstraction,
@ -215,6 +217,10 @@ export function initFactory(
StateMigrationServiceAbstraction, StateMigrationServiceAbstraction,
], ],
}, },
{
provide: BaseStateServiceAbstraction,
useExisting: StateServiceAbstraction,
},
{ {
provide: PasswordRepromptServiceAbstraction, provide: PasswordRepromptServiceAbstraction,
useClass: PasswordRepromptService, useClass: PasswordRepromptService,

View File

@ -4,4 +4,5 @@ import { GlobalState as BaseGlobalState } from "jslib-common/models/domain/globa
export class GlobalState extends BaseGlobalState { export class GlobalState extends BaseGlobalState {
theme?: ThemeType = ThemeType.Light; theme?: ThemeType = ThemeType.Light;
rememberEmail: boolean = true;
} }

View File

@ -1,13 +1,36 @@
import { StateService as BaseStateService } from "jslib-common/services/state.service"; import { StateService as BaseStateService } from "jslib-common/services/state.service";
import { Account } from "../models/account"; import { Account } from "../models/account";
import { GlobalState } from "../models/globalState";
import { StateService as StateServiceAbstraction } from "jslib-common/abstractions/state.service"; import { StateService as StateServiceAbstraction } from "../abstractions/state.service";
export class StateService extends BaseStateService<Account> implements StateServiceAbstraction { import { StorageOptions } from "jslib-common/models/domain/storageOptions";
export class StateService
extends BaseStateService<Account, GlobalState>
implements StateServiceAbstraction
{
async addAccount(account: Account) { async addAccount(account: Account) {
// Apply web overides to default account values // Apply web overides to default account values
account = new Account(account); account = new Account(account);
await super.addAccount(account); await super.addAccount(account);
} }
async getRememberEmail(options?: StorageOptions) {
return (
await this.getGlobals(this.reconcileOptions(options, await this.defaultOnDiskLocalOptions()))
)?.rememberEmail;
}
async setRememberEmail(value: boolean, options?: StorageOptions): Promise<void> {
const globals = await this.getGlobals(
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())
);
globals.rememberEmail = value;
await this.saveGlobals(
globals,
this.reconcileOptions(options, await this.defaultOnDiskLocalOptions())
);
}
} }

View File

@ -0,0 +1,11 @@
import { StateMigrationService as BaseStateMigrationService } from "jslib-common/services/stateMigration.service";
import { GlobalState } from "../models/globalState";
export class StateMigrationService extends BaseStateMigrationService<GlobalState> {
protected async migrationStateFrom1To2(): Promise<void> {
await super.migrateStateFrom1To2();
const globals = (await this.get<GlobalState>("global")) ?? this.globalStateFactory.create();
globals.rememberEmail = (await this.get<boolean>("rememberEmail")) ?? globals.rememberEmail;
await this.set("global", globals);
}
}

View File

@ -13,5 +13,10 @@
"preserveWhitespaces": true "preserveWhitespaces": true
}, },
"files": ["src/app/polyfills.ts", "src/app/main.ts", "bitwarden_license/src/app/main.ts"], "files": ["src/app/polyfills.ts", "src/app/main.ts", "bitwarden_license/src/app/main.ts"],
"include": ["src/connectors/*.ts", "src/models/*.ts", "src/services/*.ts"] "include": [
"src/connectors/*.ts",
"src/models/*.ts",
"src/services/*.ts",
"src/abstractions/*.ts"
]
} }