Skip to content

Commit 8f97e35

Browse files
committed
move strings to locales file for splash, log in, register, password reset
1 parent c73d3ba commit 8f97e35

7 files changed

Lines changed: 121 additions & 64 deletions

File tree

api/src/controllers/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export const initiatePasswordReset = (mail) => async (req, res, next) => {
371371
const user = await User.findOne({ email: req.body.email }).lean();
372372

373373
if (!user) {
374-
res.status(404).send("User does not exist");
374+
res.sendStatus(200);
375375
return;
376376
}
377377

@@ -397,7 +397,7 @@ export const initiatePasswordReset = (mail) => async (req, res, next) => {
397397
${process.env.SQ_BASE_URL}/reset-password/finalise?token=${token}`,
398398
});
399399

400-
res.send(token);
400+
res.sendStatus(200);
401401
} catch (e) {
402402
next(e);
403403
}

client/locales.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@
77
"username": "Username",
88
"usernameRules": "Can only consist of letters, numbers, and “.”",
99
"password": "Password",
10+
"totp": "One-time code",
1011
"resetPassword": "Reset password",
11-
"newPassword": "New password"
12+
"newPassword": "New password",
13+
"welcomeBack": "Welcome back",
14+
"logInFailed": "Could not log in",
15+
"welcome": "Welcome",
16+
"registerFailed": "Could not register",
17+
"registrationClosed": "Registration closed",
18+
"passwordResetRequestSuccess": "If an account with that email address exists, you will receive an email shortly",
19+
"passwordResetRequestFailed": "Could not initiate password reset",
20+
"passwordResetSuccess": "Password was reset successfully",
21+
"passwordResetFailed": "Could not complete password reset",
22+
"tokenError": "Token error"
1223
},
1324
"fr": {
1425
"logIn": "Se connecter"

client/pages/index.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useContext } from "react";
22
import getConfig from "next/config";
33
import Link from "next/link";
44
import { useRouter } from "next/router";
@@ -13,34 +13,38 @@ import Infobox from "../components/Infobox";
1313
import { ErrorCircle } from "@styled-icons/boxicons-regular/ErrorCircle";
1414
import { News } from "@styled-icons/boxicons-regular/News";
1515
import moment from "moment/moment";
16+
import LocaleContext from "../utils/LocaleContext";
1617

17-
const PublicLanding = ({ name, allowRegister }) => (
18-
<Box
19-
minHeight="calc(100vh - 173px)"
20-
display="flex"
21-
alignItems="center"
22-
justifyContent="center"
23-
flexDirection="column"
24-
>
25-
<Text as="h1" fontSize={6} textAlign="center" lineHeight={1.2}>
26-
{name}
27-
</Text>
28-
<Box display="flex" mt={4}>
29-
<Box>
30-
<Link href="/login">
31-
<a>Log in</a>
32-
</Link>
33-
</Box>
34-
{allowRegister && (
35-
<Box ml={4}>
36-
<Link href="/register">
37-
<a>Register</a>
18+
const PublicLanding = ({ name, allowRegister }) => {
19+
const { getLocaleString } = useContext(LocaleContext);
20+
return (
21+
<Box
22+
minHeight="calc(100vh - 173px)"
23+
display="flex"
24+
alignItems="center"
25+
justifyContent="center"
26+
flexDirection="column"
27+
>
28+
<Text as="h1" fontSize={6} textAlign="center" lineHeight={1.2}>
29+
{name}
30+
</Text>
31+
<Box display="flex" mt={4}>
32+
<Box>
33+
<Link href="/login">
34+
<a>{getLocaleString("logIn")}</a>
3835
</Link>
3936
</Box>
40-
)}
37+
{allowRegister && (
38+
<Box ml={4}>
39+
<Link href="/register">
40+
<a>{getLocaleString("register")}</a>
41+
</Link>
42+
</Box>
43+
)}
44+
</Box>
4145
</Box>
42-
</Box>
43-
);
46+
);
47+
};
4448

4549
const Index = ({
4650
token,

client/pages/login.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Input from "../components/Input";
99
import Button from "../components/Button";
1010
import { NotificationContext } from "../components/Notifications";
1111
import LoadingContext from "../utils/LoadingContext";
12+
import LocaleContext from "../utils/LocaleContext";
1213
import { usernamePattern } from "./register";
1314

1415
const Login = () => {
@@ -18,6 +19,7 @@ const Login = () => {
1819

1920
const { addNotification } = useContext(NotificationContext);
2021
const { setLoading } = useContext(LoadingContext);
22+
const { getLocaleString } = useContext(LocaleContext);
2123

2224
const router = useRouter();
2325

@@ -57,11 +59,17 @@ const Login = () => {
5759
setCookie("userId", uid, { path: "/", expires });
5860
setCookie("username", username, { path: "/", expires });
5961

60-
addNotification("success", `Welcome back ${form.get("username")}!`);
62+
addNotification(
63+
"success",
64+
`${getLocaleString("welcomeBack")} ${form.get("username")}!`
65+
);
6166

6267
router.push("/");
6368
} catch (e) {
64-
addNotification("error", `Could not log in: ${e.message}`);
69+
addNotification(
70+
"error",
71+
`${getLocaleString("logInFailed")}: ${e.message}`
72+
);
6573
console.error(e);
6674
}
6775

@@ -70,33 +78,33 @@ const Login = () => {
7078

7179
return (
7280
<>
73-
<SEO title="Log in" />
81+
<SEO title={getLocaleString("logIn")} />
7482
<Text as="h1" mb={5}>
75-
Log in
83+
{getLocaleString("logIn")}
7684
</Text>
7785
<form onSubmit={handleLogin}>
7886
<Input
7987
name="username"
80-
label="Username"
88+
label={getLocaleString("username")}
8189
pattern={usernamePattern}
8290
mb={4}
8391
required
8492
/>
8593
<Input
8694
name="password"
8795
type="password"
88-
label="Password"
96+
label={getLocaleString("password")}
8997
mb={4}
9098
required
9199
/>
92100
{totpRequired && (
93-
<Input name="totp" label="One-time code" mb={4} required />
101+
<Input name="totp" label={getLocaleString("totp")} mb={4} required />
94102
)}
95-
<Button>Log in</Button>
103+
<Button>{getLocaleString("logIn")}</Button>
96104
</form>
97105
<Link href="/reset-password/initiate" passHref>
98106
<Text as="a" display="inline-block" mt={5}>
99-
Reset password
107+
{getLocaleString("resetPassword")}
100108
</Text>
101109
</Link>
102110
</>

client/pages/register.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Button from "../components/Button";
1212
import Box from "../components/Box";
1313
import { NotificationContext } from "../components/Notifications";
1414
import LoadingContext from "../utils/LoadingContext";
15+
import LocaleContext from "../utils/LocaleContext";
1516

1617
export const usernamePattern = "[A-Za-z0-9.]+";
1718

@@ -21,6 +22,7 @@ const Register = ({ token: inviteToken, tokenError }) => {
2122
const { colors } = useContext(ThemeContext);
2223
const { addNotification } = useContext(NotificationContext);
2324
const { setLoading } = useContext(LoadingContext);
25+
const { getLocaleString } = useContext(LocaleContext);
2426

2527
const router = useRouter();
2628

@@ -60,11 +62,17 @@ const Register = ({ token: inviteToken, tokenError }) => {
6062
setCookie("userId", uid, { path: "/", expires });
6163
setCookie("username", username, { path: "/", expires });
6264

63-
addNotification("success", `Welcome ${form.get("username")}!`);
65+
addNotification(
66+
"success",
67+
`${getLocaleString("welcome")} ${form.get("username")}!`
68+
);
6469

6570
router.push("/");
6671
} catch (e) {
67-
addNotification("error", `Could not register: ${e.message}`);
72+
addNotification(
73+
"error",
74+
`${getLocaleString("registerFailed")}: ${e.message}`
75+
);
6876
console.error(e);
6977
}
7078

@@ -74,40 +82,46 @@ const Register = ({ token: inviteToken, tokenError }) => {
7482
if (SQ_ALLOW_REGISTER !== "open" && SQ_ALLOW_REGISTER !== "invite") {
7583
return (
7684
<>
77-
<SEO title="Register" />
85+
<SEO title={getLocaleString("register")} />
7886
<Text as="h1" mb={5}>
79-
Register
87+
{getLocaleString("register")}
8088
</Text>
81-
<p>Registration is closed.</p>
89+
<p>{getLocaleString("registrationClosed")}.</p>
8290
</>
8391
);
8492
}
8593

8694
return (
8795
<>
88-
<SEO title="Register" />
96+
<SEO title={getLocaleString("register")} />
8997
<Text as="h1" mb={5}>
90-
Register
98+
{getLocaleString("register")}
9199
</Text>
92100
{!tokenError ? (
93101
<form onSubmit={handleRegister}>
94-
<Input name="email" type="email" label="Email" mb={4} required />
102+
<Input
103+
name="email"
104+
type="email"
105+
label={getLocaleString("email")}
106+
mb={4}
107+
required
108+
/>
95109
<Input
96110
name="username"
97-
label="Username"
98-
placeholder={`Can only consist of letters, numbers, and “.”`}
111+
label={getLocaleString("username")}
112+
placeholder={getLocaleString("usernameRules")}
99113
pattern={usernamePattern}
100114
mb={4}
101115
required
102116
/>
103117
<Input
104118
name="password"
105119
type="password"
106-
label="Password"
120+
label={getLocaleString("password")}
107121
mb={4}
108122
required
109123
/>
110-
<Button>Register</Button>
124+
<Button>{getLocaleString("register")}</Button>
111125
</form>
112126
) : (
113127
<Box
@@ -117,7 +131,9 @@ const Register = ({ token: inviteToken, tokenError }) => {
117131
borderRadius={1}
118132
p={4}
119133
>
120-
<Text>Could not register: {tokenError}</Text>
134+
<Text>
135+
{getLocaleString("registerFailed")}: {tokenError}
136+
</Text>
121137
</Box>
122138
)}
123139
</>

client/pages/reset-password/finalise.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import Input from "../../components/Input";
88
import Button from "../../components/Button";
99
import { NotificationContext } from "../../components/Notifications";
1010
import LoadingContext from "../../utils/LoadingContext";
11+
import LocaleContext from "../../utils/LocaleContext";
1112

1213
const FinalisePasswordReset = ({ token, email, tokenError }) => {
1314
const { addNotification } = useContext(NotificationContext);
1415
const { setLoading } = useContext(LoadingContext);
16+
const { getLocaleString } = useContext(LocaleContext);
1517

1618
const router = useRouter();
1719

@@ -42,13 +44,13 @@ const FinalisePasswordReset = ({ token, email, tokenError }) => {
4244
throw new Error(reason);
4345
}
4446

45-
addNotification("success", "Password was reset successfully");
47+
addNotification("success", getLocaleString("passwordResetSuccess"));
4648

4749
router.push("/login");
4850
} catch (e) {
4951
addNotification(
5052
"error",
51-
`Could not complete password reset: ${e.message}`
53+
`${getLocaleString("passwordResetFailed")}: ${e.message}`
5254
);
5355
console.error(e);
5456
}
@@ -58,24 +60,32 @@ const FinalisePasswordReset = ({ token, email, tokenError }) => {
5860

5961
return (
6062
<>
61-
<SEO title="Reset password" />
63+
<SEO title={getLocaleString("resetPassword")} />
6264
<Text as="h1" mb={5}>
63-
Reset password
65+
{getLocaleString("resetPassword")}
6466
</Text>
65-
<Input type="email" label="Email" value={email} mb={4} disabled />
67+
<Input
68+
type="email"
69+
label={getLocaleString("email")}
70+
value={email}
71+
mb={4}
72+
disabled
73+
/>
6674
{!tokenError ? (
6775
<form onSubmit={handleInitiate}>
6876
<Input
6977
name="newPassword"
7078
type="password"
71-
label="New password"
79+
label={getLocaleString("newPassword")}
7280
mb={4}
7381
required
7482
/>
75-
<Button>Reset password</Button>
83+
<Button>{getLocaleString("resetPassword")}</Button>
7684
</form>
7785
) : (
78-
<p>Token error: {tokenError}</p>
86+
<p>
87+
{getLocaleString("tokenError")}: {tokenError}
88+
</p>
7989
)}
8090
</>
8191
);

0 commit comments

Comments
 (0)