@flink-app/generic-auth-plugin 0.6.1 → 0.6.3

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.
@@ -1,4 +1,4 @@
1
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredHandlers, HttpMethod } from "@flink-app/flink";
3
3
  import * as UserCreate_0 from "../src/handlers/UserCreate";
4
4
  import * as UserLogin_0 from "../src/handlers/UserLogin";
@@ -1,4 +1,4 @@
1
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredJobs } from "@flink-app/flink";
3
3
  export const jobs = [];
4
4
  autoRegisteredJobs.push(...jobs);
@@ -1,4 +1,4 @@
1
- // Generated Mon May 22 2023 15:57:14 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import { autoRegisteredRepos } from "@flink-app/flink";
3
3
  export const repos = [];
4
4
  autoRegisteredRepos.push(...repos);
@@ -471,63 +471,6 @@
471
471
  "properties": {},
472
472
  "definitions": {}
473
473
  },
474
- "GetUserByUserid_11_ResSchema": {
475
- "$schema": "http://json-schema.org/draft-07/schema#",
476
- "type": "object",
477
- "additionalProperties": false,
478
- "properties": {
479
- "_id": {
480
- "type": "string"
481
- },
482
- "username": {
483
- "type": "string"
484
- },
485
- "roles": {
486
- "type": "array",
487
- "items": {
488
- "type": "string"
489
- }
490
- },
491
- "authentificationMethod": {
492
- "type": "string",
493
- "enum": [
494
- "password",
495
- "sms"
496
- ]
497
- },
498
- "profile": {
499
- "type": "object"
500
- },
501
- "pushNotificationTokens": {
502
- "type": "array",
503
- "items": {
504
- "type": "object",
505
- "properties": {
506
- "deviceId": {
507
- "type": "string"
508
- },
509
- "token": {
510
- "type": "string"
511
- }
512
- },
513
- "required": [
514
- "deviceId",
515
- "token"
516
- ],
517
- "additionalProperties": false
518
- }
519
- }
520
- },
521
- "required": [
522
- "_id",
523
- "authentificationMethod",
524
- "profile",
525
- "pushNotificationTokens",
526
- "roles",
527
- "username"
528
- ],
529
- "definitions": {}
530
- },
531
474
  "GetUserViewByUserid_6_ReqSchema": {
532
475
  "$schema": "http://json-schema.org/draft-07/schema#",
533
476
  "type": "object",
@@ -18,7 +18,6 @@ import { DeleteManagementUserByUseridRes } from "../../src/schemas/Management/De
18
18
  import { GetManagementUserReq } from "../../src/schemas/Management/GetUserReq";
19
19
  import { GetManagementUserRes } from "../../src/schemas/Management/GetUserRes";
20
20
  import { GetManagementUserByUseridReq } from "../../src/schemas/Management/GetUserByUseridReq";
21
- import { GetManagementUserByUseridRes } from "../../src/schemas/Management/GetUserByUseridRes";
22
21
  import { GetManagementUserViewByUseridReq } from "../../src/schemas/Management/GetUserViewByUseridReq";
23
22
  import { GetManagementUserViewByUseridRes } from "../../src/schemas/Management/GetUserViewByUseridRes";
24
23
  import { PutManagementUserPasswordByUseridReq } from "../../src/schemas/Management/PutUserPasswordByUseridReq";
@@ -30,7 +29,7 @@ import { PutManagementUserRolesByUseridRes } from "../../src/schemas/Management/
30
29
  import { PutManagementUserUsernameByUseridReq } from "../../src/schemas/Management/PutUserUsernameByUseridReq";
31
30
  import { PutManagementUserUsernameByUseridRes } from "../../src/schemas/Management/PutUserUsernameByUseridRes";
32
31
 
33
- // Generated Mon May 22 2023 15:57:18 GMT+0200 (Central European Summer Time)
32
+ // Generated Wed Aug 16 2023 08:50:01 GMT+0200 (Central European Summer Time)
34
33
  export interface UserCreate_7_ReqSchema extends UserCreateReq {}
35
34
 
36
35
  export interface UserCreate_7_ResSchema extends UserCreateRes {}
@@ -81,8 +80,6 @@ export interface GetUser_5_ResSchema extends GetManagementUserRes {}
81
80
 
82
81
  export interface GetUserByUserid_11_ReqSchema extends GetManagementUserByUseridReq {}
83
82
 
84
- export interface GetUserByUserid_11_ResSchema extends GetManagementUserByUseridRes {}
85
-
86
83
  export interface GetUserViewByUserid_6_ReqSchema extends GetManagementUserViewByUseridReq {}
87
84
 
88
85
  export interface GetUserViewByUserid_6_ResSchema extends GetManagementUserViewByUseridRes {}
package/.flink/start.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
1
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
2
2
  import "./generatedHandlers";
3
3
  import "./generatedRepos";
4
4
  import "./generatedJobs";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlers = void 0;
4
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.handlers = [];
7
7
  flink_1.autoRegisteredHandlers.push.apply(flink_1.autoRegisteredHandlers, exports.handlers);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jobs = void 0;
4
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.jobs = [];
7
7
  flink_1.autoRegisteredJobs.push.apply(flink_1.autoRegisteredJobs, exports.jobs);
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.repos = void 0;
4
- // Generated Mon May 22 2023 15:57:14 GMT+0200 (Central European Summer Time)
4
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
5
5
  var flink_1 = require("@flink-app/flink");
6
6
  exports.repos = [];
7
7
  flink_1.autoRegisteredRepos.push.apply(flink_1.autoRegisteredRepos, exports.repos);
@@ -18,7 +18,6 @@ import { DeleteManagementUserByUseridRes } from "../../src/schemas/Management/De
18
18
  import { GetManagementUserReq } from "../../src/schemas/Management/GetUserReq";
19
19
  import { GetManagementUserRes } from "../../src/schemas/Management/GetUserRes";
20
20
  import { GetManagementUserByUseridReq } from "../../src/schemas/Management/GetUserByUseridReq";
21
- import { GetManagementUserByUseridRes } from "../../src/schemas/Management/GetUserByUseridRes";
22
21
  import { GetManagementUserViewByUseridReq } from "../../src/schemas/Management/GetUserViewByUseridReq";
23
22
  import { GetManagementUserViewByUseridRes } from "../../src/schemas/Management/GetUserViewByUseridRes";
24
23
  import { PutManagementUserPasswordByUseridReq } from "../../src/schemas/Management/PutUserPasswordByUseridReq";
@@ -79,8 +78,6 @@ export interface GetUser_5_ResSchema extends GetManagementUserRes {
79
78
  }
80
79
  export interface GetUserByUserid_11_ReqSchema extends GetManagementUserByUseridReq {
81
80
  }
82
- export interface GetUserByUserid_11_ResSchema extends GetManagementUserByUseridRes {
83
- }
84
81
  export interface GetUserViewByUserid_6_ReqSchema extends GetManagementUserViewByUseridReq {
85
82
  }
86
83
  export interface GetUserViewByUserid_6_ResSchema extends GetManagementUserViewByUseridRes {
@@ -471,63 +471,6 @@
471
471
  "properties": {},
472
472
  "definitions": {}
473
473
  },
474
- "GetUserByUserid_11_ResSchema": {
475
- "$schema": "http://json-schema.org/draft-07/schema#",
476
- "type": "object",
477
- "additionalProperties": false,
478
- "properties": {
479
- "_id": {
480
- "type": "string"
481
- },
482
- "username": {
483
- "type": "string"
484
- },
485
- "roles": {
486
- "type": "array",
487
- "items": {
488
- "type": "string"
489
- }
490
- },
491
- "authentificationMethod": {
492
- "type": "string",
493
- "enum": [
494
- "password",
495
- "sms"
496
- ]
497
- },
498
- "profile": {
499
- "type": "object"
500
- },
501
- "pushNotificationTokens": {
502
- "type": "array",
503
- "items": {
504
- "type": "object",
505
- "properties": {
506
- "deviceId": {
507
- "type": "string"
508
- },
509
- "token": {
510
- "type": "string"
511
- }
512
- },
513
- "required": [
514
- "deviceId",
515
- "token"
516
- ],
517
- "additionalProperties": false
518
- }
519
- }
520
- },
521
- "required": [
522
- "_id",
523
- "authentificationMethod",
524
- "profile",
525
- "pushNotificationTokens",
526
- "roles",
527
- "username"
528
- ],
529
- "definitions": {}
530
- },
531
474
  "GetUserViewByUserid_6_ReqSchema": {
532
475
  "$schema": "http://json-schema.org/draft-07/schema#",
533
476
  "type": "object",
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- // Generated Mon May 22 2023 15:57:15 GMT+0200 (Central European Summer Time)
3
+ // Generated Wed Aug 16 2023 08:49:59 GMT+0200 (Central European Summer Time)
4
4
  require("./generatedHandlers");
5
5
  require("./generatedRepos");
6
6
  require("./generatedJobs");
@@ -297,17 +297,22 @@ function changePassword(repo, auth, userId, newPassword, createPasswordHashAndSa
297
297
  exports.changePassword = changePassword;
298
298
  function passwordResetStart(repo, auth, jwtSecret, username, numberOfDigits, lifeTime) {
299
299
  return __awaiter(this, void 0, void 0, function () {
300
- var user, payload, code, secret, options, token;
300
+ var user, fakepayload, fakeToken, payload, code, secret, options, token;
301
301
  return __generator(this, function (_a) {
302
302
  switch (_a.label) {
303
303
  case 0: return [4 /*yield*/, repo.getOne({ username: username.toLowerCase() })];
304
304
  case 1:
305
305
  user = _a.sent();
306
+ fakepayload = {
307
+ type: "passwordReset",
308
+ username: username.toLocaleLowerCase(),
309
+ };
310
+ fakeToken = jsonwebtoken_1.default.sign(fakepayload, "fake_payload", { expiresIn: lifeTime });
306
311
  if (user == null) {
307
- return [2 /*return*/, { status: "userNotFound" }];
312
+ return [2 /*return*/, { status: "userNotFound", passwordResetToken: fakeToken }];
308
313
  }
309
314
  if (user.authentificationMethod != "password") {
310
- return [2 /*return*/, { status: "userNotFound" }];
315
+ return [2 /*return*/, { status: "userNotFound", passwordResetToken: fakeToken }];
311
316
  }
312
317
  if (numberOfDigits == null)
313
318
  numberOfDigits = 6;
@@ -1,7 +1,6 @@
1
1
  import { FlinkContext, Handler } from "@flink-app/flink";
2
2
  import { GetManagementUserByUseridReq } from "../../schemas/Management/GetUserByUseridReq";
3
- import { GetManagementUserByUseridRes } from "../../schemas/Management/GetUserByUseridRes";
4
- declare const GetManagementUserByUserid: Handler<FlinkContext, GetManagementUserByUseridReq, GetManagementUserByUseridRes>;
3
+ declare const GetManagementUserByUserid: Handler<FlinkContext, GetManagementUserByUseridReq, any>;
5
4
  export default GetManagementUserByUserid;
6
5
  export declare const __assumedHttpMethod = "get", __file = "GetUserByUserid.ts", __query: never[], __params: never[];
7
6
  export declare const __schemas: any;
@@ -75,4 +75,4 @@ var GetManagementUserByUserid = function (_a) {
75
75
  };
76
76
  exports.default = GetManagementUserByUserid;
77
77
  exports.__assumedHttpMethod = "get", exports.__file = "GetUserByUserid.ts", exports.__query = [], exports.__params = [];
78
- exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": {}, "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "roles": { "type": "array", "items": { "type": "string" } }, "authentificationMethod": { "type": "string", "enum": ["password", "sms"] }, "profile": { "type": "object" }, "pushNotificationTokens": { "type": "array", "items": { "type": "object", "properties": { "deviceId": { "type": "string" }, "token": { "type": "string" } }, "required": ["deviceId", "token"], "additionalProperties": false } } }, "required": ["_id", "authentificationMethod", "profile", "pushNotificationTokens", "roles", "username"], "definitions": {} } };
78
+ exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": {}, "definitions": {} }, resSchema: undefined };
@@ -45,33 +45,37 @@ var handlebars_1 = __importDefault(require("handlebars"));
45
45
  var postPasswordResetStartHandler = function (_a) {
46
46
  var ctx = _a.ctx, req = _a.req, origin = _a.origin;
47
47
  return __awaiter(void 0, void 0, void 0, function () {
48
- var pluginName, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailSettings, emailCtx, subject, html, email;
48
+ var pluginName, genericAuthPlugin, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
49
49
  var _c;
50
50
  return __generator(this, function (_d) {
51
51
  switch (_d.label) {
52
52
  case 0:
53
53
  pluginName = origin || "genericAuthPlugin";
54
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
54
+ genericAuthPlugin = ctx.plugins[pluginName];
55
+ repo = ctx.repos[genericAuthPlugin.repoName];
55
56
  if (((_c = ctx.plugins.emailPlugin) === null || _c === void 0 ? void 0 : _c.client) == null) {
56
57
  return [2 /*return*/, flink_1.internalServerError("Email plugin have to be initialized to use /password/reset")];
57
58
  }
58
- if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
59
+ if (!genericAuthPlugin.passwordResetSettings) {
59
60
  return [2 /*return*/, flink_1.internalServerError("Password reset settings is needed to use /password/reset")];
60
61
  }
61
- _b = ctx.plugins[pluginName].passwordResetSettings.code, jwtSecret = _b.jwtSecret, numberOfDigits = _b.numberOfDigits, lifeTime = _b.lifeTime;
62
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime)];
62
+ _b = genericAuthPlugin.passwordResetSettings.code, jwtSecret = _b.jwtSecret, numberOfDigits = _b.numberOfDigits, lifeTime = _b.lifeTime;
63
+ return [4 /*yield*/, genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime)];
63
64
  case 1:
64
65
  resp = _d.sent();
65
66
  if (resp.status != "success") {
66
- return [2 /*return*/, { data: { status: resp.status } }];
67
+ return [2 /*return*/, { data: { status: "success", passwordResetToken: resp.passwordResetToken } }];
67
68
  }
68
- emailSettings = ctx.plugins[pluginName].passwordResetSettings.email;
69
69
  emailCtx = {
70
70
  code: resp.code,
71
71
  passwordResetToken: resp.passwordResetToken,
72
72
  username: req.body.username,
73
73
  profile: resp.profile,
74
74
  };
75
+ emailSettings = genericAuthPlugin.passwordResetSettings.email;
76
+ if (typeof emailSettings == "function") {
77
+ emailSettings = emailSettings(emailCtx);
78
+ }
75
79
  subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
76
80
  html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
77
81
  email = req.body.username;
@@ -1,3 +1,2 @@
1
- import { User } from "../User";
2
- export interface GetManagementUserByUseridRes extends Omit<User, "password" | "salt"> {
1
+ export interface GetManagementUserByUseridRes {
3
2
  }
@@ -1,9 +1,17 @@
1
+ import { UserProfile } from "./UserProfile";
2
+ interface EmailConfig {
3
+ from_address: string;
4
+ subject: string;
5
+ html: string;
6
+ }
7
+ interface EmailCtx {
8
+ code?: string;
9
+ passwordResetToken?: string;
10
+ username: string;
11
+ profile?: UserProfile;
12
+ }
1
13
  export interface UserPasswordResetSettings {
2
- email: {
3
- from_address: string;
4
- subject: string;
5
- html: string;
6
- };
14
+ email: EmailConfig | ((emailCtx: EmailCtx) => EmailConfig);
7
15
  code: {
8
16
  numberOfDigits: number;
9
17
  lifeTime: string;
@@ -12,3 +20,4 @@ export interface UserPasswordResetSettings {
12
20
  enablePasswordResetForm?: boolean;
13
21
  passwordResetForm?: string;
14
22
  }
23
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flink-app/generic-auth-plugin",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "description": "Flink plugin that provides a generic user authentification solution.",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\"",
@@ -30,5 +30,5 @@
30
30
  "ts-node": "^9.1.1",
31
31
  "typescript": "^4.2.4"
32
32
  },
33
- "gitHead": "86e5a311e8945c87f32d038a63658483076ffcff"
33
+ "gitHead": "0ed59ee7618fda029a8979cc9e4c88894d93548e"
34
34
  }
@@ -281,12 +281,21 @@ export async function passwordResetStart(
281
281
  lifeTime?: string
282
282
  ): Promise<UserPasswordResetStartRes> {
283
283
  const user = await repo.getOne({ username: username.toLowerCase() });
284
+
285
+ const fakepayload = {
286
+ type: "passwordReset",
287
+ username: username.toLocaleLowerCase(),
288
+ };
289
+ const fakeToken = jsonwebtoken.sign(fakepayload, "fake_payload", { expiresIn: lifeTime });
290
+
291
+
292
+
284
293
  if (user == null) {
285
- return { status: "userNotFound" };
294
+ return { status: "userNotFound", passwordResetToken : fakeToken };
286
295
  }
287
296
 
288
297
  if (user.authentificationMethod != "password") {
289
- return { status: "userNotFound" };
298
+ return { status: "userNotFound", passwordResetToken : fakeToken };
290
299
  }
291
300
 
292
301
  if (numberOfDigits == null) numberOfDigits = 6;
@@ -11,7 +11,7 @@ import { GetManagementUserByUseridRes } from "../../schemas/Management/GetUserBy
11
11
  const GetManagementUserByUserid: Handler<
12
12
  FlinkContext,
13
13
  GetManagementUserByUseridReq,
14
- GetManagementUserByUseridRes
14
+ any
15
15
  > = async ({ ctx, req, origin }) => {
16
16
  let pluginName = origin || "genericAuthPlugin";
17
17
  let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
@@ -7,67 +7,59 @@ import { UserPasswordResetStartReq } from "../schemas/UserPasswordResetStartReq"
7
7
  import { UserPasswordResetStartResPublic } from "../schemas/UserPasswordResetStartResPublic";
8
8
 
9
9
  const postPasswordResetStartHandler: Handler<
10
- FlinkContext<genericAuthContext & emailPluginContext>,
11
- UserPasswordResetStartReq,
12
- UserPasswordResetStartResPublic
10
+ FlinkContext<genericAuthContext & emailPluginContext>,
11
+ UserPasswordResetStartReq,
12
+ UserPasswordResetStartResPublic
13
13
  > = async ({ ctx, req, origin }) => {
14
- let pluginName = origin || "genericAuthPlugin";
15
- let repo = ctx.repos[(<any>ctx.plugins)[pluginName].repoName];
14
+ let pluginName = origin || "genericAuthPlugin";
16
15
 
17
- if (ctx.plugins.emailPlugin?.client == null) {
18
- return internalServerError(
19
- "Email plugin have to be initialized to use /password/reset"
20
- );
21
- }
16
+ const genericAuthPlugin = (<any>ctx.plugins)[pluginName] as genericAuthContext["genericAuthPlugin"];
22
17
 
23
- if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
24
- return internalServerError(
25
- "Password reset settings is needed to use /password/reset"
26
- );
27
- }
18
+ let repo = ctx.repos[genericAuthPlugin.repoName];
28
19
 
29
- const { jwtSecret, numberOfDigits, lifeTime } =
30
- (<any>ctx.plugins)[pluginName].passwordResetSettings.code;
20
+ if (ctx.plugins.emailPlugin?.client == null) {
21
+ return internalServerError("Email plugin have to be initialized to use /password/reset");
22
+ }
31
23
 
32
-
24
+ if (!genericAuthPlugin.passwordResetSettings) {
25
+ return internalServerError("Password reset settings is needed to use /password/reset");
26
+ }
33
27
 
34
- const resp = await ctx.plugins.genericAuthPlugin.passwordResetStart(
35
- repo,
36
- <JwtAuthPlugin>ctx.auth,
37
- jwtSecret,
38
- req.body.username,
39
- numberOfDigits,
40
- lifeTime
41
- );
28
+ const { jwtSecret, numberOfDigits, lifeTime } = genericAuthPlugin.passwordResetSettings.code;
42
29
 
43
- if (resp.status != "success") {
44
- return { data: { status: resp.status } };
45
- }
30
+ const resp = await genericAuthPlugin.passwordResetStart(repo, <JwtAuthPlugin>ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime);
46
31
 
47
- const emailSettings =
48
- (<any>ctx.plugins)[pluginName].passwordResetSettings.email;
32
+ if (resp.status != "success") {
33
+ return { data: { status: "success", passwordResetToken: resp.passwordResetToken } };
34
+ }
49
35
 
50
- const emailCtx = {
51
- code: resp.code,
52
- passwordResetToken: resp.passwordResetToken,
53
- username: req.body.username,
54
- profile: resp.profile,
55
- };
36
+ const emailCtx = {
37
+ code: resp.code,
38
+ passwordResetToken: resp.passwordResetToken,
39
+ username: req.body.username,
40
+ profile: resp.profile,
41
+ };
56
42
 
57
- const subject = Handlebars.compile(emailSettings.subject)(emailCtx);
58
- const html = Handlebars.compile(emailSettings.html)(emailCtx);
59
- const email = req.body.username;
43
+ let emailSettings = genericAuthPlugin.passwordResetSettings.email;
60
44
 
61
- await ctx.plugins.emailPlugin.client.send({
62
- from: emailSettings.from_address,
63
- to: [email],
64
- subject,
65
- html,
66
- });
45
+ if (typeof emailSettings == "function") {
46
+ emailSettings = emailSettings(emailCtx);
47
+ }
67
48
 
68
- return {
69
- data: { status: "success", passwordResetToken: resp.passwordResetToken },
70
- };
49
+ const subject = Handlebars.compile(emailSettings.subject)(emailCtx);
50
+ const html = Handlebars.compile(emailSettings.html)(emailCtx);
51
+ const email = req.body.username;
52
+
53
+ await ctx.plugins.emailPlugin.client.send({
54
+ from: emailSettings.from_address,
55
+ to: [email],
56
+ subject,
57
+ html,
58
+ });
59
+
60
+ return {
61
+ data: { status: "success", passwordResetToken: resp.passwordResetToken },
62
+ };
71
63
  };
72
64
 
73
65
  export default postPasswordResetStartHandler;
@@ -1,6 +1,6 @@
1
1
  import { User} from "../User";
2
2
 
3
- export interface GetManagementUserByUseridRes extends Omit<User, "password" | "salt">{
3
+ export interface GetManagementUserByUseridRes {
4
4
 
5
5
 
6
6
 
@@ -1,14 +1,25 @@
1
- export interface UserPasswordResetSettings {
2
- email: {
1
+ import { UserProfile } from "./UserProfile";
2
+
3
+ interface EmailConfig {
3
4
  from_address: string;
4
5
  subject: string;
5
6
  html: string;
6
- };
7
- code: {
8
- numberOfDigits: number;
9
- lifeTime: string;
10
- jwtSecret: string;
11
- };
12
- enablePasswordResetForm?: boolean;
13
- passwordResetForm?: string;
7
+ }
8
+
9
+ interface EmailCtx {
10
+ code?: string;
11
+ passwordResetToken?: string;
12
+ username: string;
13
+ profile?: UserProfile;
14
+ }
15
+
16
+ export interface UserPasswordResetSettings {
17
+ email: EmailConfig | ((emailCtx: EmailCtx) => EmailConfig);
18
+ code: {
19
+ numberOfDigits: number;
20
+ lifeTime: string;
21
+ jwtSecret: string;
22
+ };
23
+ enablePasswordResetForm?: boolean;
24
+ passwordResetForm?: string;
14
25
  }