@flink-app/generic-auth-plugin 0.11.4-next.0 → 0.11.4

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.
Files changed (37) hide show
  1. package/.flink/generatedHandlers.ts +1 -1
  2. package/.flink/generatedJobs.ts +1 -1
  3. package/.flink/generatedRepos.ts +1 -1
  4. package/.flink/schemas/schemas.ts +1 -1
  5. package/.flink/start.ts +1 -1
  6. package/dist/.flink/generatedHandlers.js +1 -1
  7. package/dist/.flink/generatedJobs.js +1 -1
  8. package/dist/.flink/generatedRepos.js +1 -1
  9. package/dist/.flink/start.js +1 -1
  10. package/dist/src/coreFunctions.js +12 -11
  11. package/dist/src/handlers/Management/DeleteUserByUserid.js +25 -23
  12. package/dist/src/handlers/Management/GetSchema.js +16 -14
  13. package/dist/src/handlers/Management/GetUser.js +25 -23
  14. package/dist/src/handlers/Management/GetUserByUserid.js +26 -24
  15. package/dist/src/handlers/Management/GetUserViewByUserid.js +38 -36
  16. package/dist/src/handlers/Management/PutUserPasswordByUserid.js +50 -48
  17. package/dist/src/handlers/Management/PutUserProfileByUserid.js +28 -26
  18. package/dist/src/handlers/Management/PutUserProfileByUseridAppend.js +31 -29
  19. package/dist/src/handlers/Management/PutUserRolesByUserid.js +28 -26
  20. package/dist/src/handlers/Management/PutUserUsernameByUserid.js +37 -35
  21. package/dist/src/handlers/UserCreate.js +48 -46
  22. package/dist/src/handlers/UserLogin.js +27 -25
  23. package/dist/src/handlers/UserLoginByToken.js +27 -25
  24. package/dist/src/handlers/UserPasswordPut.js +25 -23
  25. package/dist/src/handlers/UserPasswordResetComplete.js +31 -29
  26. package/dist/src/handlers/UserPasswordResetForm.js +11 -11
  27. package/dist/src/handlers/UserPasswordResetStart.js +54 -52
  28. package/dist/src/handlers/UserProfileGet.js +25 -23
  29. package/dist/src/handlers/UserProfilePut.js +32 -30
  30. package/dist/src/handlers/UserPushRegisterToken.js +34 -32
  31. package/dist/src/handlers/UserPushRemoveToken.js +28 -26
  32. package/dist/src/handlers/UserToken.js +28 -26
  33. package/dist/src/index.js +2 -6
  34. package/dist/src/init.js +4 -7
  35. package/dist/src/management.js +1 -5
  36. package/package.json +32 -32
  37. package/src/handlers/UserLogin.ts +1 -1
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -38,30 +38,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
40
40
  var flink_1 = require("@flink-app/flink");
41
- var userLoginHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var pluginName, repo, loginRespons;
43
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0:
47
- pluginName = origin || "genericAuthPlugin";
48
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
49
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginUser(repo, ctx.auth, req.body.username, req.body.password, ctx.plugins.genericAuthPlugin.validatePasswordMethod, ctx.plugins[pluginName].smsOptions, ctx.plugins.genericAuthPlugin.onSuccessfulLogin)];
50
- case 1:
51
- loginRespons = _c.sent();
52
- if (loginRespons.status != "success") {
53
- switch (loginRespons.status) {
54
- case "failed":
55
- return [2 /*return*/, (0, flink_1.unauthorized)("Invalid username or password", loginRespons.status)];
41
+ var userLoginHandler = function (_a) {
42
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var pluginName, repo, loginRespons;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0:
48
+ pluginName = origin || "genericAuthPlugin";
49
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
50
+ return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginUser(repo, ctx.auth, req.body.username, req.body.password, ctx.plugins.genericAuthPlugin.validatePasswordMethod, ctx.plugins[pluginName].smsOptions, ctx.plugins[pluginName].onSuccessfulLogin)];
51
+ case 1:
52
+ loginRespons = _b.sent();
53
+ if (loginRespons.status != "success") {
54
+ switch (loginRespons.status) {
55
+ case "failed":
56
+ return [2 /*return*/, flink_1.unauthorized("Invalid username or password", loginRespons.status)];
57
+ }
56
58
  }
57
- }
58
- return [2 /*return*/, {
59
- data: loginRespons,
60
- status: 200,
61
- }];
62
- }
59
+ return [2 /*return*/, {
60
+ data: loginRespons,
61
+ status: 200,
62
+ }];
63
+ }
64
+ });
63
65
  });
