Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: add change email settings

ammarahm-ed5f3c89a93a32
diff --git a/apps/mobile/app/common/database/index.js b/apps/mobile/app/common/database/index.js
index 3e5db2303..dfbf4636f 100644
--- a/apps/mobile/app/common/database/index.js
+++ b/apps/mobile/app/common/database/index.js
@@ -49,16 +49,16 @@ export var 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",
- ISSUES_HOST: "https://issues.streetwriters.co"
- // API_HOST: "http://192.168.8.109:5264",
- // AUTH_HOST: "http://192.168.8.109:8264",
- // SSE_HOST: "http://192.168.8.109:7264",
- // SUBSCRIPTIONS_HOST: "http://192.168.8.109:9264",
- // ISSUES_HOST: "http://192.168.8.109: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",
+ // ISSUES_HOST: "https://issues.streetwriters.co"
+ API_HOST: "http://192.168.8.101:5264",
+ AUTH_HOST: "http://192.168.8.101:8264",
+ SSE_HOST: "http://192.168.8.101:7264",
+ SUBSCRIPTIONS_HOST: "http://192.168.8.101:9264",
+ ISSUES_HOST: "http://192.168.8.101:2624"
}
: {
API_HOST: "https://api.notesnook.com",
diff --git a/apps/mobile/app/components/auth/forgot-password.js b/apps/mobile/app/components/auth/forgot-password.js
index 14078fed9..e0a4d7e4a 100644
--- a/apps/mobile/app/components/auth/forgot-password.js
+++ b/apps/mobile/app/components/auth/forgot-password.js
@@ -97,6 +97,9 @@ export const ForgotPassword = () => {
text: email.current
});
}}
+ indicatorStyle={{
+ width: 100
+ }}
gestureEnabled
id="forgotpassword_sheet"
>
diff --git a/apps/mobile/app/components/sheets/change-email/index.tsx b/apps/mobile/app/components/sheets/change-email/index.tsx
new file mode 100644
index 000000000..c5859b5d2
--- /dev/null
+++ b/apps/mobile/app/components/sheets/change-email/index.tsx
@@ -0,0 +1,178 @@
+/*
+This file is part of the Notesnook project (https://notesnook.com/)
+
+Copyright (C) 2022 Streetwriters (Private) Limited
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+import React, { RefObject, useRef, useState } from "react";
+import { TextInput, View } from "react-native";
+import ActionSheet from "react-native-actions-sheet";
+import { db } from "../../../common/database";
+import {
+ eSendEvent,
+ presentSheet,
+ PresentSheetOptions,
+ ToastEvent
+} from "../../../services/event-manager";
+import DialogHeader from "../../dialog/dialog-header";
+import { Button } from "../../ui/button";
+import Input from "../../ui/input";
+
+type ChangeEmailProps = {
+ actionSheetRef: RefObject<ActionSheet>;
+ close?: () => void;
+ update?: (options: PresentSheetOptions) => void;
+};
+
+enum EmailChangeSteps {
+ verify,
+ changeEmail
+}
+
+export const ChangeEmail = ({
+ actionSheetRef,
+ close,
+ update
+}: ChangeEmailProps) => {
+ const [step, setStep] = useState(EmailChangeSteps.verify);
+ const emailChangeData = useRef<{
+ email?: string;
+ password?: string;
+ code?: string;
+ }>({});
+ const [loading, setLoading] = useState(false);
+ const [error, setError] = useState(false);
+ const emailInputRef = useRef<TextInput>(null);
+ const passInputRef = useRef<TextInput>(null);
+ const codeInputRef = useRef<TextInput>(null);
+
+ const onSubmit = async () => {
+ try {
+ if (step === EmailChangeSteps.verify) {
+ if (
+ !emailChangeData.current.email ||
+ !emailChangeData.current.password ||
+ error
+ )
+ return;
+ setLoading(true);
+ const verified = await db.user?.verifyPassword(
+ emailChangeData.current.password
+ );
+ if (!verified) throw new Error("Password is incorrect");
+ await db.user?.sendVerificationEmail(emailChangeData.current.email);
+ setStep(EmailChangeSteps.changeEmail);
+ setLoading(false);
+ } else {
+ if (
+ !emailChangeData.current.email ||
+ !emailChangeData.current.password ||
+ error ||
+ !emailChangeData.current.code
+ )
+ return;
+ await db.user?.changeEmail(
+ emailChangeData.current.email,
+ emailChangeData.current.password,
+ emailChangeData.current.code
+ );
+ eSendEvent("userLoggedIn");
+ close?.();
+ ToastEvent.show({
+ heading: `Email changed`,
+ message: `Your account email has been updated to ${emailChangeData.current.email}`,
+ type: "success",
+ context: "global"
+ });
+ }
+ } catch (e) {
+ setLoading(false);
+ ToastEvent.error(e as Error);
+ }
+ };
+
+ return (
+ <View style={{ paddingHorizontal: 12 }}>
+ <DialogHeader
+ title="Change email"
+ paragraph="Your account email will be changed without affecting your subscription or any other settings."
+ />
+ <View
+ style={{
+ marginTop: 12
+ }}
+ >
+ {step === EmailChangeSteps.verify ? (
+ <>
+ <Input
+ fwdRef={emailInputRef}
+ placeholder="Enter your new email"
+ validationType="email"
+ onErrorCheck={(e) => setError(e)}
+ onChangeText={(email) => {
+ emailChangeData.current.email = email;
+ }}
+ />
+ <Input
+ fwdRef={passInputRef}
+ placeholder="Enter your account password"
+ secureTextEntry
+ onChangeText={(pass) => {
+ emailChangeData.current.password = pass;
+ }}
+ />
+ </>
+ ) : (
+ <>
+ <Input
+ fwdRef={codeInputRef}
+ placeholder="Enter verification code sent to your new email"
+ onChangeText={(code) => {
+ emailChangeData.current.code = code;
+ }}
+ />
+ </>
+ )}
+ </View>
+
+ <Button
+ title={
+ loading
+ ? undefined
+ : step === EmailChangeSteps.verify
+ ? "Verify"
+ : "Change email"
+ }
+ type="accent"
+ width={250}
+ loading={loading}
+ onPress={onSubmit}
+ style={{
+ borderRadius: 100,
+ height: 45,
+ marginTop: 2
+ }}
+ />
+ </View>
+ );
+};
+
+ChangeEmail.present = () => {
+ presentSheet({
+ component: (ref, close, update) => (
+ <ChangeEmail actionSheetRef={ref} close={close} update={update} />
+ )
+ });
+};
diff --git a/apps/mobile/app/components/ui/sheet/index.js b/apps/mobile/app/components/ui/sheet/index.js
index ce4b28d39..697271fe4 100644
--- a/apps/mobile/app/components/ui/sheet/index.js
+++ b/apps/mobile/app/components/ui/sheet/index.js
@@ -83,6 +83,9 @@ const SheetWrapper = ({
testIDs={{
backdrop: "sheet-backdrop"
}}
+ indicatorStyle={{
+ width: 100
+ }}
drawUnderStatusBar={false}
containerStyle={style}
gestureEnabled={gestureEnabled}
diff --git a/apps/mobile/app/screens/notes/common.ts b/apps/mobile/app/screens/notes/common.ts
index 08adea892..e2d48b606 100644
--- a/apps/mobile/app/screens/notes/common.ts
+++ b/apps/mobile/app/screens/notes/common.ts
@@ -29,6 +29,7 @@ import { tabBarRef } from "../../utils/global-refs";
import { editorController, editorState } from "../editor/tiptap/utils";
import { NotesScreenParams } from "../../stores/use-navigation-store";
import { TopicType } from "../../utils/types";
+import { ChangeEmail } from "../../components/sheets/change-email";
export function toCamelCase(title: string) {
return title.slice(0, 1).toUpperCase() + title.slice(1);
diff --git a/apps/mobile/app/screens/settings/settings-data.tsx b/apps/mobile/app/screens/settings/settings-data.tsx
index bfdc80018..b4acecc87 100644
--- a/apps/mobile/app/screens/settings/settings-data.tsx
+++ b/apps/mobile/app/screens/settings/settings-data.tsx
@@ -27,6 +27,7 @@ import { db } from "../../common/database";
import { MMKV } from "../../common/database/mmkv";
import { ChangePassword } from "../../components/auth/change-password";
import { presentDialog } from "../../components/dialog/functions";
+import { ChangeEmail } from "../../components/sheets/change-email";
import ExportNotesSheet from "../../components/sheets/export-notes";
import { Issue } from "../../components/sheets/github/issue";
import { Progress } from "../../components/sheets/progress";
@@ -157,6 +158,14 @@ export const settingsGroups: SettingSection[] = [
},
description: "Setup a new password for your account."
},
+ {
+ id: "change-email",
+ name: "Change email",
+ modifer: async () => {
+ ChangeEmail.present();
+ },
+ description: "Setup a new email for your account."
+ },
{
id: "2fa-settings",
type: "screen",
diff --git a/apps/mobile/app/utils/color-scheme/index.js b/apps/mobile/app/utils/color-scheme/index.js
index fbeb78e1a..285630c69 100644
--- a/apps/mobile/app/utils/color-scheme/index.js
+++ b/apps/mobile/app/utils/color-scheme/index.js
@@ -89,7 +89,7 @@ export const COLOR_SCHEME_LIGHT = {
light: "#ffffff",
transGray: "#00000010",
border: "#E8E8E8",
- placeholder: "#a9a9a9"
+ placeholder: "#b6b6b6"
};
export const COLOR_SCHEME_PITCH_BLACK = {
...fixedColors,