From 5c5eb43242c43130341b120089c50f4f5ad5c997 Mon Sep 17 00:00:00 2001 From: "Visal .In" Date: Thu, 12 Oct 2023 18:51:44 +0700 Subject: [PATCH] feat: add change master key (#170) * feat: add change master key * refetch account to update the new test encrypt value --- src/renderer/components/Stack/index.tsx | 8 +- .../components/Stack/styles.module.scss | 6 +- .../WelcomeScreen/SetupAccountCallout.tsx | 154 ++++++++++++++++-- .../screens/WelcomeScreen/styles.module.scss | 10 +- src/renderer/utils/RemoteAPI.ts | 9 +- 5 files changed, 162 insertions(+), 25 deletions(-) diff --git a/src/renderer/components/Stack/index.tsx b/src/renderer/components/Stack/index.tsx index fcc6007f..81a1a4a2 100644 --- a/src/renderer/components/Stack/index.tsx +++ b/src/renderer/components/Stack/index.tsx @@ -6,7 +6,7 @@ interface StackProps { center?: boolean; full?: boolean; padding?: boolean; - spacing?: 'none' | 'md'; + spacing?: 'none' | 'sm' | 'md'; } export default memo(function Stack({ @@ -23,7 +23,11 @@ export default memo(function Stack({ vertical ? styles.vertical : undefined, full ? styles.full : undefined, padding ? styles.padding : undefined, - spacing === 'none' ? styles.spaceNone : undefined, + spacing === 'none' + ? styles.spaceNone + : spacing === 'sm' + ? styles.spaceSmall + : undefined, ] .filter(Boolean) .join(' '); diff --git a/src/renderer/components/Stack/styles.module.scss b/src/renderer/components/Stack/styles.module.scss index 09e0f5ce..68299eed 100644 --- a/src/renderer/components/Stack/styles.module.scss +++ b/src/renderer/components/Stack/styles.module.scss @@ -23,4 +23,8 @@ .spaceNone { gap: 0px; -} \ No newline at end of file +} + +.spaceSmall { + gap: 10px; +} diff --git a/src/renderer/screens/WelcomeScreen/SetupAccountCallout.tsx b/src/renderer/screens/WelcomeScreen/SetupAccountCallout.tsx index cda68520..65a42a2c 100644 --- a/src/renderer/screens/WelcomeScreen/SetupAccountCallout.tsx +++ b/src/renderer/screens/WelcomeScreen/SetupAccountCallout.tsx @@ -9,8 +9,9 @@ import { import PasswordField from 'renderer/components/PasswordField'; import { useCallback, useRef, useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faCheckCircle } from '@fortawesome/free-solid-svg-icons'; +import { faCheckCircle, faSpinner } from '@fortawesome/free-solid-svg-icons'; import LinkButton from 'renderer/components/Button/LinkButton'; +import ButtonGroup from 'renderer/components/ButtonGroup'; function SetupAccountNotLogin() { return ( @@ -93,23 +94,25 @@ function SetupAccountNewMasterKey({ user }: { user: LoginUser }) { - -

- -

- + + + + + + + ); } @@ -153,6 +156,11 @@ function SetupAccountExistingMasterKey({ user }: { user: LoginUser }) { placeholder="Master password" value={password} onChange={setPassword} + onKeyDown={(e) => { + if (e.key === 'Enter') { + onCheckMasterPassword(); + } + }} />

+ + + + + ); +} + function SetupAccountComplete({ user }: { user: LoginUser }) { + const [showChangePassword, setShowChangePassword] = useState(false); + + if (showChangePassword) { + return ( + { + setShowChangePassword(false); + }} + /> + ); + } + return (
@@ -175,6 +284,15 @@ function SetupAccountComplete({ user }: { user: LoginUser }) {

Welcome, {user.name}

Your account is secured with your master password.

+ +
    +
  • + setShowChangePassword(true)} + /> +
  • +
); diff --git a/src/renderer/screens/WelcomeScreen/styles.module.scss b/src/renderer/screens/WelcomeScreen/styles.module.scss index c552e055..aa5ad541 100644 --- a/src/renderer/screens/WelcomeScreen/styles.module.scss +++ b/src/renderer/screens/WelcomeScreen/styles.module.scss @@ -1,6 +1,11 @@ .calloutBackground { - background-color: #4158D0; - background-image: linear-gradient(43deg, #4158D0 0%, #C850C0 46%, #FFCC70 100%); + background-color: #4158d0; + background-image: linear-gradient( + 43deg, + #4158d0 0%, + #c850c0 46%, + #ffcc70 100% + ); padding: 40px; } @@ -61,4 +66,5 @@ .footer { border-top: 1px solid var(--color-border); padding-top: 10px; + margin-top: 10px; } diff --git a/src/renderer/utils/RemoteAPI.ts b/src/renderer/utils/RemoteAPI.ts index cdfd655a..fa4bf49d 100644 --- a/src/renderer/utils/RemoteAPI.ts +++ b/src/renderer/utils/RemoteAPI.ts @@ -34,9 +34,14 @@ export default class RemoteAPI { oldMasterPassword?: string, ) { return ( - await this.client.post('/v1/user/master_key', { + await this.client.post<{ + status: boolean; + error?: { + message?: string; + }; + }>('/v1/user/master_key', { masterkey: newMasterPassword, - oldMasterPassword: oldMasterPassword, + old_masterkey: oldMasterPassword, }) ).data; }