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
add recovery key message flow
ammarahm-edfc05e0f6dd20
diff --git a/apps/mobile/src/components/Dialog/BaseDialog.js b/apps/mobile/src/components/Dialog/BaseDialog.jsindex 4227c7a84..e67df67e1 100644--- a/apps/mobile/src/components/Dialog/BaseDialog.js+++ b/apps/mobile/src/components/Dialog/BaseDialog.js@@ -24,7 +24,8 @@ const BaseDialog = ({bottom = false,background = null,animated = true,- bounce+ bounce,+ closeOnTouch=true}) => {const floating = useIsFloatingKeyboard();@@ -50,6 +51,7 @@ const BaseDialog = ({}}animationType={animation}onRequestClose={() => {+ if (!closeOnTouch) return nulluseSettingStore.getState().setSheetKeyboardHandler(true);onRequestClose && onRequestClose();}}>@@ -79,7 +81,7 @@ const BaseDialog = ({}]}><TouchableOpacity- onPress={onRequestClose}+ onPress={closeOnTouch ? onRequestClose : null}style={styles.overlayButton}/>{premium}diff --git a/apps/mobile/src/components/Dialog/index.js b/apps/mobile/src/components/Dialog/index.jsindex 9ee560534..c0fbd85ed 100644--- a/apps/mobile/src/components/Dialog/index.js+++ b/apps/mobile/src/components/Dialog/index.js@@ -31,7 +31,8 @@ export const Dialog = ({context = 'global'}) => {paragraphColor: colors.pri,input: false,inputPlaceholder: 'Enter some text',- defaultValue: ''+ defaultValue: '',+ disableBackdropClosing:false});useEffect(() => {@@ -89,6 +90,7 @@ export const Dialog = ({context = 'global'}) => {<BaseDialogstatusBarTranslucent={false}bounce={!dialogInfo.input}+ closeOnTouch={!dialogInfo.disableBackdropClosing}onShow={async () => {if (dialogInfo.input) {diff --git a/apps/mobile/src/components/PressableButton/index.js b/apps/mobile/src/components/PressableButton/index.jsindex f4aae7e84..887e6d544 100644--- a/apps/mobile/src/components/PressableButton/index.js+++ b/apps/mobile/src/components/PressableButton/index.js@@ -8,7 +8,7 @@ import { br } from '../../utils/SizeUtils';/**** @typedef {Object} buttonTypes- * @property {"transparent" | "gray" | "grayBg" | "accent" | "inverted" | "shade"} type type of button+ * @property {"transparent" | "gray" | "grayBg" | "accent" | "inverted" | "shade" | "grayAccent"} type type of button**@param {buttonTypes} type*diff --git a/apps/mobile/src/components/RecoveryKeyDialog/index.js b/apps/mobile/src/components/RecoveryKeyDialog/index.jsindex 4f250196f..f3f2dc598 100644--- a/apps/mobile/src/components/RecoveryKeyDialog/index.js+++ b/apps/mobile/src/components/RecoveryKeyDialog/index.js@@ -24,6 +24,8 @@ import Paragraph from '../Typography/Paragraph';import FileViewer from 'react-native-file-viewer';import * as ScopedStorage from 'react-native-scoped-storage';+import {MMKV} from '../../utils/mmkv';+import {clearMessage} from '../../services/Message';let RNFetchBlob;@@ -73,12 +75,14 @@ class RecoveryKeyDialog extends React.Component {visible: false});});- if (this.signup) {- this.signup = false;- setTimeout(() => {- eSendEvent(eOpenResultDialog);- }, 500);- }+ MMKV.setItem('userHasSavedRecoveryKey', 'true');+ clearMessage();+ // if (this.signup) {+ // this.signup = false;+ // setTimeout(() => {+ // eSendEvent(eOpenResultDialog);+ // }, 500);+ // }};async componentDidMount() {eSubscribeEvent(eOpenRecoveryKeyDialog, this.open);@@ -91,7 +95,7 @@ class RecoveryKeyDialog extends React.Component {saveQRCODE = async () => {this.svg.current?.toDataURL(async data => {try {- let path = await Storage.checkAndCreateDir('/');+ let path;RNFetchBlob = require('rn-fetch-blob').default;let fileName = 'nn_' + this.user.email + '_recovery_key_qrcode';fileName = sanitizeFilename(fileName, {replacement: '_'});@@ -105,6 +109,7 @@ class RecoveryKeyDialog extends React.Component {'base64');} else {+ path = await Storage.checkAndCreateDir('/');await RNFetchBlob.fs.writeFile(path + fileName, data, 'base64');}ToastEvent.show({@@ -120,14 +125,14 @@ class RecoveryKeyDialog extends React.Component {saveToTextFile = async () => {try {- let path = await Storage.checkAndCreateDir('/');+ let path;let fileName = 'nn_' + this.user?.email + '_recovery_key';fileName = sanitizeFilename(fileName, {replacement: '_'});fileName = fileName + '.txt';RNFetchBlob = require('rn-fetch-blob').default;if (Platform.OS === 'android') {- let file = await ScopedStorage.createDocument(+ let file = await ScopedStorage.createDocument(fileName,'text/plain',this.state.key,@@ -136,6 +141,7 @@ class RecoveryKeyDialog extends React.Component {if (!file) return;path = file.uri;} else {+ path = await Storage.checkAndCreateDir('/');await RNFetchBlob.fs.writeFile(path + fileName, this.state.key, 'utf8');path = path + fileName;}@@ -200,48 +206,31 @@ class RecoveryKeyDialog extends React.Component {paddingTop: 10}}><DialogHeader- title="Your data recovery key"+ title="Save account recovery key"paragraph="If you forget your password, you can recover yourdata and reset your password only using this recovery key."/><Viewstyle={{- backgroundColor: colors.nav,borderRadius: 5,- padding: 10,+ padding: 12,marginTop: 10}}><Paragraph- color={colors.icon}+ color={colors.pri}size={SIZE.sm}numberOfLines={2}+ selectablestyle={{width: '100%',maxWidth: '100%',paddingRight: 10,- marginBottom: 10,- textAlign: 'center'+ textAlign: 'center',+ textDecorationLine: 'underline'}}>{this.state.key}</Paragraph>-- <Button- onPress={() => {- Clipboard.setString(this.state.key);- ToastEvent.show({- heading: 'Recovery key copied!',- type: 'success',- context: 'local'- });- }}- icon="content-copy"- title="Copy to clipboard"- width="100%"- type="gray"- fontSize={SIZE.md}- height={50}- /></View><Seperator />@@ -267,12 +256,30 @@ class RecoveryKeyDialog extends React.Component {) : null}</View>+ <Button+ onPress={() => {+ Clipboard.setString(this.state.key);+ ToastEvent.show({+ heading: 'Recovery key copied!',+ type: 'success',+ context: 'local'+ });+ }}+ icon="content-copy"+ title="Copy to clipboard"+ width="100%"+ type="grayAccent"+ fontSize={SIZE.md}+ height={50}+ />+ <Seperator /><Buttontitle="Save QR-Code to gallery"onPress={this.saveQRCODE}width="100%"- type="accent"+ type="grayAccent"fontSize={SIZE.md}+ icon="qrcode"height={50}/><Seperator />@@ -280,7 +287,8 @@ class RecoveryKeyDialog extends React.Component {onPress={this.saveToTextFile}title="Save to text file"width="100%"- type="accent"+ type="grayAccent"+ icon="text"fontSize={SIZE.md}height={50}/>@@ -290,7 +298,8 @@ class RecoveryKeyDialog extends React.Component {onPress={this.shareFile}title="Share to Cloud"width="100%"- type="accent"+ type="grayAccent"+ icon="cloud"fontSize={SIZE.md}height={50}/>diff --git a/apps/mobile/src/services/Message.js b/apps/mobile/src/services/Message.jsindex bd6a57ce8..e38ebb4e3 100644--- a/apps/mobile/src/services/Message.js+++ b/apps/mobile/src/services/Message.js@@ -1,7 +1,36 @@-import { useMessageStore } from '../provider/stores';-import { eOpenLoginDialog } from '../utils/Events';-import { eSendEvent } from './EventManager';+import {useMessageStore} from '../provider/stores';+import {eOpenLoginDialog, eOpenRecoveryKeyDialog} from '../utils/Events';+import {eSendEvent} from './EventManager';import PremiumService from './PremiumService';+import {verifyUser} from '../views/Settings/functions';+import {MMKV} from '../utils/mmkv';++const recoveryKeyMessage = {+ visible: true,+ message: 'Keep your data safe if you lose password',+ actionText: 'Save your account recovery key',+ onPress: () => {+ verifyUser(+ null,+ () => {+ eSendEvent(eOpenRecoveryKeyDialog);+ },+ true,+ async () => {+ await MMKV.setItem('userHasSavedRecoveryKey', 'true');+ clearMessage();+ },+ 'I have saved my key already'+ );+ },+ data: {},+ icon: 'key',+ type: 'normal'+};++export function setRecoveryKeyMessage() {+ useMessageStore.getState().setMessage(recoveryKeyMessage);+}const loginMessage = {visible: true,@@ -12,7 +41,7 @@ const loginMessage = {},data: {},icon: 'account-outline',- type: 'normal',+ type: 'normal'};export function setLoginMessage() {@@ -28,7 +57,7 @@ const emailMessage = {},data: {},icon: 'email',- type: 'normal',+ type: 'normal'};export function setEmailVerifyMessage() {@@ -41,7 +70,7 @@ const noMessage = {actionText: '',onPress: null,data: {},- icon: 'account-outline',+ icon: 'account-outline'};export function clearMessage() {diff --git a/apps/mobile/src/utils/database.js b/apps/mobile/src/utils/database.jsindex 9dec12e66..a78d6c610 100644--- a/apps/mobile/src/utils/database.js+++ b/apps/mobile/src/utils/database.js@@ -14,15 +14,15 @@ export const db = new Database(db.host(__DEV__? {- // API_HOST: 'https://api.notesnook.com',- // AUTH_HOST: 'https://auth.streetwriters.co',- // SSE_HOST: 'https://events.streetwriters.co',- // SUBSCRIPTIONS_HOST: 'https://subscriptions.streetwriters.co'- API_HOST: 'http://192.168.10.29:5264',- AUTH_HOST: 'http://192.168.10.29:8264',- SSE_HOST: 'http://192.168.10.29:7264',- SUBSCRIPTIONS_HOST: 'http://192.168.10.29:9264',- ISSUES_HOST: 'http://192.168.10.29:2624'+ API_HOST: 'https://api.notesnook.com',+ AUTH_HOST: 'https://auth.streetwriters.co',+ SSE_HOST: 'https://events.streetwriters.co',+ SUBSCRIPTIONS_HOST: 'https://subscriptions.streetwriters.co'+ // API_HOST: 'http://192.168.10.29:5264',+ // AUTH_HOST: 'http://192.168.10.29:8264',+ // SSE_HOST: 'http://192.168.10.29:7264',+ // SUBSCRIPTIONS_HOST: 'http://192.168.10.29:9264',+ // ISSUES_HOST: 'http://192.168.10.29:2624'}: {API_HOST: 'https://api.notesnook.com',diff --git a/apps/mobile/src/utils/index.js b/apps/mobile/src/utils/index.jsindex 7987c478a..dfc1cd7b4 100755--- a/apps/mobile/src/utils/index.js+++ b/apps/mobile/src/utils/index.js@@ -282,6 +282,11 @@ export const BUTTON_TYPES = {text: 'icon',selected: 'nav'},+ grayAccent: {+ primary: 'nav',+ text: 'accent',+ selected: 'nav'+ },accent: (themeColor, text) => ({primary: themeColor,text: text,diff --git a/apps/mobile/src/utils/useAppEvents.js b/apps/mobile/src/utils/useAppEvents.jsindex bf4695fec..0e2101012 100644--- a/apps/mobile/src/utils/useAppEvents.js+++ b/apps/mobile/src/utils/useAppEvents.js@@ -32,14 +32,15 @@ import {import {clearMessage,setEmailVerifyMessage,- setLoginMessage+ setLoginMessage,+ setRecoveryKeyMessage} from '../services/Message';import Navigation from '../services/Navigation';import PremiumService from '../services/PremiumService';import SettingsService from '../services/SettingsService';import Sync from '../services/Sync';import {doInBackground, editing} from '.';-import { APP_VERSION } from "../../version";+import {APP_VERSION} from '../../version';import {updateStatusBarColor} from './Colors';import {db} from './database';import {@@ -365,6 +366,15 @@ export const useAppEvents = () => {}, 1000);}+ if (user.isEmailConfirmed) {+ let hasSavedRecoveryKey = await MMKV.getItem(+ 'userHasSavedRecoveryKey'+ );+ if (!hasSavedRecoveryKey) {+ setRecoveryKeyMessage();+ }+ }+await Sync.run();if (!user.isEmailConfirmed) {setEmailVerifyMessage();@@ -380,6 +390,14 @@ export const useAppEvents = () => {}} catch (e) {let user = await db.user.getUser();++ if (user?.isEmailConfirmed) {+ let hasSavedRecoveryKey = await MMKV.getItem('userHasSavedRecoveryKey');+ if (!hasSavedRecoveryKey) {+ setRecoveryKeyMessage();+ }+ }+if (user && !user.isEmailConfirmed) {setEmailVerifyMessage();} else if (!user) {diff --git a/apps/mobile/src/views/Settings/functions.js b/apps/mobile/src/views/Settings/functions.jsindex 9b24fe81e..5b9fe9234 100644--- a/apps/mobile/src/views/Settings/functions.js+++ b/apps/mobile/src/views/Settings/functions.js@@ -3,7 +3,7 @@ import {ToastEvent} from '../../services/EventManager';import {db} from '../../utils/database';import {sleep} from '../../utils/TimeUtils';-export async function verifyUser(context, onsuccess) {+export async function verifyUser(context, onsuccess,disableBackdropClosing,onclose,closeText) {presentDialog({context: context,title: "Verify it's you",@@ -12,6 +12,9 @@ export async function verifyUser(context, onsuccess) {paragraph: 'Please enter your account password',positiveText: 'Verify',secureTextEntry: true,+ disableBackdropClosing:disableBackdropClosing,+ onClose:onclose,+ negativeText:closeText || "Cancel",positivePress: async value => {try {let verified = await db.user.verifyPassword(value);