@flink-app/generic-auth-plugin 0.2.0-beta.7 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flink/generatedHandlers.ts +2 -1
- package/.flink/generatedRepos.ts +1 -1
- package/.flink/schemas/schemas.json +12 -12
- package/.flink/schemas/schemas.ts +13 -13
- package/.flink/start.ts +1 -1
- package/dist/.flink/generatedHandlers.js +1 -1
- package/dist/.flink/generatedRepos.js +1 -1
- package/dist/.flink/schemas/schemas.d.ts +12 -12
- package/dist/.flink/schemas/schemas.json +12 -12
- package/dist/.flink/start.js +1 -1
- package/dist/src/coreFunctions.js +32 -21
- package/dist/src/handlers/Management/DeleteUserByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/DeleteUserByUserid.js +2 -2
- package/dist/src/handlers/Management/GetSchema.d.ts +1 -1
- package/dist/src/handlers/Management/GetSchema.js +2 -2
- package/dist/src/handlers/Management/GetUser.d.ts +1 -1
- package/dist/src/handlers/Management/GetUser.js +2 -2
- package/dist/src/handlers/Management/GetUserByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/GetUserByUserid.js +4 -4
- package/dist/src/handlers/Management/PutUserPasswordByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/PutUserPasswordByUserid.js +3 -3
- package/dist/src/handlers/Management/PutUserProfileByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/PutUserProfileByUserid.js +4 -4
- package/dist/src/handlers/Management/PutUserProfileByUseridAppend.d.ts +1 -1
- package/dist/src/handlers/Management/PutUserProfileByUseridAppend.js +4 -4
- package/dist/src/handlers/Management/PutUserRolesByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/PutUserRolesByUserid.js +4 -4
- package/dist/src/handlers/Management/PutUserUsernameByUserid.d.ts +1 -1
- package/dist/src/handlers/Management/PutUserUsernameByUserid.js +7 -5
- package/dist/src/handlers/UserCreate.d.ts +1 -1
- package/dist/src/handlers/UserCreate.js +2 -2
- package/dist/src/handlers/UserLogin.d.ts +1 -1
- package/dist/src/handlers/UserLogin.js +3 -3
- package/dist/src/handlers/UserPasswordPut.d.ts +1 -1
- package/dist/src/handlers/UserPasswordPut.js +2 -2
- package/dist/src/handlers/UserPasswordResetComplete.d.ts +2 -3
- package/dist/src/handlers/UserPasswordResetComplete.js +7 -12
- package/dist/src/handlers/UserPasswordResetForm.d.ts +6 -0
- package/dist/src/handlers/UserPasswordResetForm.js +96 -0
- package/dist/src/handlers/UserPasswordResetStart.d.ts +1 -1
- package/dist/src/handlers/UserPasswordResetStart.js +3 -2
- package/dist/src/handlers/UserProfileGet.d.ts +1 -1
- package/dist/src/handlers/UserProfileGet.js +3 -3
- package/dist/src/handlers/UserProfilePut.d.ts +1 -1
- package/dist/src/handlers/UserProfilePut.js +4 -4
- package/dist/src/handlers/UserPushRegisterToken.d.ts +1 -1
- package/dist/src/handlers/UserPushRegisterToken.js +3 -3
- package/dist/src/handlers/UserPushRemoveToken.d.ts +1 -1
- package/dist/src/handlers/UserPushRemoveToken.js +3 -3
- package/dist/src/handlers/UserToken.d.ts +1 -1
- package/dist/src/handlers/UserToken.js +3 -3
- package/dist/src/init.js +11 -0
- package/dist/src/schemas/UserPasswordResetSettings.d.ts +2 -0
- package/package.json +6 -6
- package/src/coreFunctions.ts +190 -175
- package/src/handlers/Management/GetUserByUserid.ts +21 -15
- package/src/handlers/Management/PutUserPasswordByUserid.ts +1 -1
- package/src/handlers/Management/PutUserProfileByUserid.ts +22 -16
- package/src/handlers/Management/PutUserProfileByUseridAppend.ts +26 -20
- package/src/handlers/Management/PutUserRolesByUserid.ts +22 -17
- package/src/handlers/Management/PutUserUsernameByUserid.ts +28 -19
- package/src/handlers/UserPasswordResetComplete.ts +2 -10
- package/src/handlers/UserPasswordResetForm.ts +144 -0
- package/src/handlers/UserPasswordResetStart.ts +1 -0
- package/src/handlers/UserProfileGet.ts +1 -1
- package/src/handlers/UserProfilePut.ts +2 -2
- package/src/handlers/UserPushRegisterToken.ts +1 -1
- package/src/handlers/UserPushRemoveToken.ts +1 -1
- package/src/handlers/UserToken.ts +1 -1
- package/src/init.ts +12 -0
- package/src/schemas/UserPasswordResetCompleteReq.ts +5 -5
- package/src/schemas/UserPasswordResetSettings.ts +14 -12
- package/src/schemas/UserPasswordResetStartRes.ts +5 -5
|
@@ -1,25 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FlinkContext,
|
|
3
|
+
Handler,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
notFound,
|
|
6
|
+
RouteProps,
|
|
7
|
+
} from "@flink-app/flink";
|
|
2
8
|
import { PutManagementUserProfileByUseridReq } from "../../schemas/Management/PutUserProfileByUseridReq";
|
|
3
9
|
import { PutManagementUserProfileByUseridRes } from "../../schemas/Management/PutUserProfileByUseridRes";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
const PutManagementUserProfileByUserid: Handler<
|
|
12
|
+
FlinkContext,
|
|
13
|
+
PutManagementUserProfileByUseridReq,
|
|
14
|
+
PutManagementUserProfileByUseridRes
|
|
15
|
+
> = async ({ ctx, req, origin }) => {
|
|
7
16
|
let pluginName = origin || "genericAuthPlugin";
|
|
8
|
-
let repo = ctx.repos[
|
|
17
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
9
18
|
|
|
10
|
-
const user = await repo.
|
|
11
|
-
if(user == null){
|
|
19
|
+
const user = await repo.getById(req.params.userid);
|
|
20
|
+
if (user == null) {
|
|
12
21
|
return notFound();
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
|
|
16
|
-
await repo.updateOne(user._id, { profile : req.body });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
data: {},
|
|
21
|
-
status : 200
|
|
22
|
-
};
|
|
24
|
+
await repo.updateOne(user._id, { profile: req.body });
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
return {
|
|
27
|
+
data: {},
|
|
28
|
+
status: 200,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default PutManagementUserProfileByUserid;
|
|
@@ -1,32 +1,38 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FlinkContext,
|
|
3
|
+
Handler,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
notFound,
|
|
6
|
+
RouteProps,
|
|
7
|
+
} from "@flink-app/flink";
|
|
2
8
|
import { PutManagementUserProfileByUseridReq } from "../../schemas/Management/PutUserProfileByUseridReq";
|
|
3
9
|
import { PutManagementUserProfileByUseridRes } from "../../schemas/Management/PutUserProfileByUseridRes";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
const PutManagementUserProfileByUserid: Handler<
|
|
12
|
+
FlinkContext,
|
|
13
|
+
PutManagementUserProfileByUseridReq,
|
|
14
|
+
PutManagementUserProfileByUseridRes
|
|
15
|
+
> = async ({ ctx, req, origin }) => {
|
|
7
16
|
let pluginName = origin || "genericAuthPlugin";
|
|
8
|
-
let repo = ctx.repos[
|
|
17
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
9
18
|
|
|
10
|
-
const user = await repo.
|
|
11
|
-
if(user == null){
|
|
19
|
+
const user = await repo.getById(req.params.userid);
|
|
20
|
+
if (user == null) {
|
|
12
21
|
return notFound();
|
|
13
22
|
}
|
|
14
23
|
|
|
15
|
-
if(user.profile == null) user.profile = {};
|
|
16
|
-
|
|
24
|
+
if (user.profile == null) user.profile = {};
|
|
25
|
+
|
|
17
26
|
const profile = {
|
|
18
27
|
...user.profile,
|
|
19
|
-
...req.body
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
await repo.updateOne(user._id, { profile : profile });
|
|
24
|
-
|
|
28
|
+
...req.body,
|
|
29
|
+
};
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
data: {},
|
|
28
|
-
status : 200
|
|
29
|
-
};
|
|
31
|
+
await repo.updateOne(user._id, { profile: profile });
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
return {
|
|
34
|
+
data: {},
|
|
35
|
+
status: 200,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export default PutManagementUserProfileByUserid;
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
FlinkContext,
|
|
3
|
+
Handler,
|
|
4
|
+
HttpMethod,
|
|
5
|
+
notFound,
|
|
6
|
+
RouteProps,
|
|
7
|
+
} from "@flink-app/flink";
|
|
2
8
|
import { PutManagementUserRolesByUseridReq } from "../../schemas/Management/PutUserRolesByUseridReq";
|
|
3
9
|
import { PutManagementUserRolesByUseridRes } from "../../schemas/Management/PutUserRolesByUseridRes";
|
|
4
10
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
const PutManagementUserRolesByUserid: Handler<
|
|
12
|
+
FlinkContext,
|
|
13
|
+
PutManagementUserRolesByUseridReq,
|
|
14
|
+
PutManagementUserRolesByUseridRes
|
|
15
|
+
> = async ({ ctx, req, origin }) => {
|
|
9
16
|
let pluginName = origin || "genericAuthPlugin";
|
|
10
|
-
let repo = ctx.repos[
|
|
17
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
11
18
|
|
|
12
|
-
const user = await repo.
|
|
13
|
-
if(user == null){
|
|
19
|
+
const user = await repo.getById(req.params.userid);
|
|
20
|
+
if (user == null) {
|
|
14
21
|
return notFound();
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
await repo.updateOne(user._id, { roles : req.body.roles });
|
|
19
|
-
|
|
24
|
+
await repo.updateOne(user._id, { roles: req.body.roles });
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
export default PutManagementUserRolesByUserid;
|
|
26
|
+
return {
|
|
27
|
+
data: {},
|
|
28
|
+
status: 200,
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export default PutManagementUserRolesByUserid;
|
|
@@ -1,32 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
conflict,
|
|
3
|
+
FlinkContext,
|
|
4
|
+
Handler,
|
|
5
|
+
HttpMethod,
|
|
6
|
+
notFound,
|
|
7
|
+
RouteProps,
|
|
8
|
+
} from "@flink-app/flink";
|
|
2
9
|
import { PutManagementUserUsernameByUseridReq } from "../../schemas/Management/PutUserUsernameByUseridReq";
|
|
3
10
|
import { PutManagementUserUsernameByUseridRes } from "../../schemas/Management/PutUserUsernameByUseridRes";
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
const PutManagementUserUsernameByUserid: Handler<
|
|
13
|
+
FlinkContext,
|
|
14
|
+
PutManagementUserUsernameByUseridReq,
|
|
15
|
+
PutManagementUserUsernameByUseridRes
|
|
16
|
+
> = async ({ ctx, req, origin }) => {
|
|
8
17
|
let pluginName = origin || "genericAuthPlugin";
|
|
9
|
-
let repo = ctx.repos[
|
|
18
|
+
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
10
19
|
|
|
11
|
-
const user = await repo.
|
|
12
|
-
if(user == null){
|
|
20
|
+
const user = await repo.getById(req.params.userid);
|
|
21
|
+
if (user == null) {
|
|
13
22
|
return notFound();
|
|
14
23
|
}
|
|
15
24
|
|
|
16
|
-
const existingUser = await repo.getOne({
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
const existingUser = await repo.getOne({
|
|
26
|
+
username: req.body.username.toLowerCase(),
|
|
27
|
+
});
|
|
28
|
+
if (existingUser != null) {
|
|
29
|
+
if (existingUser._id + "" != user._id + "") {
|
|
19
30
|
return conflict("Username already taken");
|
|
20
31
|
}
|
|
21
32
|
}
|
|
22
|
-
|
|
23
|
-
await repo.updateOne(user._id, { username : req.body.username.toLowerCase() });
|
|
24
|
-
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
data: {},
|
|
28
|
-
status : 200
|
|
29
|
-
};
|
|
34
|
+
await repo.updateOne(user._id, { username: req.body.username.toLowerCase() });
|
|
30
35
|
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
return {
|
|
37
|
+
data: {},
|
|
38
|
+
status: 200,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export default PutManagementUserUsernameByUserid;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { emailPlugin, emailPluginContext } from "@flink-app/email-plugin";
|
|
2
1
|
import {
|
|
3
2
|
badRequest,
|
|
4
3
|
FlinkContext,
|
|
@@ -12,27 +11,20 @@ import { UserPasswordResetCompleteReq } from "../schemas/UserPasswordResetComple
|
|
|
12
11
|
import { UserPasswordResetCompleteRes } from "../schemas/UserPasswordResetCompleteRes";
|
|
13
12
|
|
|
14
13
|
const postPasswordResetCompleteHandler: Handler<
|
|
15
|
-
FlinkContext<genericAuthContext
|
|
14
|
+
FlinkContext<genericAuthContext>,
|
|
16
15
|
UserPasswordResetCompleteReq,
|
|
17
16
|
UserPasswordResetCompleteRes
|
|
18
17
|
> = async ({ ctx, req, origin }) => {
|
|
19
18
|
let pluginName = origin || "genericAuthPlugin";
|
|
20
19
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
21
20
|
|
|
22
|
-
const emailPlguin = ctx.plugins.emailPlugin;
|
|
23
|
-
if (emailPlugin == null) {
|
|
24
|
-
return internalServerError(
|
|
25
|
-
"Email plugin have to be initialized to use password-reset"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
21
|
if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
|
|
30
22
|
return internalServerError(
|
|
31
23
|
"Password reset settings is needed to use password-reset"
|
|
32
24
|
);
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
const { jwtSecret
|
|
27
|
+
const { jwtSecret /*, numberOfDigits, lifeTime*/ } =
|
|
36
28
|
ctx.plugins.genericAuthPlugin.passwordResetSettings.code;
|
|
37
29
|
|
|
38
30
|
const resp = await ctx.plugins.genericAuthPlugin.passwordResetComplete(
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { ExpressRequest, ExpressResponse } from "@flink-app/flink";
|
|
2
|
+
import fs from "fs/promises";
|
|
3
|
+
import { log } from "@flink-app/flink";
|
|
4
|
+
import Handlebars from "handlebars";
|
|
5
|
+
|
|
6
|
+
const defaultTemplate = `<html>
|
|
7
|
+
<head>
|
|
8
|
+
<title>Password reset</title>
|
|
9
|
+
<style>
|
|
10
|
+
* {
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
p {
|
|
16
|
+
margin: 0.5rem 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
body {
|
|
20
|
+
padding: 1rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
form {
|
|
24
|
+
display: block;
|
|
25
|
+
max-width: 320px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
input {
|
|
29
|
+
width: 100%;
|
|
30
|
+
display: block;
|
|
31
|
+
margin: 0.5rem 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#success {
|
|
35
|
+
display: none;
|
|
36
|
+
font-size: 1.2rem;
|
|
37
|
+
color: rgb(0, 177, 115);
|
|
38
|
+
max-width: 350px;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
41
|
+
<script>
|
|
42
|
+
window.onload = () => {
|
|
43
|
+
const urlSearchParams = new URLSearchParams(window.location.search);
|
|
44
|
+
const params = Object.fromEntries(urlSearchParams.entries());
|
|
45
|
+
const { token, code } = params;
|
|
46
|
+
|
|
47
|
+
if (!token) {
|
|
48
|
+
alert("Missing token");
|
|
49
|
+
} else if (!code) {
|
|
50
|
+
alert("Missing code");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const submitBtnEl = document.getElementById("submit-btn");
|
|
54
|
+
const [passwordInputEl, confirmPasswordEl] =
|
|
55
|
+
document.getElementsByTagName("input");
|
|
56
|
+
|
|
57
|
+
submitBtnEl.onclick = async (e) => {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
e.stopPropagation();
|
|
60
|
+
|
|
61
|
+
if (!passwordInputEl.value) {
|
|
62
|
+
return alert("Enter a new password");
|
|
63
|
+
} else if (passwordInputEl.value !== confirmPasswordEl.value) {
|
|
64
|
+
return alert(
|
|
65
|
+
"Passwords does not match, make sure that new and confirmed passwords are the same"
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const res = await window.fetch("{{completeUrl}}", {
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: {
|
|
72
|
+
Accept: "application/json",
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
passwordResetToken: token,
|
|
77
|
+
code: code,
|
|
78
|
+
password: passwordInputEl.value,
|
|
79
|
+
}),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (res.status > 399) {
|
|
83
|
+
alert("Failed to set new password");
|
|
84
|
+
} else {
|
|
85
|
+
document.getElementById("form").style.display = "none";
|
|
86
|
+
document.getElementById("success").style.display = "block";
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
</script>
|
|
91
|
+
</head>
|
|
92
|
+
<body>
|
|
93
|
+
<form id="form">
|
|
94
|
+
<p>Please enter new password</p>
|
|
95
|
+
<input type="password" name="password" placeholder="Enter new password" />
|
|
96
|
+
<input
|
|
97
|
+
type="password"
|
|
98
|
+
name="confirmPassword"
|
|
99
|
+
placeholder="Confirm new password"
|
|
100
|
+
/>
|
|
101
|
+
<button id="submit-btn">Submit</button>
|
|
102
|
+
</form>
|
|
103
|
+
<div id="success">Password has been updated, please proceed to login.</div>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
|
106
|
+
`;
|
|
107
|
+
|
|
108
|
+
export async function handleUserPasswordResetForm(
|
|
109
|
+
_req: ExpressRequest,
|
|
110
|
+
res: ExpressResponse,
|
|
111
|
+
{ templateFile, completeUrl }: { templateFile?: string; completeUrl: string }
|
|
112
|
+
) {
|
|
113
|
+
const tpl = await readTemplate(templateFile);
|
|
114
|
+
|
|
115
|
+
const html = Handlebars.compile(tpl)({
|
|
116
|
+
completeUrl,
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
res.send(html);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let cachedTemplate = "";
|
|
123
|
+
|
|
124
|
+
async function readTemplate(templateFilename?: string) {
|
|
125
|
+
if (!cachedTemplate) {
|
|
126
|
+
if (templateFilename) {
|
|
127
|
+
try {
|
|
128
|
+
const buff = await fs.readFile(templateFilename);
|
|
129
|
+
cachedTemplate = buff.toString();
|
|
130
|
+
} catch (err) {
|
|
131
|
+
log.error(
|
|
132
|
+
"Failed reading template file for password reset",
|
|
133
|
+
templateFilename,
|
|
134
|
+
err
|
|
135
|
+
);
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
} else {
|
|
139
|
+
cachedTemplate = defaultTemplate;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return cachedTemplate;
|
|
144
|
+
}
|
|
@@ -10,7 +10,7 @@ const getProfileHandler: Handler<
|
|
|
10
10
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
11
11
|
|
|
12
12
|
let userId = req.user._id;
|
|
13
|
-
let user = await repo.
|
|
13
|
+
let user = await repo.getById(userId);
|
|
14
14
|
if (user == null) {
|
|
15
15
|
return notFound();
|
|
16
16
|
}
|
|
@@ -11,7 +11,7 @@ const putUserProfileHandler: Handler<
|
|
|
11
11
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
12
12
|
|
|
13
13
|
let userId = req.user._id;
|
|
14
|
-
let user = await repo.
|
|
14
|
+
let user = await repo.getById(userId);
|
|
15
15
|
if (user == null) {
|
|
16
16
|
return notFound();
|
|
17
17
|
}
|
|
@@ -19,7 +19,7 @@ const putUserProfileHandler: Handler<
|
|
|
19
19
|
user.profile = req.body;
|
|
20
20
|
await repo.updateOne(userId, { profile: req.body });
|
|
21
21
|
|
|
22
|
-
user = await repo.
|
|
22
|
+
user = await repo.getById(userId);
|
|
23
23
|
|
|
24
24
|
return {
|
|
25
25
|
data: user.profile,
|
|
@@ -12,7 +12,7 @@ const postUserPushRegisterTokenHandler: Handler<
|
|
|
12
12
|
let pluginName = origin || "genericAuthPlugin";
|
|
13
13
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
14
14
|
|
|
15
|
-
const user = <User>await repo.
|
|
15
|
+
const user = <User>await repo.getById(req.user._id);
|
|
16
16
|
|
|
17
17
|
if (user == null) {
|
|
18
18
|
return notFound("User not found");
|
|
@@ -12,7 +12,7 @@ const postUserRemoveTokenHandler: Handler<
|
|
|
12
12
|
let pluginName = origin || "genericAuthPlugin";
|
|
13
13
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
14
14
|
|
|
15
|
-
const user = <User>await repo.
|
|
15
|
+
const user = <User>await repo.getById(req.user._id);
|
|
16
16
|
|
|
17
17
|
if (user == null) {
|
|
18
18
|
return notFound("User not found");
|
|
@@ -14,7 +14,7 @@ const getUserTokenHandler: Handler<
|
|
|
14
14
|
let pluginName = origin || "genericAuthPlugin";
|
|
15
15
|
let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
|
|
16
16
|
|
|
17
|
-
const user = await repo.
|
|
17
|
+
const user = await repo.getById(req.user._id);
|
|
18
18
|
if (user == null) {
|
|
19
19
|
return notFound("User not found");
|
|
20
20
|
}
|
package/src/init.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { GenericAuthPluginOptions } from "./genericAuthPluginOptions";
|
|
|
10
10
|
import * as postUserPushRegisterTokenHandler from "./handlers/UserPushRegisterToken";
|
|
11
11
|
import * as postUserRemoveTokenHandler from "./handlers/UserPushRemoveToken";
|
|
12
12
|
import * as getUserTokenHandler from "./handlers/UserToken";
|
|
13
|
+
import { handleUserPasswordResetForm } from "./handlers/UserPasswordResetForm";
|
|
13
14
|
|
|
14
15
|
export function init(app: FlinkApp<any>, options: GenericAuthPluginOptions) {
|
|
15
16
|
if (options.enableUserCreation == null) options.enableUserCreation = true;
|
|
@@ -83,6 +84,17 @@ export function init(app: FlinkApp<any>, options: GenericAuthPluginOptions) {
|
|
|
83
84
|
docs: "Completes a password reset for a user",
|
|
84
85
|
origin: options.pluginId,
|
|
85
86
|
});
|
|
87
|
+
|
|
88
|
+
if (options.passwordResetSettings?.enablePasswordResetForm) {
|
|
89
|
+
app.expressApp?.get(
|
|
90
|
+
options.baseUrl + "/password/reset/form",
|
|
91
|
+
(req, res) =>
|
|
92
|
+
handleUserPasswordResetForm(req, res, {
|
|
93
|
+
templateFile: options.passwordResetSettings?.passwordResetForm,
|
|
94
|
+
completeUrl: options.baseUrl + "/password/reset/complete",
|
|
95
|
+
})
|
|
96
|
+
);
|
|
97
|
+
}
|
|
86
98
|
}
|
|
87
99
|
|
|
88
100
|
if (options.enablePushNotificationTokens) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export interface UserPasswordResetCompleteReq{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
export interface UserPasswordResetCompleteReq {
|
|
2
|
+
passwordResetToken: string;
|
|
3
|
+
code: string;
|
|
4
|
+
password: string;
|
|
5
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
export interface UserPasswordResetSettings{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
export interface UserPasswordResetSettings {
|
|
2
|
+
email: {
|
|
3
|
+
from_address: string;
|
|
4
|
+
subject: string;
|
|
5
|
+
html: string;
|
|
6
|
+
};
|
|
7
|
+
code: {
|
|
8
|
+
numberOfDigits: number;
|
|
9
|
+
lifeTime: string;
|
|
10
|
+
jwtSecret: string;
|
|
11
|
+
};
|
|
12
|
+
enablePasswordResetForm?: boolean;
|
|
13
|
+
passwordResetForm?: string;
|
|
14
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { UserProfile } from "./UserProfile";
|
|
2
2
|
|
|
3
3
|
export interface UserPasswordResetStartRes {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
4
|
+
status: "success" | "userNotFound";
|
|
5
|
+
passwordResetToken?: string;
|
|
6
|
+
code?: string;
|
|
7
|
+
profile?: UserProfile;
|
|
8
|
+
}
|