64
- }); };
66
+ };
65
67
  exports.default = userLoginHandler;
66
68
  exports.__assumedHttpMethod = "", exports.__file = "UserLogin.ts", exports.__query = [], exports.__params = [];
67
69
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" }, "password": { "type": "string" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed", "requiresValidation"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" }, "profile": { "type": "object" } }, "required": ["_id", "username", "token", "profile"], "additionalProperties": false }, "validationToken": { "type": "string" } }, "required": ["status"], "definitions": {} } };
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -38,30 +38,32 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
40
40
  var flink_1 = require("@flink-app/flink");
41
- var userLoginHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var pluginName, repo, loginRespons;
43
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0:
47
- pluginName = origin || "genericAuthPlugin";
48
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
49
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginByToken(repo, ctx.auth, req.body.token, req.body.code, ctx.plugins[pluginName].smsOptions.jwtToken)];
50
- case 1:
51
- loginRespons = _c.sent();
52
- if (loginRespons.status != "success") {
53
- switch (loginRespons.status) {
54
- case "failed":
55
- return [2 /*return*/, (0, flink_1.unauthorized)("Invalid token or code", loginRespons.status)];
41
+ var userLoginHandler = function (_a) {
42
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var pluginName, repo, loginRespons;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0:
48
+ pluginName = origin || "genericAuthPlugin";
49
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
50
+ return [4 /*yield*/, ctx.plugins.genericAuthPlugin.loginByToken(repo, ctx.auth, req.body.token, req.body.code, ctx.plugins[pluginName].smsOptions.jwtToken)];
51
+ case 1:
52
+ loginRespons = _b.sent();
53
+ if (loginRespons.status != "success") {
54
+ switch (loginRespons.status) {
55
+ case "failed":
56
+ return [2 /*return*/, flink_1.unauthorized("Invalid token or code", loginRespons.status)];
57
+ }
56
58
  }
57
- }
58
- return [2 /*return*/, {
59
- data: loginRespons,
60
- status: 200,
61
- }];
62
- }
59
+ return [2 /*return*/, {
60
+ data: loginRespons,
61
+ status: 200,
62
+ }];
63
+ }
64
+ });
63
65
  });
64
- }); };
66
+ };
65
67
  exports.default = userLoginHandler;
66
68
  exports.__assumedHttpMethod = "", exports.__file = "UserLoginByToken.ts", exports.__query = [], exports.__params = [];
67
69
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "token": { "type": "string" }, "code": { "type": "string" } }, "required": ["code", "token"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed", "requiresValidation"] }, "user": { "type": "object", "properties": { "_id": { "type": "string" }, "username": { "type": "string" }, "token": { "type": "string" }, "profile": { "type": "object" } }, "required": ["_id", "username", "token", "profile"], "additionalProperties": false }, "validationToken": { "type": "string" } }, "required": ["status"], "definitions": {} } };
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -38,27 +38,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
40
40
  var flink_1 = require("@flink-app/flink");
41
- var putUserPasswordHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var pluginName, repo, resp;
43
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0:
47
- pluginName = origin || "genericAuthPlugin";
48
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
49
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.changePassword(repo, ctx.auth, req.user._id, req.body.password, ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod)];
50
- case 1:
51
- resp = _c.sent();
52
- switch (resp.status) {
53
- case "failed":
54
- return [2 /*return*/, (0, flink_1.badRequest)("Password could not be changed on this user", resp.status)];
55
- case "passwordError":
56
- return [2 /*return*/, (0, flink_1.badRequest)("Invalid password", resp.status)];
57
- }
58
- return [2 /*return*/, { data: resp, status: 200 }];
59
- }
41
+ var putUserPasswordHandler = function (_a) {
42
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var pluginName, repo, resp;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0:
48
+ pluginName = origin || "genericAuthPlugin";
49
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
50
+ return [4 /*yield*/, ctx.plugins.genericAuthPlugin.changePassword(repo, ctx.auth, req.user._id, req.body.password, ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod)];
51
+ case 1:
52
+ resp = _b.sent();
53
+ switch (resp.status) {
54
+ case "failed":
55
+ return [2 /*return*/, flink_1.badRequest("Password could not be changed on this user", resp.status)];
56
+ case "passwordError":
57
+ return [2 /*return*/, flink_1.badRequest("Invalid password", resp.status)];
58
+ }
59
+ return [2 /*return*/, { data: resp, status: 200 }];
60
+ }
61
+ });
60
62
  });
