@steedos/accounts 3.0.0-beta.71 → 3.0.0-beta.72

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.
@@ -9,96 +9,101 @@ var get_user_agent_1 = require("../../utils/get-user-agent");
9
9
  var ismobilejs_1 = require("ismobilejs");
10
10
  var db_1 = require("../../../db");
11
11
  var config = (0, objectql_1.getSteedosConfig)();
12
- var changePassword = function (accountsServer) { return function (req, res) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
13
- var _a, oldPassword, newPassword, password, userAgent, ip, is_phone, is_tablet, _b, phone, tablet, userSpaces, _i, userSpaces_1, userSpace, userId, error_1, err_1;
14
- return tslib_1.__generator(this, function (_c) {
15
- switch (_c.label) {
16
- case 0:
17
- _c.trys.push([0, 10, , 11]);
18
- if (!req.userId) {
19
- res.status(401);
20
- res.json({ message: 'Unauthorized' });
21
- return [2];
22
- }
23
- _a = req.body, oldPassword = _a.oldPassword, newPassword = _a.newPassword;
24
- password = accountsServer.getServices().password;
25
- return [4, password.changePassword(req.userId, oldPassword, newPassword)];
26
- case 1:
27
- _c.sent();
28
- password.db.collection.updateOne({ _id: req.userId }, { $set: { password_expired: false } });
29
- _c.label = 2;
30
- case 2:
31
- _c.trys.push([2, 8, , 9]);
32
- Creator.getCollection('space_users').update({ user: req.userId }, { $set: { password_expired: false } }, {
33
- multi: true
34
- });
35
- userAgent = (0, get_user_agent_1.getUserAgent)(req);
36
- ip = requestIp.getClientIp(req);
37
- is_phone = false;
38
- is_tablet = false;
39
- if (userAgent) {
40
- try {
41
- _b = (0, ismobilejs_1.default)(userAgent), phone = _b.phone, tablet = _b.tablet;
42
- is_phone = phone;
43
- is_tablet = tablet;
12
+ var changePassword = function (accountsServer) {
13
+ return function (req, res) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
14
+ var _a, oldPassword, newPassword, password, userAgent, ip, is_phone, is_tablet, _b, phone, tablet, userSpaces, _i, userSpaces_1, userSpace, userId, error_1, err_1;
15
+ return tslib_1.__generator(this, function (_c) {
16
+ switch (_c.label) {
17
+ case 0:
18
+ _c.trys.push([0, 11, , 12]);
19
+ if (!req.userId) {
20
+ res.status(401);
21
+ res.json({ message: "Unauthorized" });
22
+ return [2];
44
23
  }
45
- catch (Exception) {
46
- console.log("Exception", Exception);
47
- }
48
- }
49
- return [4, db_1.db.find("space_users", {
50
- filters: [["user", "=", req.userId], ["user_accepted", "=", true]],
51
- fields: ["space"],
52
- })];
53
- case 3:
54
- userSpaces = _c.sent();
55
- if (!(userSpaces && userSpaces.length > 0)) return [3, 7];
56
- _i = 0, userSpaces_1 = userSpaces;
57
- _c.label = 4;
58
- case 4:
59
- if (!(_i < userSpaces_1.length)) return [3, 7];
60
- userSpace = userSpaces_1[_i];
61
- userId = req.userId;
62
- return [4, (0, objectql_1.getObject)('operation_logs').insert({
63
- name: '修改密码',
64
- type: 'change_password',
65
- remote_user: userId,
66
- remote_addr: ip,
67
- http_user_agent: userAgent,
68
- is_mobile: is_phone,
69
- is_tablet: is_tablet,
70
- object: 'users',
71
- status: 'success',
72
- create: new Date(),
73
- create_by: userId,
74
- modified_by: userId,
75
- space: userSpace.space,
76
- related_to: {
77
- o: "users",
78
- ids: [userId]
24
+ _a = req.body, oldPassword = _a.oldPassword, newPassword = _a.newPassword;
25
+ password = accountsServer.getServices().password;
26
+ return [4, password.changePassword(req.userId, oldPassword, newPassword)];
27
+ case 1:
28
+ _c.sent();
29
+ password.db.collection.updateOne({ _id: req.userId }, { $set: { password_expired: false } });
30
+ _c.label = 2;
31
+ case 2:
32
+ _c.trys.push([2, 9, , 10]);
33
+ return [4, db_1.db.updateMany("space_users", [["user", "=", req.userId]], { password_expired: false })];
34
+ case 3:
35
+ _c.sent();
36
+ userAgent = (0, get_user_agent_1.getUserAgent)(req);
37
+ ip = requestIp.getClientIp(req);
38
+ is_phone = false;
39
+ is_tablet = false;
40
+ if (userAgent) {
41
+ try {
42
+ _b = (0, ismobilejs_1.default)(userAgent), phone = _b.phone, tablet = _b.tablet;
43
+ is_phone = phone;
44
+ is_tablet = tablet;
45
+ }
46
+ catch (Exception) {
47
+ console.log("Exception", Exception);
79
48
  }
80
- })];
81
- case 5:
82
- _c.sent();
83
- _c.label = 6;
84
- case 6:
85
- _i++;
86
- return [3, 4];
87
- case 7: return [3, 9];
88
- case 8:
89
- error_1 = _c.sent();
90
- console.log('error', error_1);
91
- return [3, 9];
92
- case 9:
93
- res.json({ userId: req.userId, password_expired: false });
94
- return [3, 11];
95
- case 10:
96
- err_1 = _c.sent();
97
- (0, send_error_1.sendError)(res, err_1);
98
- return [3, 11];
99
- case 11: return [2];
100
- }
101
- });
102
- }); }; };
49
+ }
50
+ return [4, db_1.db.find("space_users", {
51
+ filters: [
52
+ ["user", "=", req.userId],
53
+ ["user_accepted", "=", true],
54
+ ],
55
+ fields: ["space"],
56
+ })];
57
+ case 4:
58
+ userSpaces = _c.sent();
59
+ if (!(userSpaces && userSpaces.length > 0)) return [3, 8];
60
+ _i = 0, userSpaces_1 = userSpaces;
61
+ _c.label = 5;
62
+ case 5:
63
+ if (!(_i < userSpaces_1.length)) return [3, 8];
64
+ userSpace = userSpaces_1[_i];
65
+ userId = req.userId;
66
+ return [4, (0, objectql_1.getObject)("operation_logs").insert({
67
+ name: "修改密码",
68
+ type: "change_password",
69
+ remote_user: userId,
70
+ remote_addr: ip,
71
+ http_user_agent: userAgent,
72
+ is_mobile: is_phone,
73
+ is_tablet: is_tablet,
74
+ object: "users",
75
+ status: "success",
76
+ create: new Date(),
77
+ create_by: userId,
78
+ modified_by: userId,
79
+ space: userSpace.space,
80
+ related_to: {
81
+ o: "users",
82
+ ids: [userId],
83
+ },
84
+ })];
85
+ case 6:
86
+ _c.sent();
87
+ _c.label = 7;
88
+ case 7:
89
+ _i++;
90
+ return [3, 5];
91
+ case 8: return [3, 10];
92
+ case 9:
93
+ error_1 = _c.sent();
94
+ console.log("error", error_1);
95
+ return [3, 10];
96
+ case 10:
97
+ res.json({ userId: req.userId, password_expired: false });
98
+ return [3, 12];
99
+ case 11:
100
+ err_1 = _c.sent();
101
+ (0, send_error_1.sendError)(res, err_1);
102
+ return [3, 12];
103
+ case 12: return [2];
104
+ }
105
+ });
106
+ }); };
107
+ };
103
108
  exports.changePassword = changePassword;
