A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: impl account password changing
thecodrrc00ebf699d1e
diff --git a/apps/web/src/app.js b/apps/web/src/app.jsindex df35be77a..215cc9054 100644--- a/apps/web/src/app.js+++ b/apps/web/src/app.js@@ -19,7 +19,10 @@ import { EV } from "notes-core/common";import useTablet from "./utils/use-tablet";import { showBuyDialog } from "./components/dialogs/buy-dialog";import Banner from "./components/banner";-import { showAccountDeletedNotice } from "./components/dialogs/confirm";+import {+ showAccountDeletedNotice,+ showPasswordChangedNotice,+} from "./components/dialogs/confirm";function App() {const [show, setShow] = useState(true);@@ -62,6 +65,9 @@ function App() {EV.subscribe("user:deleted", async () => {await showAccountDeletedNotice();});+ EV.subscribe("user:passwordChanged", async () => {+ await showPasswordChangedNotice();+ });}, []);useEffect(() => {diff --git a/apps/web/src/common/index.js b/apps/web/src/common/index.jsindex e11e8aa7d..7911091a1 100644--- a/apps/web/src/common/index.js+++ b/apps/web/src/common/index.js@@ -15,8 +15,9 @@ import Config from "../utils/config";import { store as userstore } from "../stores/user-store";export const db = new Database(StorageInterface, EventSource);+//db.host("http://192.168.10.5:8100");db.host("http://localhost:4100");-+//db.host("https://api.notesnook.com");export const COLORS = {red: "#f44336",orange: "#FF9800",diff --git a/apps/web/src/components/dialogs/confirm.js b/apps/web/src/components/dialogs/confirm.jsindex fb4df025a..ab6586de9 100644--- a/apps/web/src/components/dialogs/confirm.js+++ b/apps/web/src/components/dialogs/confirm.js@@ -19,7 +19,9 @@ function Confirm(props) {onClick: props.onYes,disabled: !isButtonEnabled,}}- negativeButton={{ text: props.noText, onClick: props.onNo }}+ negativeButton={+ props.noText && { text: props.noText, onClick: props.onNo }+ }><Box><Text as="span" variant="body">@@ -144,9 +146,26 @@ export function showAccountDeleteConfirmation(username) {export function showAccountDeletedNotice() {return confirm(Icon.Logout, {- title: `Your account was deleted.`,+ title: `Account deleted`,message:"You deleted your account from another device. You have been logged out.",yesText: `Okay`,});}++export function showPasswordChangedNotice() {+ return confirm(Icon.Logout, {+ title: `Account password changed`,+ message:+ "Your account password was changed, please login again using the new password.",+ yesText: `Okay`,+ });+}++export function showAccountLoggedOutNotice(reason) {+ return confirm(Icon.Logout, {+ title: `You were logged out`,+ message: reason,+ yesText: `Okay`,+ });+}diff --git a/apps/web/src/components/dialogs/password-dialog.js b/apps/web/src/components/dialogs/password-dialog.jsindex 398146f89..9ceee410d 100644--- a/apps/web/src/components/dialogs/password-dialog.js+++ b/apps/web/src/components/dialogs/password-dialog.js@@ -1,7 +1,6 @@import React, { useState, useCallback, useMemo } from "react";import { Box, Text } from "rebass";import Dialog, { showDialog } from "./dialog";-import * as Icon from "../icons";import Field from "../field";const requiredValues = ["password", "newPassword", "oldPassword"];@@ -10,9 +9,10 @@ function PasswordDialog(props) {const [error, setError] = useState();const [isLoading, setIsLoading] = useState(false);- const isChangePasswordDialog = useMemo(() => type === "change_password", [- type,- ]);+ const isChangePasswordDialog = useMemo(+ () => type === "change_password" || "change_account_password",+ [type]+ );const submit = useCallback(async (data) => {@@ -25,7 +25,7 @@ function PasswordDialog(props) {setError("Wrong password.");}} catch (e) {- setError("Wrong password.");+ setError(e.message);} finally {setIsLoading(false);}@@ -38,7 +38,7 @@ function PasswordDialog(props) {title={props.title}description={props.subtitle}icon={props.icon}- onClose={props.onCancel}+ onClose={props.onClose}positiveButton={{props: {form: "passwordForm",@@ -48,7 +48,7 @@ function PasswordDialog(props) {loading: isLoading,disabled: isLoading,}}- negativeButton={{ text: "Cancel", onClick: props.onCancel }}+ negativeButton={{ text: "Cancel", onClick: props.onClose }}><Boxid="passwordForm"@@ -106,21 +106,18 @@ function getDialogData(type) {return {title: "Create Your Vault",subtitle: "A vault stores your notes in a password-encrypted storage.",- icon: Icon.Vault,positiveButtonText: "Create vault",};case "unlock_vault":return {title: "Unlock your Vault",subtitle: "Your vault will remain unlocked for 30 minutes.",- icon: Icon.Unlock,positiveButtonText: "Unlock vault",};case "unlock_note":return {title: "Unlock Note",subtitle: "Unlocking will make this note openly available.",- icon: Icon.Unlock,positiveButtonText: "Unlock note",};case "change_password":@@ -128,7 +125,13 @@ function getDialogData(type) {title: "Change Vault Password",subtitle:"All locked notes will be re-encrypted with the new password.",- icon: Icon.Unlock,+ positiveButtonText: "Change password",+ };+ case "change_account_password":+ return {+ title: "Change Account Password",+ subtitle:+ "All your data will be re-encrypted and synced with the new password.",positiveButtonText: "Change password",};default:@@ -137,16 +140,15 @@ function getDialogData(type) {}export function showPasswordDialog(type, validate) {- const { title, subtitle, icon, positiveButtonText } = getDialogData(type);+ const { title, subtitle, positiveButtonText } = getDialogData(type);return showDialog((perform) => (<PasswordDialogtype={type}title={title}subtitle={subtitle}- icon={icon}positiveButtonText={positiveButtonText}- onCancel={() => perform(false)}validate={validate}+ onClose={() => perform(false)}onDone={() => perform(true)}/>));diff --git a/apps/web/src/views/settings.js b/apps/web/src/views/settings.jsindex f101cd1ad..35322c821 100644--- a/apps/web/src/views/settings.js+++ b/apps/web/src/views/settings.js@@ -26,6 +26,7 @@ import Vault from "../common/vault";import ScrollContainer from "../components/scroll-container";import { showLoadingDialog } from "../components/dialogs/loadingdialog";import { showToast } from "../utils/toast";+import { showPasswordDialog } from "../components/dialogs/passworddialog";function importBackup() {return new Promise((resolve, reject) => {@@ -189,6 +190,25 @@ function Settings(props) {tip="In case you lose your password, you can recover your data using your recovery key."/></Button>+ <Button+ variant="list"+ onClick={async () => {+ const result = await showPasswordDialog(+ "change_account_password",+ (data) => {+ return db.user.changePassword(+ data.oldPassword,+ data.newPassword+ );+ }+ );+ if (result) {+ await showToast("success", "Account password changed!");+ }+ }}+ >+ <TextWithTip text="Change account password" />+ </Button><Buttonvariant="list"onClick={async () => {