61
- }); };
63
+ };
62
64
  exports.default = putUserPasswordHandler;
63
65
  exports.__assumedHttpMethod = "", exports.__file = "UserPasswordPut.ts", exports.__query = [], exports.__params = [];
64
66
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "password": { "type": "string" } }, "required": ["password"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "failed", "passwordError"] } }, "required": ["status"], "definitions": {} } };
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -38,33 +38,35 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
40
40
  var flink_1 = require("@flink-app/flink");
41
- var postPasswordResetCompleteHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var pluginName, repo, jwtSecret /*, numberOfDigits, lifeTime*/, resp;
43
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0:
47
- pluginName = origin || "genericAuthPlugin";
48
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
49
- if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
50
- return [2 /*return*/, (0, flink_1.internalServerError)("Password reset settings is needed to use password-reset")];
51
- }
52
- jwtSecret = ctx.plugins[pluginName].passwordResetSettings.code.jwtSecret;
53
- return [4 /*yield*/, ctx.plugins.genericAuthPlugin.passwordResetComplete(repo, ctx.auth, jwtSecret, req.body.passwordResetToken, req.body.code, req.body.password, ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod)];
54
- case 1:
55
- resp = _c.sent();
56
- switch (resp.status) {
57
- case "invalidCode":
58
- return [2 /*return*/, (0, flink_1.badRequest)("Invalid validation code", resp.status)];
59
- case "passwordError":
60
- return [2 /*return*/, (0, flink_1.badRequest)("Invalid password", resp.status)];
61
- case "userNotFound":
62
- return [2 /*return*/, (0, flink_1.notFound)("User not found", resp.status)];
63
- }
64
- return [2 /*return*/, { data: resp, status: 200 }];
65
- }
41
+ var postPasswordResetCompleteHandler = function (_a) {
42
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var pluginName, repo, jwtSecret /*, numberOfDigits, lifeTime*/, resp;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0:
48
+ pluginName = origin || "genericAuthPlugin";
49
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
50
+ if (ctx.plugins.genericAuthPlugin.passwordResetSettings == null) {
51
+ return [2 /*return*/, flink_1.internalServerError("Password reset settings is needed to use password-reset")];
52
+ }
53
+ jwtSecret = ctx.plugins[pluginName].passwordResetSettings.code.jwtSecret;
54
+ return [4 /*yield*/, ctx.plugins.genericAuthPlugin.passwordResetComplete(repo, ctx.auth, jwtSecret, req.body.passwordResetToken, req.body.code, req.body.password, ctx.plugins.genericAuthPlugin.createPasswordHashAndSaltMethod)];
55
+ case 1:
56
+ resp = _b.sent();
57
+ switch (resp.status) {
58
+ case "invalidCode":
59
+ return [2 /*return*/, flink_1.badRequest("Invalid validation code", resp.status)];
60
+ case "passwordError":
61
+ return [2 /*return*/, flink_1.badRequest("Invalid password", resp.status)];
62
+ case "userNotFound":
63
+ return [2 /*return*/, flink_1.notFound("User not found", resp.status)];
64
+ }
65
+ return [2 /*return*/, { data: resp, status: 200 }];
66
+ }
67
+ });
66
68
  });
67
- }); };
69
+ };
68
70
  exports.default = postPasswordResetCompleteHandler;