104
109
  //# sourceMappingURL=change-password.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"change-password.js","sourceRoot":"","sources":["../../../../src/rest-express/endpoints/password/change-password.ts"],"names":[],"mappings":";;;;AASA,qDAAmD;AACnD,8CAA+D;AAG/D,sCAAwC;AACxC,6DAA0D;AAC1D,yCAAkC;AAClC,kCAAiC;AAEjC,IAAM,MAAM,GAAG,IAAA,2BAAgB,GAAE,CAAC;AAG3B,IAAM,cAAc,GAAG,UAAC,cAA8B,IAAK,OAAA,UAChE,GAAoB,EACpB,GAAqB;;;;;;gBAGnB,IAAI,CAAE,GAAW,CAAC,MAAM,EAAE,CAAC;oBACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;oBAChB,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC;oBACtC,WAAO;gBACT,CAAC;gBAEK,KAA+B,GAAG,CAAC,IAAI,EAArC,WAAW,iBAAA,EAAE,WAAW,iBAAA,CAAc;gBAWxC,QAAQ,GAAQ,cAAc,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC;gBAE5D,WAAM,QAAQ,CAAC,cAAc,CAAE,GAAW,CAAC,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,EAAA;;gBAA5E,SAA4E,CAAC;gBAC7E,QAAQ,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAC,GAAG,EAAG,GAAW,CAAC,MAAM,EAAC,EAAE,EAAC,IAAI,EAAE,EAAC,gBAAgB,EAAE,KAAK,EAAC,EAAC,CAAC,CAAA;;;;gBAE7F,OAAO,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,EAAC,I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AiB;wBACvB,WAAW,EAAE,MAAM;wBACnB,WAAW,EAAE,EAAE;wBACf,eAAe,EAAE,SAAS;wBAC1B,SAAS,EAAE,QAAQ;wBACnB,SAAS,WAAA;wBACT,MAAM,EAAE,OAAO;wBACf,MAAM,EAAE,SAAS;wBACjB,MAAM,EAAE,IAAI,IAAI,EAAE;wBAClB,SAAS,EAAE,MAAM;wBACjB,WAAW,EAAE,MAAM;wBACnB,KAAK,EAAE,SAAS,CAAC,KAAK;wBACtB,UAAU,EAAE;4BACV,CAAC,EAAE,OAAO;4BACV,GAAG,EAAE,CAAC,MAAM,CAAC;yBACd;qBACF,CAAC,EAAA;;gBAlBF,SAkBE,CAAA;;;gBApBkB,IAAU,CAAA;;;;;gBAwBlC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,OAAK,CAAC,CAAC;;;gBAE9B,GAAG,CAAC,IAAI,CAAC,EAAC,MAAM,EAAG,GAAW,CAAC,MAAM,EAAE,gBAAgB,EAAE,KAAK,EAAC,CAAC,CAAC;;;;gBAEjE,IAAA,sBAAS,EAAC,GAAG,EAAE,KAAG,CAAC,CAAC;;;;;KAEvB,EAjFiE,CAiFjE,CAAC;AAjFW,QAAA,cAAc,kBAiFzB"}
