From abfd1fa25412a73f2657bbc9d8915a539bd2b0c8 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 19 Aug 2020 11:15:04 -0400 Subject: [PATCH] abstract set password to jslib (#614) --- jslib | 2 +- src/app/accounts/change-password.component.ts | 97 ------------------- ...onent.html => set-password.component.html} | 0 src/app/accounts/set-password.component.ts | 37 +++++++ src/app/app-routing.module.ts | 4 +- src/app/app.module.ts | 4 +- 6 files changed, 42 insertions(+), 102 deletions(-) delete mode 100644 src/app/accounts/change-password.component.ts rename src/app/accounts/{change-password.component.html => set-password.component.html} (100%) create mode 100644 src/app/accounts/set-password.component.ts diff --git a/jslib b/jslib index 9957125d..719c9c56 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 9957125d3a9d416d7a60b9904f0b7882f3fb58d0 +Subproject commit 719c9c569beca2b726879ae2e84792220362d495 diff --git a/src/app/accounts/change-password.component.ts b/src/app/accounts/change-password.component.ts deleted file mode 100644 index 9e8acc58..00000000 --- a/src/app/accounts/change-password.component.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { Component } from '@angular/core'; -import { - ActivatedRoute, - Router, -} from '@angular/router'; - -import { ApiService } from 'jslib/abstractions/api.service'; -import { CipherService } from 'jslib/abstractions/cipher.service'; -import { CryptoService } from 'jslib/abstractions/crypto.service'; -import { FolderService } from 'jslib/abstractions/folder.service'; -import { I18nService } from 'jslib/abstractions/i18n.service'; -import { MessagingService } from 'jslib/abstractions/messaging.service'; -import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; -import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; -import { PolicyService } from 'jslib/abstractions/policy.service'; -import { SyncService } from 'jslib/abstractions/sync.service'; -import { UserService } from 'jslib/abstractions/user.service'; - -import { CipherString } from 'jslib/models/domain/cipherString'; -import { SymmetricCryptoKey } from 'jslib/models/domain/symmetricCryptoKey'; - -import { KeysRequest } from 'jslib/models/request/keysRequest'; -import { SetPasswordRequest } from 'jslib/models/request/setPasswordRequest'; - -import { - ChangePasswordComponent as BaseChangePasswordComponent, -} from 'jslib/angular/components/change-password.component'; - -import { KdfType } from 'jslib/enums/kdfType'; - -@Component({ - selector: 'app-accounts-change-password', - templateUrl: 'change-password.component.html', -}) -export class ChangePasswordComponent extends BaseChangePasswordComponent { - showPassword: boolean = false; - hint: string = ''; - - onSuccessfulChangePassword: () => Promise; - successRoute = 'vault'; - - constructor(apiService: ApiService, i18nService: I18nService, - cryptoService: CryptoService, messagingService: MessagingService, - userService: UserService, passwordGenerationService: PasswordGenerationService, - platformUtilsService: PlatformUtilsService, folderService: FolderService, - cipherService: CipherService, syncService: SyncService, - policyService: PolicyService, router: Router, private route: ActivatedRoute) { - super(apiService, i18nService, cryptoService, messagingService, userService, passwordGenerationService, - platformUtilsService, folderService, cipherService, syncService, policyService, router); - } - - async setupSubmitActions() { - this.kdf = KdfType.PBKDF2_SHA256; - const useLowerKdf = this.platformUtilsService.isEdge() || this.platformUtilsService.isIE(); - this.kdfIterations = useLowerKdf ? 10000 : 100000; - return true; - } - - async performSubmitActions(masterPasswordHash: string, key: SymmetricCryptoKey, - encKey: [SymmetricCryptoKey, CipherString]) { - const request = new SetPasswordRequest(); - request.masterPasswordHash = masterPasswordHash; - request.key = encKey[1].encryptedString; - request.masterPasswordHint = this.hint; - request.kdf = this.kdf; - request.kdfIterations = this.kdfIterations; - - const keys = await this.cryptoService.makeKeyPair(encKey[0]); - request.keys = new KeysRequest(keys[0], keys[1].encryptedString); - - try { - this.formPromise = this.apiService.setPassword(request); - await this.formPromise; - - await this.userService.setInformation(await this.userService.getUserId(), await this.userService.getEmail(), - this.kdf, this.kdfIterations); - await this.cryptoService.setKey(key); - await this.cryptoService.setKeyHash(masterPasswordHash); - await this.cryptoService.setEncKey(encKey[1].encryptedString); - await this.cryptoService.setEncPrivateKey(keys[1].encryptedString); - - if (this.onSuccessfulChangePassword != null) { - this.onSuccessfulChangePassword(); - } else { - this.router.navigate([this.successRoute]); - } - } catch { - this.platformUtilsService.showToast('error', null, this.i18nService.t('errorOccurred')); - } - } - - togglePassword(confirmField: boolean) { - this.platformUtilsService.eventTrack('Toggled Master Password on Set Password'); - this.showPassword = !this.showPassword; - document.getElementById(confirmField ? 'masterPasswordRetype' : 'masterPassword').focus(); - } -} diff --git a/src/app/accounts/change-password.component.html b/src/app/accounts/set-password.component.html similarity index 100% rename from src/app/accounts/change-password.component.html rename to src/app/accounts/set-password.component.html diff --git a/src/app/accounts/set-password.component.ts b/src/app/accounts/set-password.component.ts new file mode 100644 index 00000000..9598114d --- /dev/null +++ b/src/app/accounts/set-password.component.ts @@ -0,0 +1,37 @@ +import { Component } from '@angular/core'; +import { + ActivatedRoute, + Router, +} from '@angular/router'; + +import { ApiService } from 'jslib/abstractions/api.service'; +import { CipherService } from 'jslib/abstractions/cipher.service'; +import { CryptoService } from 'jslib/abstractions/crypto.service'; +import { FolderService } from 'jslib/abstractions/folder.service'; +import { I18nService } from 'jslib/abstractions/i18n.service'; +import { MessagingService } from 'jslib/abstractions/messaging.service'; +import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service'; +import { PlatformUtilsService } from 'jslib/abstractions/platformUtils.service'; +import { PolicyService } from 'jslib/abstractions/policy.service'; +import { SyncService } from 'jslib/abstractions/sync.service'; +import { UserService } from 'jslib/abstractions/user.service'; + +import { + SetPasswordComponent as BaseSetPasswordComponent, +} from 'jslib/angular/components/set-password.component'; + +@Component({ + selector: 'app-set-password', + templateUrl: 'set-password.component.html', +}) +export class SetPasswordComponent extends BaseSetPasswordComponent { + constructor(apiService: ApiService, i18nService: I18nService, + cryptoService: CryptoService, messagingService: MessagingService, + userService: UserService, passwordGenerationService: PasswordGenerationService, + platformUtilsService: PlatformUtilsService, folderService: FolderService, + cipherService: CipherService, syncService: SyncService, + policyService: PolicyService, router: Router, route: ActivatedRoute) { + super(apiService, i18nService, cryptoService, messagingService, userService, passwordGenerationService, + platformUtilsService, folderService, cipherService, syncService, policyService, router, route); + } +} diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 9a376fc3..49fe65ed 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -9,13 +9,13 @@ import { OrganizationLayoutComponent } from './layouts/organization-layout.compo import { UserLayoutComponent } from './layouts/user-layout.component'; import { AcceptOrganizationComponent } from './accounts/accept-organization.component'; -import { ChangePasswordComponent } from './accounts/change-password.component'; import { HintComponent } from './accounts/hint.component'; import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RecoverDeleteComponent } from './accounts/recover-delete.component'; import { RecoverTwoFactorComponent } from './accounts/recover-two-factor.component'; import { RegisterComponent } from './accounts/register.component'; +import { SetPasswordComponent } from './accounts/set-password.component'; import { SsoComponent } from './accounts/sso.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; import { VerifyEmailTokenComponent } from './accounts/verify-email-token.component'; @@ -107,7 +107,7 @@ const routes: Routes = [ data: { titleId: 'createAccount' }, // TODO }, { - path: 'change-password', component: ChangePasswordComponent, + path: 'set-password', component: SetPasswordComponent, data: { titleId: 'setMasterPassword' }, }, { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 026b3dbb..17b98e8b 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -28,13 +28,13 @@ import { OrganizationLayoutComponent } from './layouts/organization-layout.compo import { UserLayoutComponent } from './layouts/user-layout.component'; import { AcceptOrganizationComponent } from './accounts/accept-organization.component'; -import { ChangePasswordComponent as AccountsChangePasswordComponent } from './accounts/change-password.component'; import { HintComponent } from './accounts/hint.component'; import { LockComponent } from './accounts/lock.component'; import { LoginComponent } from './accounts/login.component'; import { RecoverDeleteComponent } from './accounts/recover-delete.component'; import { RecoverTwoFactorComponent } from './accounts/recover-two-factor.component'; import { RegisterComponent } from './accounts/register.component'; +import { SetPasswordComponent } from './accounts/set-password.component'; import { SsoComponent } from './accounts/sso.component'; import { TwoFactorOptionsComponent } from './accounts/two-factor-options.component'; import { TwoFactorComponent } from './accounts/two-factor.component'; @@ -249,7 +249,7 @@ registerLocaleData(localeZhTw, 'zh-TW'); A11yTitleDirective, AcceptOrganizationComponent, AccountComponent, - AccountsChangePasswordComponent, + SetPasswordComponent, AddCreditComponent, AddEditComponent, AdjustPaymentComponent,