69
71
  exports.__assumedHttpMethod = "", exports.__file = "UserPasswordResetComplete.ts", exports.__query = [], exports.__params = [];
70
72
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "passwordResetToken": { "type": "string" }, "code": { "type": "string" }, "password": { "type": "string" } }, "required": ["code", "password", "passwordResetToken"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound", "invalidCode", "passwordError"] } }, "required": ["status"], "definitions": {} } };
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -39,21 +39,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
40
  };
41
41
  Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
43
- exports.handleUserPasswordResetForm = handleUserPasswordResetForm;
42
+ exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = exports.handleUserPasswordResetForm = void 0;
44
43
  var promises_1 = __importDefault(require("fs/promises"));
45
44
  var flink_1 = require("@flink-app/flink");
46
45
  var handlebars_1 = __importDefault(require("handlebars"));
47
46
  var defaultTemplate = "<html>\n<head>\n <title>Password reset</title>\n <style>\n * {\n box-sizing: border-box;\n font-family: Arial, Helvetica, sans-serif;\n }\n\n p {\n margin: 0.5rem 0;\n }\n\n body {\n padding: 1rem;\n }\n\n form {\n display: block;\n max-width: 320px;\n }\n\n input {\n width: 100%;\n display: block;\n margin: 0.5rem 0;\n }\n\n #success {\n display: none;\n font-size: 1.2rem;\n color: rgb(0, 177, 115);\n max-width: 350px;\n }\n </style>\n <script>\n window.onload = () => {\n const urlSearchParams = new URLSearchParams(window.location.search);\n const params = Object.fromEntries(urlSearchParams.entries());\n const { token, code } = params;\n\n if (!token) {\n alert(\"Missing token\");\n } else if (!code) {\n alert(\"Missing code\");\n }\n\n const submitBtnEl = document.getElementById(\"submit-btn\");\n const [passwordInputEl, confirmPasswordEl] =\n document.getElementsByTagName(\"input\");\n\n submitBtnEl.onclick = async (e) => {\n e.preventDefault();\n e.stopPropagation();\n\n if (!passwordInputEl.value) {\n return alert(\"Enter a new password\");\n } else if (passwordInputEl.value !== confirmPasswordEl.value) {\n return alert(\n \"Passwords does not match, make sure that new and confirmed passwords are the same\"\n );\n }\n\n const res = await window.fetch(\"{{completeUrl}}\", {\n method: \"POST\",\n headers: {\n Accept: \"application/json\",\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify({\n passwordResetToken: token,\n code: code,\n password: passwordInputEl.value,\n }),\n });\n\n if (res.status > 399) {\n alert(\"Failed to set new password\");\n } else {\n document.getElementById(\"form\").style.display = \"none\";\n document.getElementById(\"success\").style.display = \"block\";\n }\n };\n };\n </script>\n</head>\n<body>\n <form id=\"form\">\n <p>Please enter new password</p>\n <input type=\"password\" name=\"password\" placeholder=\"Enter new password\" />\n <input\n type=\"password\"\n name=\"confirmPassword\"\n placeholder=\"Confirm new password\"\n />\n <button id=\"submit-btn\">Submit</button>\n </form>\n <div id=\"success\">Password has been updated, please proceed to login.</div>\n</body>\n</html>\n";