1
+ {"version":3,"file":"change-password.js","sourceRoot":"","sources":["../../../../src/rest-express/endpoints/password/change-password.ts"],"names":[],"mappings":";;;;AASA,qDAAmD;AACnD,8CAAgE;AAGhE,sCAAwC;AACxC,6DAA0D;AAC1D,yCAAkC;AAClC,kCAAiC;AAEjC,IAAM,MAAM,GAAG,IAAA,2BAAgB,GAAE,CAAC;AAG3B,IAAM,cAAc,GACzB,UAAC,cAA8B;IAC/B,OAAA,UAAO,GAAoB,EAAE,GAAqB;;;;;;oBAE9C,IAAI,CAAE,GAAW,CAAC,MAAM,EAAE,CAAC;wBACzB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;wBAChB,GAAG,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE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AAC;AA5FS,QAAA,cAAc,kBA4FvB"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@steedos/accounts",
3
3
  "private": false,
4
- "version": "3.0.0-beta.71",
4
+ "version": "3.0.0-beta.72",
5
5
  "main": "lib/index.js",
6
6
  "files": [
7
7
  "/package.json",
@@ -29,9 +29,9 @@
29
29
  "@accounts/two-factor": "^0.20.1",
30
30
  "@accounts/types": "0.20.1",
31
31
  "@babel/runtime": "^7.12.18",
32
- "@steedos/auth": "3.0.0-beta.71",
33
- "@steedos/objectql": "3.0.0-beta.71",
34
- "@steedos/utils": "3.0.0-beta.71",
32
+ "@steedos/auth": "3.0.0-beta.72",
33
+ "@steedos/objectql": "3.0.0-beta.72",
34
+ "@steedos/utils": "3.0.0-beta.72",
35
35
  "app-root-path": "^2.2.1",
36
36
  "bcryptjs": "^2.4.3",
37
37
  "body-parser": "1.19.0",
@@ -60,5 +60,5 @@
60
60
  "publishConfig": {
61
61
  "access": "public"
62
62
  },
63
- "gitHead": "32cf4e8cafda54a3e30a46a6506eaa021fa25fb7"
63
+ "gitHead": "18b81ddcdafac5d7690c29bfdb1ee0bd8cf8bc48"
64
64
  }
@@ -3,101 +3,112 @@
3
3
  * @Date: 2022-05-19 11:38:30
4
4
  * @LastEditors: baozhoutao@steedos.com
5
5
  * @LastEditTime: 2023-09-18 17:58:22
6
- * @Description:
6
+ * @Description:
7
7
  */
8
- import * as express from 'express';
9
- import { AccountsServer } from '../../../server';
10
- import { sendError } from '../../utils/send-error';
11
- import { getSteedosConfig, getObject } from '@steedos/objectql'
12
- import { hashPassword } from '../../../password/utils';
8
+ import * as express from "express";
9
+ import { AccountsServer } from "../../../server";
10
+ import { sendError } from "../../utils/send-error";
11
+ import { getSteedosConfig, getObject } from "@steedos/objectql";
12
+ import { hashPassword } from "../../../password/utils";
13
13
 
14
- import * as requestIp from 'request-ip';
15
- import { getUserAgent } from '../../utils/get-user-agent';
14
+ import * as requestIp from "request-ip";
15
+ import { getUserAgent } from "../../utils/get-user-agent";
16
16
  import isMobile from "ismobilejs";
17
- import { db } from '../../../db';
17
+ import { db } from "../../../db";
18
18
 
19
19
  const config = getSteedosConfig();
20
20
  declare var Creator;
21
21
 
22
- export const changePassword = (accountsServer: AccountsServer) => async (
23
- req: express.Request,
24
- res: express.Response
25
- ) => {
26
- try {
27
- if (!(req as any).userId) {
28
- res.status(401);
29
- res.json({ message: 'Unauthorized' });
30
- return;
31
- }
32
- // oldPassword newPassword 已经是 sha256之后的
33
- const { oldPassword, newPassword } = req.body;
22
+ export const changePassword =
23
+ (accountsServer: AccountsServer) =>
24
+ async (req: express.Request, res: express.Response) => {
25
+ try {
26
+ if (!(req as any).userId) {
27
+ res.status(401);
28
+ res.json({ message: "Unauthorized" });
29
+ return;
30
+ }
31
+ // oldPassword 、newPassword 已经是 sha256之后的
32
+ const { oldPassword, newPassword } = req.body;
34
33
 
35
- // let passworPolicy = ((config as any).password || {}).policy
34
+ // let passworPolicy = ((config as any).password || {}).policy
36
35
 
37
- // if(passworPolicy){
38
- // if(!(new RegExp(passworPolicy)).test(newPassword || '')){
39
- // sendError(res, new Error((config as any).password.policyError));
40
- // return;
41
- // }
42
- // }
43
-
44
- const password: any = accountsServer.getServices().password;
36
+ // if(passworPolicy){
37
+ // if(!(new RegExp(passworPolicy)).test(newPassword || '')){
38
+ // sendError(res, new Error((config as any).password.policyError));
39
+ // return;
40
+ // }
41
+ // }
45
42
 
46
- await password.changePassword((req as any).userId, oldPassword, newPassword);
47
- password.db.collection.updateOne({_id: (req as any).userId}, {$set: {password_expired: false}})
48
- try {
49
- Creator.getCollection('space_users').update({user: (req as any).userId}, {$set: {password_expired: false}}, {
50
- multi: true
51
- })
43
+ const password: any = accountsServer.getServices().password;
44
+
45
+ await password.changePassword(
46
+ (req as any).userId,
47
+ oldPassword,
48
+ newPassword,
49
+ );
50
+ password.db.collection.updateOne(
51
+ { _id: (req as any).userId },
52
+ { $set: { password_expired: false } },
53
+ );
54
+ try {
55
+ await db.updateMany(
56
+ "space_users",
57
+ [["user", "=", (req as any).userId]],
58
+ { password_expired: false },
59
+ );
52
60
 
53
- const userAgent = getUserAgent(req);
54
- const ip = requestIp.getClientIp(req);
55
- let is_phone = false;
56
- let is_tablet = false;
57
- if (userAgent) {
58
- try {
59
- const { phone, tablet } = isMobile(userAgent);
60
- is_phone = phone;
61
- is_tablet = tablet;
62
- } catch (Exception) {
63
- console.log(`Exception`, Exception);
61
+ const userAgent = getUserAgent(req);
62
+ const ip = requestIp.getClientIp(req);
63
+ let is_phone = false;
64
+ let is_tablet = false;
65
+ if (userAgent) {
66
+ try {
67
+ const { phone, tablet } = isMobile(userAgent);
68
+ is_phone = phone;
69
+ is_tablet = tablet;
70
+ } catch (Exception) {
71
+ console.log(`Exception`, Exception);
72
+ }
64
73
  }
65
- }
66
74
 
67
- const userSpaces = await db.find("space_users", {
68
- filters: [["user", "=", (req as any).userId],["user_accepted", "=", true]],
69
- fields: ["space"],
70
- });
75
+ const userSpaces = await db.find("space_users", {
76
+ filters: [
77
+ ["user", "=", (req as any).userId],
78
+ ["user_accepted", "=", true],
79
+ ],
80
+ fields: ["space"],
81
+ });
71
82
 
72
- if(userSpaces && userSpaces.length > 0){
73
- for (let userSpace of userSpaces) {
74
- const userId = (req as any).userId
75
- await getObject('operation_logs').insert({
76
- name: '修改密码',
77
- type: 'change_password',
78
- remote_user: userId,
79
- remote_addr: ip,
80
- http_user_agent: userAgent,
81
- is_mobile: is_phone,
82
- is_tablet,
83
- object: 'users',
84
- status: 'success',
85
- create: new Date(),
86
- create_by: userId,
87
- modified_by: userId,
88
- space: userSpace.space,
89
- related_to: {
90
- o: "users",
91
- ids: [userId]
92
- }
93
- })
83
+ if (userSpaces && userSpaces.length > 0) {
84
+ for (let userSpace of userSpaces) {
85
+ const userId = (req as any).userId;
86
+ await getObject("operation_logs").insert({
87
+ name: "修改密码",
88
+ type: "change_password",
89
+ remote_user: userId,
90
+ remote_addr: ip,
91
+ http_user_agent: userAgent,
92
+ is_mobile: is_phone,
93
+ is_tablet,
94
+ object: "users",
95
+ status: "success",
96
+ create: new Date(),
97
+ create_by: userId,
98
+ modified_by: userId,
99
+ space: userSpace.space,
100
+ related_to: {
101
+ o: "users",
102
+ ids: [userId],
103
+ },
104
+ });
105
+ }
94
106
  }
107
+ } catch (error) {
108
+ console.log("error", error);
95
109
  }
96
- } catch (error) {
97
- console.log('error', error);
110
+ res.json({ userId: (req as any).userId, password_expired: false });
111
+ } catch (err) {
112
+ sendError(res, err);
98
113
  }
99
- res.json({userId: (req as any).userId, password_expired: false});
100
- } catch (err) {
101
- sendError(res, err);
102
- }
103
- };
114
+ };