Skip to content

Commit 5153b43

Browse files
committed
mobile: enable password change and forgot password
1 parent 9ea7d09 commit 5153b43

File tree

8 files changed

+90
-107
lines changed

8 files changed

+90
-107
lines changed

apps/mobile/app/components/auth/change-password.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ export const ChangePassword = () => {
7373
throw new Error(strings.backupFailed() + `: ${result.error}`);
7474
}
7575

76-
await db.user.changePassword(oldPassword.current, password.current);
76+
const passwordChanged = await db.user.changePassword(
77+
oldPassword.current,
78+
password.current
79+
);
80+
81+
if (!passwordChanged) {
82+
throw new Error("Could not change user account password.");
83+
}
84+
7785
ToastManager.show({
7886
heading: strings.passwordChangedSuccessfully(),
7987
type: "success",

apps/mobile/app/components/auth/forgot-password.tsx

Lines changed: 65 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1919

2020
import React, { useRef, useState } from "react";
2121
import { TextInput, View } from "react-native";
22-
import ActionSheet from "react-native-actions-sheet";
2322
import { db } from "../../common/database";
2423
import { DDS } from "../../services/device-detection";
2524
import { ToastManager } from "../../services/event-manager";
@@ -35,9 +34,9 @@ import Paragraph from "../ui/typography/paragraph";
3534
import { strings } from "@notesnook/intl";
3635
import { DefaultAppStyles } from "../../utils/styles";
3736

38-
export const ForgotPassword = () => {
37+
export const ForgotPassword = ({ userEmail }: { userEmail: string }) => {
3938
const { colors } = useThemeColors("sheet");
40-
const email = useRef<string>(undefined);
39+
const email = useRef<string>(userEmail);
4140
const emailInputRef = useRef<TextInput>(null);
4241
const [error, setError] = useState(false);
4342
const [loading, setLoading] = useState(false);
@@ -87,94 +86,76 @@ export const ForgotPassword = () => {
8786

8887
return (
8988
<>
90-
<ActionSheet
91-
onBeforeShow={(data) => (email.current = data)}
92-
onClose={() => {
93-
setSent(false);
94-
setLoading(false);
95-
}}
96-
onOpen={() => {
97-
emailInputRef.current?.setNativeProps({
98-
text: email.current
99-
});
100-
}}
101-
indicatorStyle={{
102-
width: 100
103-
}}
104-
gestureEnabled
105-
id="forgotpassword_sheet"
106-
>
107-
{sent ? (
108-
<View
89+
{sent ? (
90+
<View
91+
style={{
92+
padding: DefaultAppStyles.GAP,
93+
justifyContent: "center",
94+
alignItems: "center",
95+
paddingBottom: 50
96+
}}
97+
>
98+
<IconButton
10999
style={{
110-
padding: DefaultAppStyles.GAP,
111-
justifyContent: "center",
112-
alignItems: "center",
113-
paddingBottom: 50
100+
width: null,
101+
height: null
114102
}}
115-
>
116-
<IconButton
117-
style={{
118-
width: null,
119-
height: null
120-
}}
121-
color={colors.primary.accent}
122-
name="email"
123-
size={50}
124-
/>
125-
<Heading>{strings.recoveryEmailSent()}</Heading>
126-
<Paragraph
127-
style={{
128-
textAlign: "center"
129-
}}
130-
>
131-
{strings.recoveryEmailSentDesc()}
132-
</Paragraph>
133-
</View>
134-
) : (
135-
<View
103+
color={colors.primary.accent}
104+
name="email"
105+
size={50}
106+
/>
107+
<Heading>{strings.recoveryEmailSent()}</Heading>
108+
<Paragraph
136109
style={{
137-
borderRadius: DDS.isTab ? 5 : 0,
138-
backgroundColor: colors.primary.background,
139-
zIndex: 10,
140-
width: "100%",
141-
padding: DefaultAppStyles.GAP
110+
textAlign: "center"
142111
}}
143112
>
144-
<DialogHeader title={strings.accountRecovery()} />
145-
<Seperator />
113+
{strings.recoveryEmailSentDesc()}
114+
</Paragraph>
115+
</View>
116+
) : (
117+
<View
118+
style={{
119+
borderRadius: DDS.isTab ? 5 : 0,
120+
backgroundColor: colors.primary.background,
121+
zIndex: 10,
122+
width: "100%",
123+
padding: DefaultAppStyles.GAP
124+
}}
125+
>
126+
<DialogHeader title={strings.accountRecovery()} />
127+
<Seperator />
146128

147-
<Input
148-
fwdRef={emailInputRef}
149-
onChangeText={(value) => {
150-
email.current = value;
151-
}}
152-
defaultValue={email.current}
153-
onErrorCheck={(e) => setError(e)}
154-
returnKeyLabel={strings.next()}
155-
returnKeyType="next"
156-
autoComplete="email"
157-
validationType="email"
158-
autoCorrect={false}
159-
autoCapitalize="none"
160-
errorMessage={strings.emailInvalid()}
161-
placeholder={strings.email()}
162-
onSubmit={() => {}}
163-
/>
129+
<Input
130+
fwdRef={emailInputRef}
131+
onChangeText={(value) => {
132+
email.current = value;
133+
}}
134+
defaultValue={email.current}
135+
onErrorCheck={(e) => setError(e)}
136+
returnKeyLabel={strings.next()}
137+
returnKeyType="next"
138+
autoComplete="email"
139+
validationType="email"
140+
autoCorrect={false}
141+
autoCapitalize="none"
142+
errorMessage={strings.emailInvalid()}
143+
placeholder={strings.email()}
144+
onSubmit={() => {}}
145+
/>
164146

165-
<Button
166-
style={{
167-
marginTop: DefaultAppStyles.GAP_VERTICAL,
168-
width: "100%"
169-
}}
170-
loading={loading}
171-
onPress={sendRecoveryEmail}
172-
type="accent"
173-
title={loading ? null : strings.next()}
174-
/>
175-
</View>
176-
)}
177-
</ActionSheet>
147+
<Button
148+
style={{
149+
marginTop: DefaultAppStyles.GAP_VERTICAL,
150+
width: "100%"
151+
}}
152+
loading={loading}
153+
onPress={sendRecoveryEmail}
154+
type="accent"
155+
title={loading ? null : strings.next()}
156+
/>
157+
</View>
158+
)}
178159
</>
179160
);
180161
};

apps/mobile/app/components/auth/login.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ import { TouchableOpacity, View, useWindowDimensions } from "react-native";
2525
import { SheetManager } from "react-native-actions-sheet";
2626
import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
2727
import { DDS } from "../../services/device-detection";
28-
import { eSendEvent, ToastManager } from "../../services/event-manager";
28+
import {
29+
eSendEvent,
30+
presentSheet,
31+
ToastManager
32+
} from "../../services/event-manager";
2933
import Navigation from "../../services/navigation";
3034
import PremiumService from "../../services/premium";
3135
import SettingsService from "../../services/settings";
@@ -110,7 +114,6 @@ export const Login = ({
110114
return (
111115
<>
112116
<AuthHeader />
113-
<ForgotPassword />
114117
<Dialog context="two_factor_verify" />
115118
<KeyboardAwareScrollView
116119
style={{
@@ -257,13 +260,10 @@ export const Login = ({
257260
paddingHorizontal: 0
258261
}}
259262
onPress={() => {
260-
ToastManager.show({
261-
type: "info",
262-
message:
263-
"Password changing has been disabled temporarily to address some issues faced by users. It will be enabled again once the issues have resolved."
263+
if (loading || !email.current) return;
264+
presentSheet({
265+
component: <ForgotPassword userEmail={email.current} />
264266
});
265-
// if (loading || !email.current) return;
266-
// SheetManager.show("forgotpassword_sheet");
267267
}}
268268
textStyle={{
269269
textDecorationLine: "underline"

apps/mobile/app/components/auth/session-expired.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const SessionExpired = () => {
9797
if (db.tokenManager._isTokenExpired(res))
9898
throw new Error("token expired");
9999

100-
const key = await db.user.getEncryptionKey();
100+
const key = await db.user.getDataEncryptionKeys();
101101
if (!key) throw new Error("No encryption key found.");
102102

103103
Sync.run("global", false, "full", async (complete) => {

apps/mobile/app/components/paywall/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ const PayWall = (props: NavigationProps<"PayWall">) => {
182182
>
183183
<IconButton
184184
name="close"
185+
color={colors.primary.icon}
185186
onPress={() => {
186187
Navigation.replace("FluidPanelsView", {});
187188
}}

apps/mobile/app/components/sheets/recovery-key/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class RecoveryKeySheet extends React.Component {
169169
};
170170

171171
onOpen = async () => {
172-
let k = await db.user.getEncryptionKey();
172+
let k = await db.user.getMasterKey();
173173
this.user = await db.user.getUser();
174174
if (k) {
175175
this.setState({

apps/mobile/app/screens/settings/settings-data.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,10 @@ export const settingsGroups: SettingSection[] = [
331331
{
332332
id: "change-password",
333333
name: strings.changePassword(),
334-
// type: "screen",
334+
type: "screen",
335335
description: strings.changePasswordDesc(),
336-
// component: "change-password",
337-
icon: "form-textbox-password",
338-
modifer: () => {
339-
ToastManager.show({
340-
type: "info",
341-
message:
342-
"Password changing has been disabled temporarily to address some issues faced by users. It will be enabled again once the issues have resolved."
343-
});
344-
}
336+
component: "change-password",
337+
icon: "form-textbox-password"
345338
},
346339
{
347340
id: "change-email",

apps/mobile/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)