48
- function handleUserPasswordResetForm(_req_1, res_1, _a) {
49
- return __awaiter(this, arguments, void 0, function (_req, res, _b) {
47
+ function handleUserPasswordResetForm(_req, res, _a) {
48
+ var templateFile = _a.templateFile, completeUrl = _a.completeUrl;
49
+ return __awaiter(this, void 0, void 0, function () {
50
50
  var tpl, html;
51
- var templateFile = _b.templateFile, completeUrl = _b.completeUrl;
52
- return __generator(this, function (_c) {
53
- switch (_c.label) {
51
+ return __generator(this, function (_b) {
52
+ switch (_b.label) {
54
53
  case 0: return [4 /*yield*/, readTemplate(templateFile)];
55
54
  case 1:
56
- tpl = _c.sent();
55
+ tpl = _b.sent();
57
56
  html = handlebars_1.default.compile(tpl)({
58
57
  completeUrl: completeUrl,
59
58
  });
@@ -63,6 +62,7 @@ function handleUserPasswordResetForm(_req_1, res_1, _a) {
63
62
  });
64
63
  });
65
64
  }
65
+ exports.handleUserPasswordResetForm = handleUserPasswordResetForm;
66
66
  var cachedTemplate = "";
67
67
  function readTemplate(templateFilename) {
68
68
  return __awaiter(this, void 0, void 0, function () {
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -42,56 +42,58 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
42
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
43
43
  var flink_1 = require("@flink-app/flink");
44
44
  var handlebars_1 = __importDefault(require("handlebars"));
45
- var postPasswordResetStartHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
46
- var pluginName, genericAuthPlugin, repo, _c, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
47
- var _d;
48
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
49
- return __generator(this, function (_e) {
50
- switch (_e.label) {
51
- case 0:
52
- pluginName = origin || "genericAuthPlugin";
53
- genericAuthPlugin = ctx.plugins[pluginName];
54
- repo = ctx.repos[genericAuthPlugin.repoName];
55
- if (((_d = ctx.plugins.emailPlugin) === null || _d === void 0 ? void 0 : _d.client) == null) {
56
- return [2 /*return*/, (0, flink_1.internalServerError)("Email plugin have to be initialized to use /password/reset")];
57
- }
58
- if (!genericAuthPlugin.passwordResetSettings) {
59
- return [2 /*return*/, (0, flink_1.internalServerError)("Password reset settings is needed to use /password/reset")];
60
- }
61
- _c = genericAuthPlugin.passwordResetSettings.code, jwtSecret = _c.jwtSecret, numberOfDigits = _c.numberOfDigits, lifeTime = _c.lifeTime;
62
- return [4 /*yield*/, genericAuthPlugin.passwordResetStart(repo, ctx.auth, jwtSecret, req.body.username, numberOfDigits, lifeTime)];
63
- case 1:
64
- resp = _e.sent();
65
- if (resp.status != "success") {
66
- return [2 /*return*/, { data: { status: "success", passwordResetToken: resp.passwordResetToken } }];
67
- }
68
- emailCtx = {
69
- code: resp.code,
70
- passwordResetToken: resp.passwordResetToken,
71
- username: req.body.username,
72
- profile: resp.profile,
73
- };
74
- emailSettings = genericAuthPlugin.passwordResetSettings.email;
75
- if (typeof emailSettings == "function") {
76
- emailSettings = emailSettings(emailCtx);
77
- }
78
- subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
79
- html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
80
- email = req.body.username;
81
- return [4 /*yield*/, ctx.plugins.emailPlugin.client.send({
82
- from: emailSettings.from_address,
83
- to: [email],
84
- subject: subject,
85
- html: html,
86
- })];
87
- case 2:
88
- _e.sent();
89
- return [2 /*return*/, {
90
- data: { status: "success", passwordResetToken: resp.passwordResetToken },
91
- }];
92
- }
45
+ var postPasswordResetStartHandler = function (_a) {
46
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
47
+ return __awaiter(void 0, void 0, void 0, function () {
48
+ var pluginName, genericAuthPlugin, repo, _b, jwtSecret, numberOfDigits, lifeTime, resp, emailCtx, emailSettings, subject, html, email;
49
+ var _c;
50
+ return __generator(this, function (_d) {
51
+ switch (_d.label) {
52
+ case 0:
53
+ pluginName = origin || "genericAuthPlugin";
54
+ genericAuthPlugin = ctx.plugins[pluginName];
55
+ repo = ctx.repos[genericAuthPlugin.repoName];
56
+ if (((_c = ctx.plugins.emailPlugin) === null || _c === void 0 ? void 0 : _c.client) == null) {
57
+ return [2 /*return*/, flink_1.internalServerError("Email plugin have to be initialized to use /password/reset")];
58
+ }
59
+ if (!genericAuthPlugin.passwordResetSettings) {
60
+ return [2 /*return*/, flink_1.internalServerError("Password reset settings is needed to use /password/reset")];
61
+ }
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)];
64
+ case 1:
65
+ resp = _d.sent();
66
+ if (resp.status != "success") {
67
+ return [2 /*return*/, { data: { status: "success", passwordResetToken: resp.passwordResetToken } }];
68
+ }
69
+ emailCtx = {
70
+ code: resp.code,
71
+ passwordResetToken: resp.passwordResetToken,
72
+ username: req.body.username,
73
+ profile: resp.profile,
74
+ };
75
+ emailSettings = genericAuthPlugin.passwordResetSettings.email;
76
+ if (typeof emailSettings == "function") {
77
+ emailSettings = emailSettings(emailCtx);
78
+ }
79
+ subject = handlebars_1.default.compile(emailSettings.subject)(emailCtx);
80
+ html = handlebars_1.default.compile(emailSettings.html)(emailCtx);
81
+ email = req.body.username;
82
+ return [4 /*yield*/, ctx.plugins.emailPlugin.client.send({
83
+ from: emailSettings.from_address,
84
+ to: [email],
85
+ subject: subject,
86
+ html: html,
87
+ })];
88
+ case 2:
89
+ _d.sent();
90
+ return [2 /*return*/, {
91
+ data: { status: "success", passwordResetToken: resp.passwordResetToken },
92
+ }];
93
+ }
94
+ });
93
95
  });
94
- }); };
96
+ };
95
97
  exports.default = postPasswordResetStartHandler;
96
98
  exports.__assumedHttpMethod = "", exports.__file = "UserPasswordResetStart.ts", exports.__query = [], exports.__params = [];
97
99
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "username": { "type": "string" } }, "required": ["username"], "definitions": {} }, resSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, "properties": { "status": { "type": "string", "enum": ["success", "userNotFound"] }, "passwordResetToken": { "type": "string" }, "profile": { "type": "object" } }, "required": ["status"], "definitions": {} } };
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ while (_) try {
18
18
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
19
  if (y = 0, t) op = [op[0] & 2, t.value];
20
20
  switch (op[0]) {
@@ -38,27 +38,29 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.__schemas = exports.__params = exports.__query = exports.__file = exports.__assumedHttpMethod = void 0;
40
40
  var flink_1 = require("@flink-app/flink");
41
- var getProfileHandler = function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
42
- var pluginName, repo, userId, user;
43
- var ctx = _b.ctx, req = _b.req, origin = _b.origin;
44
- return __generator(this, function (_c) {
45
- switch (_c.label) {
46
- case 0:
47
- pluginName = origin || "genericAuthPlugin";
48
- repo = ctx.repos[ctx.plugins[pluginName].repoName];
49
- userId = req.user._id;
50
- return [4 /*yield*/, repo.getById(userId)];
51
- case 1:
52
- user = _c.sent();
53
- if (user == null) {
54
- return [2 /*return*/, (0, flink_1.notFound)()];
55
- }
56
- return [2 /*return*/, {
57
- data: user.profile,
58
- }];
59
- }
41
+ var getProfileHandler = function (_a) {
42
+ var ctx = _a.ctx, req = _a.req, origin = _a.origin;
43
+ return __awaiter(void 0, void 0, void 0, function () {
44
+ var pluginName, repo, userId, user;
45
+ return __generator(this, function (_b) {
46
+ switch (_b.label) {
47
+ case 0:
48
+ pluginName = origin || "genericAuthPlugin";
49
+ repo = ctx.repos[ctx.plugins[pluginName].repoName];
50
+ userId = req.user._id;
51
+ return [4 /*yield*/, repo.getById(userId)];
52
+ case 1:
53
+ user = _b.sent();
54
+ if (user == null) {
55
+ return [2 /*return*/, flink_1.notFound()];
56
+ }
57
+ return [2 /*return*/, {
58
+ data: user.profile,
59
+ }];
60
+ }
61
+ });
60
62
  });
61
- }); };
63
+ };
62
64
  exports.default = getProfileHandler;
63
65
  exports.__assumedHttpMethod = "", exports.__file = "UserProfileGet.ts", exports.__query = [], exports.__params = [];
64
66
  exports.__schemas = { reqSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {}, "definitions": {} }, resSchema: undefined };