@steedos/accounts 2.6.1-beta.7 → 2.6.2-beta.2
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/lib/database-mongo/mongo.js +23 -3
- package/lib/database-mongo/mongo.js.map +1 -1
- package/lib/index.js +129 -125
- package/lib/index.js.map +1 -1
- package/lib/password/accounts-password.js +63 -18
- package/lib/password/accounts-password.js.map +1 -1
- package/lib/rest-express/endpoints/login.js +73 -10
- package/lib/rest-express/endpoints/login.js.map +1 -1
- package/lib/rest-express/endpoints/logout.js +56 -9
- package/lib/rest-express/endpoints/logout.js.map +1 -1
- package/lib/rest-express/endpoints/password/change-password.js +77 -17
- package/lib/rest-express/endpoints/password/change-password.js.map +1 -1
- package/lib/rest-express/endpoints/spaces.js +13 -1
- package/lib/rest-express/endpoints/spaces.js.map +1 -1
- package/lib/rest-express/endpoints/steedos/accept_invitation.js +48 -0
- package/lib/rest-express/endpoints/steedos/accept_invitation.js.map +1 -0
- package/lib/rest-express/endpoints/steedos/decline_invitation.js +48 -0
- package/lib/rest-express/endpoints/steedos/decline_invitation.js.map +1 -0
- package/lib/rest-express/endpoints/steedos/settings.js +19 -11
- package/lib/rest-express/endpoints/steedos/settings.js.map +1 -1
- package/lib/rest-express/express-middleware.js +4 -0
- package/lib/rest-express/express-middleware.js.map +1 -1
- package/lib/server/accounts-server.js +1 -1
- package/lib/server/accounts-server.js.map +1 -1
- package/package.json +7 -8
- package/src/database-mongo/mongo.ts +21 -4
- package/src/index.ts +13 -21
- package/src/password/accounts-password.ts +30 -2
- package/src/rest-express/endpoints/login.ts +64 -5
- package/src/rest-express/endpoints/logout.ts +51 -2
- package/src/rest-express/endpoints/password/change-password.ts +51 -2
- package/src/rest-express/endpoints/spaces.ts +6 -0
- package/src/rest-express/endpoints/steedos/accept_invitation.ts +37 -0
- package/src/rest-express/endpoints/steedos/decline_invitation.ts +37 -0
- package/src/rest-express/endpoints/steedos/settings.ts +14 -6
- package/src/rest-express/express-middleware.ts +4 -2
- package/src/server/accounts-server.ts +2 -1
- package/src/types/types/authentication-service.ts +2 -0
- package/src/types/types/database-interface.ts +2 -0
- package/src/types/types/session.ts +8 -0
|
@@ -2,15 +2,20 @@
|
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2022-05-19 11:38:30
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime:
|
|
5
|
+
* @LastEditTime: 2023-09-18 17:58:22
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
import * as express from 'express';
|
|
9
9
|
import { AccountsServer } from '../../../server';
|
|
10
10
|
import { sendError } from '../../utils/send-error';
|
|
11
|
-
import { getSteedosConfig } from '@steedos/objectql'
|
|
11
|
+
import { getSteedosConfig, getObject } from '@steedos/objectql'
|
|
12
12
|
import { hashPassword } from '../../../password/utils';
|
|
13
13
|
|
|
14
|
+
import * as requestIp from 'request-ip';
|
|
15
|
+
import { getUserAgent } from '../../utils/get-user-agent';
|
|
16
|
+
import isMobile from "ismobilejs";
|
|
17
|
+
import { db } from '../../../db';
|
|
18
|
+
|
|
14
19
|
const config = getSteedosConfig();
|
|
15
20
|
declare var Creator;
|
|
16
21
|
|
|
@@ -44,6 +49,50 @@ export const changePassword = (accountsServer: AccountsServer) => async (
|
|
|
44
49
|
Creator.getCollection('space_users').update({user: (req as any).userId}, {$set: {password_expired: false}}, {
|
|
45
50
|
multi: true
|
|
46
51
|
})
|
|
52
|
+
|
|
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);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const userSpaces = await db.find("space_users", {
|
|
68
|
+
filters: [["user", "=", (req as any).userId],["user_accepted", "=", true]],
|
|
69
|
+
fields: ["space"],
|
|
70
|
+
});
|
|
71
|
+
|
|
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
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
47
96
|
} catch (error) {
|
|
48
97
|
console.log('error', error);
|
|
49
98
|
}
|
|
@@ -18,3 +18,9 @@ export const getMySpaces = (accountsServer: AccountsServer) => async (
|
|
|
18
18
|
|
|
19
19
|
res.json(spaces);
|
|
20
20
|
};
|
|
21
|
+
|
|
22
|
+
// 获取第一个spaces
|
|
23
|
+
export const getFirstSpace = async (accountsServer: AccountsServer)=>{
|
|
24
|
+
const space = await accountsServer.db.getFirstSpace();
|
|
25
|
+
return space;
|
|
26
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { AccountsServer } from '../../../server';
|
|
3
|
+
import { sendError } from '../../utils/send-error';
|
|
4
|
+
import { db } from '../../../db';
|
|
5
|
+
|
|
6
|
+
export const AcceptInvitation = (accountsServer: AccountsServer) => async (
|
|
7
|
+
req: express.Request,
|
|
8
|
+
res: express.Response
|
|
9
|
+
) => {
|
|
10
|
+
try {
|
|
11
|
+
if ((req as any).user == null) {
|
|
12
|
+
throw new Error("accounts.access_denied")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const {tenantId, email} = req.body;
|
|
16
|
+
if (!tenantId)
|
|
17
|
+
throw new Error("accounts.tenant_required")
|
|
18
|
+
if (!email)
|
|
19
|
+
throw new Error("accounts.email_required")
|
|
20
|
+
|
|
21
|
+
const spaceUsers = await db.find('space_users', {
|
|
22
|
+
filters: [["space", "=", tenantId], ["email", "=", email], ["user_accepted", "=", false], ["invite_state", "=", "pending"]]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if(spaceUsers && spaceUsers.length == 1){
|
|
26
|
+
const spaceUser = spaceUsers[0];
|
|
27
|
+
await db.update('space_users', spaceUser._id, {
|
|
28
|
+
user_accepted: true,
|
|
29
|
+
invite_state: 'accepted'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
res.json({ok: 1});
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.log(err)
|
|
35
|
+
sendError(res, err);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { AccountsServer } from '../../../server';
|
|
3
|
+
import { sendError } from '../../utils/send-error';
|
|
4
|
+
import { db } from '../../../db';
|
|
5
|
+
|
|
6
|
+
export const DeclineInvitation = (accountsServer: AccountsServer) => async (
|
|
7
|
+
req: express.Request,
|
|
8
|
+
res: express.Response
|
|
9
|
+
) => {
|
|
10
|
+
try {
|
|
11
|
+
if ((req as any).user == null) {
|
|
12
|
+
throw new Error("accounts.access_denied")
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const {tenantId, email} = req.body;
|
|
16
|
+
if (!tenantId)
|
|
17
|
+
throw new Error("accounts.tenant_required")
|
|
18
|
+
if (!email)
|
|
19
|
+
throw new Error("accounts.email_required")
|
|
20
|
+
|
|
21
|
+
const spaceUsers = await db.find('space_users', {
|
|
22
|
+
filters: [["space", "=", tenantId], ["email", "=", email], ["user_accepted", "=", false], ["invite_state", "=", "pending"]]
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
if(spaceUsers && spaceUsers.length == 1){
|
|
26
|
+
const spaceUser = spaceUsers[0];
|
|
27
|
+
await db.update('space_users', spaceUser._id, {
|
|
28
|
+
user_accepted: false,
|
|
29
|
+
invite_state: 'refused'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
res.json({ok: 1});
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.log(err)
|
|
35
|
+
sendError(res, err);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Author: baozhoutao@steedos.com
|
|
3
3
|
* @Date: 2022-03-28 09:35:34
|
|
4
4
|
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
-
* @LastEditTime: 2023-
|
|
5
|
+
* @LastEditTime: 2023-11-21 09:56:06
|
|
6
6
|
* @Description:
|
|
7
7
|
*/
|
|
8
8
|
import * as express from 'express';
|
|
@@ -34,8 +34,9 @@ export const getSettings = (accountsServer: AccountsServer) => async (
|
|
|
34
34
|
enable_bind_mobile: false,
|
|
35
35
|
enable_bind_email: false,
|
|
36
36
|
enable_saas: validator.toBoolean(process.env.STEEDOS_TENANT_ENABLE_SAAS || 'false', true),
|
|
37
|
-
enable_open_geetest: validator.toBoolean(process.env.STEEDOS_CAPTCHA_GEETEST_ENABLED || 'false')
|
|
38
|
-
|
|
37
|
+
enable_open_geetest: validator.toBoolean(process.env.STEEDOS_CAPTCHA_GEETEST_ENABLED || 'false'),
|
|
38
|
+
page_login: process.env.STEEDOS_TENANT_PAGE_LOGIN,
|
|
39
|
+
page_logout: process.env.STEEDOS_TENANT_PAGE_LOGOUT
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
if (config.tenant) {
|
|
@@ -43,12 +44,14 @@ export const getSettings = (accountsServer: AccountsServer) => async (
|
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
if(!tenant._id){
|
|
46
|
-
tenant._id = process.env.
|
|
47
|
+
tenant._id = process.env.STEEDOS_TENANT_ID
|
|
47
48
|
}
|
|
49
|
+
|
|
50
|
+
const platform = (global as any).Meteor.settings.public?.platform || {}
|
|
48
51
|
|
|
49
52
|
|
|
50
53
|
if (tenant._id) {
|
|
51
|
-
let spaceDoc = await db.findOne("spaces", tenant._id, {fields: ["name", "avatar", "avatar_dark", "background", "enable_register", "account_logo"]})
|
|
54
|
+
let spaceDoc = await db.findOne("spaces", tenant._id, {fields: ["name", "avatar", "avatar_dark", "background", "enable_register", "account_logo", "favicon"]})
|
|
52
55
|
let steedosService = getSteedosService();
|
|
53
56
|
if (steedosService && spaceDoc) {
|
|
54
57
|
_.assignIn(tenant, spaceDoc);
|
|
@@ -62,6 +65,9 @@ export const getSettings = (accountsServer: AccountsServer) => async (
|
|
|
62
65
|
if (spaceDoc.background) {
|
|
63
66
|
tenant.background_url = steedosService + "api/files/avatars/" + spaceDoc.background
|
|
64
67
|
}
|
|
68
|
+
if (platform?.is_oem && spaceDoc.favicon){
|
|
69
|
+
tenant.favicon_url = steedosService + "api/files/avatars/" + spaceDoc.favicon
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
|
|
@@ -91,6 +97,8 @@ export const getSettings = (accountsServer: AccountsServer) => async (
|
|
|
91
97
|
already_mail_service: already_mail_service,
|
|
92
98
|
already_sms_service: already_sms_service,
|
|
93
99
|
serverInitInfo: serverInitInfo,
|
|
94
|
-
redirect_url_whitelist: process.env.REDIRECT_URL_WHITELIST
|
|
100
|
+
redirect_url_whitelist: process.env.REDIRECT_URL_WHITELIST,
|
|
101
|
+
platform: platform,
|
|
102
|
+
public: (global as any).Meteor.settings.public || {}
|
|
95
103
|
})
|
|
96
104
|
}
|
|
@@ -25,7 +25,8 @@ import { login } from './endpoints/login';
|
|
|
25
25
|
import { getMySpaces } from './endpoints/spaces';
|
|
26
26
|
import { verify_email, verify_mobile} from './endpoints/password/verify';
|
|
27
27
|
import { geetest_init,geetest_validate } from './endpoints/geetestV3/geetest-init'
|
|
28
|
-
|
|
28
|
+
import { AcceptInvitation } from './endpoints/steedos/accept_invitation';
|
|
29
|
+
import { DeclineInvitation} from './endpoints/steedos/decline_invitation';
|
|
29
30
|
|
|
30
31
|
const defaultOptions: AccountsExpressOptions = {
|
|
31
32
|
path: '/accounts',
|
|
@@ -57,7 +58,8 @@ const accountsExpress = (
|
|
|
57
58
|
router.get(`${path}/settings`, userLoader(accountsServer), getSettings(accountsServer));
|
|
58
59
|
router.get(`${path}/tenant/:id`, userLoader(accountsServer), getTenant(accountsServer));
|
|
59
60
|
// router.post(`${path}/tenant`, userLoader(accountsServer), createTenant(accountsServer));
|
|
60
|
-
|
|
61
|
+
router.post(`${path}/acceptInvitation`, userLoader(accountsServer), AcceptInvitation(accountsServer));
|
|
62
|
+
router.post(`${path}/declineInvitation`, userLoader(accountsServer), DeclineInvitation(accountsServer));
|
|
61
63
|
router.post(`${path}/refreshTokens`, refreshAccessToken(accountsServer));
|
|
62
64
|
|
|
63
65
|
router.post(`${path}/logout`, userLoader(accountsServer), logout(accountsServer));
|
|
@@ -511,7 +511,7 @@ export class AccountsServer {
|
|
|
511
511
|
* @param {string} accessToken - User access token.
|
|
512
512
|
* @returns {Promise<void>} - Return a promise.
|
|
513
513
|
*/
|
|
514
|
-
public async logout(token: string): Promise<
|
|
514
|
+
public async logout(token: string): Promise<Session> {
|
|
515
515
|
try {
|
|
516
516
|
const session: Session = await this.db.findSessionByToken(token);
|
|
517
517
|
|
|
@@ -524,6 +524,7 @@ export class AccountsServer {
|
|
|
524
524
|
} else {
|
|
525
525
|
throw new Error("Session is no longer valid");
|
|
526
526
|
}
|
|
527
|
+
return session;
|
|
527
528
|
} catch (error) {
|
|
528
529
|
this.hooks.emit(ServerHooks.LogoutError, error);
|
|
529
530
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import { User } from './user';
|
|
2
3
|
import { DatabaseInterface } from './database-interface';
|
|
3
4
|
|
|
@@ -10,4 +11,5 @@ export interface AuthenticationService {
|
|
|
10
11
|
setStore(store: DatabaseInterface): void;
|
|
11
12
|
authenticate(params: any): Promise<User | null>;
|
|
12
13
|
getUserProfile(userId: string): Promise<any | null>;
|
|
14
|
+
foundUser(user: any): Promise<any | null>;
|
|
13
15
|
}
|
|
@@ -69,6 +69,8 @@ export interface DatabaseInterface extends DatabaseInterfaceSessions {
|
|
|
69
69
|
|
|
70
70
|
getMySpaces(userId: string): Promise<any | null>;
|
|
71
71
|
|
|
72
|
+
getFirstSpace(): Promise<any | null>;
|
|
73
|
+
|
|
72
74
|
getInviteInfo(id: string): Promise<any | null>;
|
|
73
75
|
|
|
74
76
|
setEmail(userId: string, newEmail: string): Promise<void>;
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: baozhoutao@steedos.com
|
|
3
|
+
* @Date: 2022-03-28 09:35:34
|
|
4
|
+
* @LastEditors: baozhoutao@steedos.com
|
|
5
|
+
* @LastEditTime: 2023-09-19 09:13:33
|
|
6
|
+
* @Description:
|
|
7
|
+
*/
|
|
1
8
|
export interface Session {
|
|
2
9
|
id: string;
|
|
3
10
|
userId: string;
|
|
@@ -7,4 +14,5 @@ export interface Session {
|
|
|
7
14
|
ip?: string;
|
|
8
15
|
createdAt: string;
|
|
9
16
|
updatedAt: string;
|
|
17
|
+
space?: string
|
|
10
18
|
}
|