@cocreate/users 1.5.3 → 1.6.0
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/CHANGELOG.md +22 -0
- package/demo/login.html +90 -0
- package/demo/logout.html +39 -0
- package/demo/signup.html +110 -0
- package/package.json +1 -1
- package/src/client.js +12 -44
- package/src/server.js +64 -120
- package/demo/index.html +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [1.6.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.5...v1.6.0) (2022-05-11)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* store lastlogin datetime in db. Add demos for signup, login, logout ([7df894a](https://github.com/CoCreate-app/CoCreate-users/commit/7df894a85931c4f6c632c70429b0df72acd0867d))
|
|
7
|
+
|
|
8
|
+
## [1.5.5](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.4...v1.5.5) (2022-05-09)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* client.js - remove adminUI_id and builderUI_id ([88da86d](https://github.com/CoCreate-app/CoCreate-users/commit/88da86d9ecc31a12d3eb5cef0a941c38697828ad))
|
|
14
|
+
* insert returns insertedId instead of [0]._id ([36c83fc](https://github.com/CoCreate-app/CoCreate-users/commit/36c83fc08d0ba70a3a9993b4d06bf8ad3304b2f7))
|
|
15
|
+
|
|
16
|
+
## [1.5.4](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.3...v1.5.4) (2022-05-08)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* convert user_id object_id to string ([bec7113](https://github.com/CoCreate-app/CoCreate-users/commit/bec711359b99594c0a6207ca478a73968dbc0a41))
|
|
22
|
+
|
|
1
23
|
## [1.5.3](https://github.com/CoCreate-app/CoCreate-users/compare/v1.5.2...v1.5.3) (2022-05-06)
|
|
2
24
|
|
|
3
25
|
|
package/demo/login.html
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Login | CoCreateJS</title>
|
|
5
|
+
|
|
6
|
+
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
7
|
+
<link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body style='background-image: url("https://cdn.cocreate.app/background.png");'>
|
|
11
|
+
<a href="./logout.html" session="true" hidden></a>
|
|
12
|
+
|
|
13
|
+
<a href="./signup.html" title="" class="position:relative z-index:1 float:right margin:15px margin-left:auto color:white">Sign Up</a>
|
|
14
|
+
|
|
15
|
+
<div class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
|
|
16
|
+
<div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
|
|
17
|
+
|
|
18
|
+
<form realtime="false" collection="users" id="signin">
|
|
19
|
+
<div class="overflow:hidden padding:0px_25px background:white">
|
|
20
|
+
<div class="float:left width:75% padding-top:25px">
|
|
21
|
+
<h3>Sign In</h3>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
|
|
24
|
+
<i class="fas fa-sign-in-alt"></i>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<div class="padding:25px background:gainsboro text-align:left">
|
|
28
|
+
|
|
29
|
+
<floating-label>
|
|
30
|
+
<input type="email" name='email' placeholder="Email" class="floating-label">
|
|
31
|
+
</floating-label>
|
|
32
|
+
|
|
33
|
+
<floating-label>
|
|
34
|
+
<input type="password" name='password' placeholder="Password" class="floating-label">
|
|
35
|
+
</floating-label>
|
|
36
|
+
|
|
37
|
+
<button actions="login" href="logout.html" class="outline">Login</button>
|
|
38
|
+
|
|
39
|
+
<a show='#forgotpass' hide='#signin'>Forgot Password</a>
|
|
40
|
+
</div>
|
|
41
|
+
</form>
|
|
42
|
+
|
|
43
|
+
<form collection="users" hidden id="forgotpass">
|
|
44
|
+
<div class="overflow:hidden padding:0px_25px background:white">
|
|
45
|
+
<div class="float:left width:75% padding-top:25px">
|
|
46
|
+
<h3>Password Recovery</h3>
|
|
47
|
+
</div>
|
|
48
|
+
<div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
|
|
49
|
+
<i class="fas fa-key"></i>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
<div class="padding:25px background:gainsboro text-align:left">
|
|
53
|
+
<floating-label>
|
|
54
|
+
<input type="email" name='email' id="email" placeholder="Email" class="floating-label">
|
|
55
|
+
</floating-label>
|
|
56
|
+
|
|
57
|
+
<button class="outline">
|
|
58
|
+
<a>Send Email</a>
|
|
59
|
+
</button>
|
|
60
|
+
|
|
61
|
+
<a show='#signin' hide='#forgotpass'>login</a>
|
|
62
|
+
</div>
|
|
63
|
+
</form>
|
|
64
|
+
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
|
|
68
|
+
<div class="position:fixed!important bottom:15px right:15px">
|
|
69
|
+
<div template_id="login" class="template card margin:5px padding:10px {{status}}">
|
|
70
|
+
<span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
|
|
71
|
+
</div>
|
|
72
|
+
|
|
73
|
+
<div template_id="notification" class="template card position:fixed!important bottom:15px right:15px padding:10px {{status}}">
|
|
74
|
+
<span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<script>
|
|
79
|
+
var config = {
|
|
80
|
+
apiKey: '2061acef-0451-4545-f754-60cf8160', // Your apiKey can be retrived after signing up at https://cocreate.app
|
|
81
|
+
organization_id: '5ff747727005da1c272740ab', // Your organization_id can be retrived after signing up at https://cocreate.app
|
|
82
|
+
host: 'server.cocreate.app' // Points to socket server. If not defined it will use the url in web browser by default
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<script src="https://cdn.cocreate.app/1.14.5/CoCreate.min.js"></script>
|
|
87
|
+
<!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
|
|
88
|
+
|
|
89
|
+
</body>
|
|
90
|
+
</html>
|
package/demo/logout.html
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<title>Logout | CoCreateJS</title>
|
|
5
|
+
|
|
6
|
+
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
7
|
+
<link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
|
|
8
|
+
</head>
|
|
9
|
+
|
|
10
|
+
<body style='background-image: url("https://cdn.cocreate.app/background.png");'>
|
|
11
|
+
<a href="./login.html" session="false" hidden></a>
|
|
12
|
+
|
|
13
|
+
<div class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
|
|
14
|
+
<div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
|
|
15
|
+
<div class="overflow:hidden padding:0px_25px background:white">
|
|
16
|
+
<div class="float:left width:75% padding-top:25px">
|
|
17
|
+
<h3>You are logged in</h3>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
|
|
20
|
+
<i class="fas fa-sign-in-alt"></i>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
<div class="padding:25px background:gainsboro text-align:left">
|
|
24
|
+
<button actions="logout" href="./login.html">Logout</button>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
|
|
29
|
+
<div class="position:fixed!important bottom:15px right:15px">
|
|
30
|
+
<div template_id="notification" class="template card position:fixed!important bottom:15px right:15px padding:10px {{status}}">
|
|
31
|
+
<span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<script src="https://cdn.cocreate.app/1.14.5/CoCreate.min.js"></script>
|
|
36
|
+
<!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
|
|
37
|
+
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
package/demo/signup.html
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
8
|
+
<title>Sign up | CoCreate</title>
|
|
9
|
+
<link rel="icon" type="image/png" sizes="32x32" href="assets/favicon.ico">
|
|
10
|
+
<link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
.speech-bubble:after { content: ''; position: absolute; top: 0; left: 50%; width: 0; height: 0; border: 23px solid transparent; border-bottom-color: #ffffff; border-top: 0; margin-left: -23px; margin-top: -23px;}
|
|
15
|
+
</style>
|
|
16
|
+
|
|
17
|
+
<body style='background: url("https://cdn.cocreate.app/background.png") no-repeat fixed;-webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;'>
|
|
18
|
+
<a href="./index.html" session="true" hidden></a>
|
|
19
|
+
|
|
20
|
+
<a href="./signin.html" title="" class="position:relative z-index:1 float:right margin:15px margin-left:auto color:white">Sign In</a>
|
|
21
|
+
|
|
22
|
+
<main class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
|
|
23
|
+
<div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
|
|
24
|
+
|
|
25
|
+
<form realtime="false" autocomplete="off">
|
|
26
|
+
|
|
27
|
+
<section>
|
|
28
|
+
<div class="overflow:hidden padding:0px_25px background:white">
|
|
29
|
+
<div class="float:left width:75% padding-top:25px">
|
|
30
|
+
<h3>Sign UP</h3>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="float:right width:25% padding-top:5px font-size:70px line-height:100px text-align:right color:very-light-gray">
|
|
33
|
+
<i class="fa fa-key"></i>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="padding:25px background:gainsboro text-align:left">
|
|
37
|
+
<floating-label>
|
|
38
|
+
<input type="text" id="name"
|
|
39
|
+
collection="users"
|
|
40
|
+
document_id=""
|
|
41
|
+
name="name"
|
|
42
|
+
placeholder="Full Name"
|
|
43
|
+
class="floating-label"
|
|
44
|
+
autocomplete="off"
|
|
45
|
+
required>
|
|
46
|
+
</floating-label>
|
|
47
|
+
<floating-label>
|
|
48
|
+
<input type="email" id="email"
|
|
49
|
+
collection="users"
|
|
50
|
+
unique
|
|
51
|
+
document_id=""
|
|
52
|
+
name='email'
|
|
53
|
+
placeholder="Email"
|
|
54
|
+
class="floating-label"
|
|
55
|
+
required>
|
|
56
|
+
</floating-label>
|
|
57
|
+
<small id="errorUemail" class="text-danger"></small>
|
|
58
|
+
|
|
59
|
+
<floating-label>
|
|
60
|
+
<input type="password" id="password"
|
|
61
|
+
collection="users"
|
|
62
|
+
document_id=""
|
|
63
|
+
name="password"
|
|
64
|
+
placeholder="Password"
|
|
65
|
+
class="floating-label">
|
|
66
|
+
</floating-label>
|
|
67
|
+
<small id="errorUpassword" class="text-danger"></small>
|
|
68
|
+
|
|
69
|
+
<floating-label>
|
|
70
|
+
<input type="password"
|
|
71
|
+
matches="#password"
|
|
72
|
+
placeholder="Confirm Password"
|
|
73
|
+
class="floating-label">
|
|
74
|
+
</floating-label>
|
|
75
|
+
<small id="errorUconfirmpassword" class="text-danger"></small>
|
|
76
|
+
|
|
77
|
+
<div class="display:flex">
|
|
78
|
+
<button type="button" class="outline red-white startAnimation" actions="validate, createUser, login" href="logout.html">
|
|
79
|
+
Sign Up
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
</div>
|
|
84
|
+
</section>
|
|
85
|
+
</form>
|
|
86
|
+
</div>
|
|
87
|
+
</main>
|
|
88
|
+
|
|
89
|
+
<div class="position:fixed!important bottom:15px right:15px">
|
|
90
|
+
<div template_id="validate" class="template card margin:5px padding:10px {{status}}">
|
|
91
|
+
<span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
|
|
92
|
+
</div>
|
|
93
|
+
|
|
94
|
+
<div template_id="notification" class="template card margin:5px padding:10px {{status}}">
|
|
95
|
+
<span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
|
|
99
|
+
<script>
|
|
100
|
+
var config = {
|
|
101
|
+
apiKey: '2061acef-0451-4545-f754-60cf8160', // Your apiKey can be retrived after signing up at https://cocreate.app
|
|
102
|
+
organization_id: '5ff747727005da1c272740ab', // Your organization_id can be retrived after signing up at https://cocreate.app
|
|
103
|
+
host: 'server.cocreate.app' // Points to socket server. If not defined it will use the url in web browser by default
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
<script src="https://cdn.cocreate.app/1.14.5/CoCreate.min.js"></script>
|
|
107
|
+
<!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
|
|
108
|
+
|
|
109
|
+
</body>
|
|
110
|
+
</html>
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -34,18 +34,13 @@ const CoCreateUser = {
|
|
|
34
34
|
detail: data
|
|
35
35
|
}));
|
|
36
36
|
});
|
|
37
|
-
crud.listen('createUserNew', function(data) {
|
|
38
|
-
document.dispatchEvent(new CustomEvent('createUserNew', {
|
|
39
|
-
detail: data
|
|
40
|
-
}));
|
|
41
|
-
});
|
|
42
37
|
crud.listen('fetchedUser', this.checkPermissions);
|
|
43
|
-
crud.listen('login', (instance) => self.
|
|
44
|
-
crud.listen('
|
|
38
|
+
crud.listen('login', (instance) => self.loginResponse(instance));
|
|
39
|
+
crud.listen('updateUserStatus', this.updateUserStatus);
|
|
45
40
|
crud.listen('usersCurrentOrg', (instance) => self.setCurrentOrg(instance));
|
|
46
41
|
},
|
|
47
42
|
|
|
48
|
-
|
|
43
|
+
loginRequest: function(btn) {
|
|
49
44
|
let form = btn.closest('form');
|
|
50
45
|
let collection = form.getAttribute('collection');
|
|
51
46
|
let loginData = {};
|
|
@@ -74,17 +69,17 @@ const CoCreateUser = {
|
|
|
74
69
|
});
|
|
75
70
|
},
|
|
76
71
|
|
|
77
|
-
|
|
72
|
+
loginResponse: function(data) {
|
|
78
73
|
let { success, status, message, token } = data;
|
|
79
74
|
|
|
80
75
|
if (success) {
|
|
81
76
|
window.localStorage.setItem('organization_id', window.config.organization_id);
|
|
82
77
|
window.localStorage.setItem("apiKey", window.config.apiKey);
|
|
83
78
|
window.localStorage.setItem("host", window.config.host);
|
|
84
|
-
window.localStorage.setItem('user_id', data['
|
|
79
|
+
window.localStorage.setItem('user_id', data['document_id']);
|
|
85
80
|
window.localStorage.setItem("token", token);
|
|
86
81
|
document.cookie = `token=${token};path=/`;
|
|
87
|
-
this.getCurrentOrg(data['
|
|
82
|
+
this.getCurrentOrg(data['document_id'], data['collection']);
|
|
88
83
|
message = "Succesful Login";
|
|
89
84
|
document.dispatchEvent(new CustomEvent('login', {
|
|
90
85
|
detail: {}
|
|
@@ -119,9 +114,6 @@ const CoCreateUser = {
|
|
|
119
114
|
window.localStorage.setItem('organization_id', data['current_org']);
|
|
120
115
|
window.localStorage.setItem('host', window.config.host);
|
|
121
116
|
|
|
122
|
-
// window.localStorage.setItem('adminUI_id', data['adminUI_id']);
|
|
123
|
-
// window.localStorage.setItem('builderUI_id', data['builderUI_id']);
|
|
124
|
-
|
|
125
117
|
document.dispatchEvent(new CustomEvent('logIn'));
|
|
126
118
|
},
|
|
127
119
|
|
|
@@ -232,7 +224,7 @@ const CoCreateUser = {
|
|
|
232
224
|
});
|
|
233
225
|
},
|
|
234
226
|
|
|
235
|
-
|
|
227
|
+
updateUserStatus: (data) => {
|
|
236
228
|
if (!data.user_id) {
|
|
237
229
|
return;
|
|
238
230
|
}
|
|
@@ -257,24 +249,6 @@ const CoCreateUser = {
|
|
|
257
249
|
}
|
|
258
250
|
},
|
|
259
251
|
|
|
260
|
-
createUserNew: function(btn) {
|
|
261
|
-
let form = btn.closest("form");
|
|
262
|
-
if (!form) return;
|
|
263
|
-
let newOrg_id = form.querySelector("input[collection='organizations'][name='_id']");
|
|
264
|
-
let user_id = form.querySelector("input[collection='users'][name='_id']");
|
|
265
|
-
|
|
266
|
-
const room = config.organization_id;
|
|
267
|
-
|
|
268
|
-
crud.send('createUserNew', {
|
|
269
|
-
apiKey: config.apiKey,
|
|
270
|
-
organization_id: config.organization_id,
|
|
271
|
-
collection: 'users',
|
|
272
|
-
newOrg_id: org_id,
|
|
273
|
-
user_id: user_id,
|
|
274
|
-
}, room);
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
|
|
278
252
|
createUser: function(btn) {
|
|
279
253
|
let form = btn.closest("form");
|
|
280
254
|
if (!form) return;
|
|
@@ -282,9 +256,11 @@ const CoCreateUser = {
|
|
|
282
256
|
let elements = form.querySelectorAll("[collection='users'][name]");
|
|
283
257
|
let orgIdElement = form.querySelector("input[collection='organizations'][name='_id']");
|
|
284
258
|
|
|
285
|
-
if (orgIdElement)
|
|
259
|
+
if (orgIdElement)
|
|
286
260
|
org_id = orgIdElement.value;
|
|
287
|
-
|
|
261
|
+
else
|
|
262
|
+
org_id = config.organization_id;
|
|
263
|
+
|
|
288
264
|
let data = {};
|
|
289
265
|
//. get form data
|
|
290
266
|
elements.forEach(el => {
|
|
@@ -314,14 +290,6 @@ const CoCreateUser = {
|
|
|
314
290
|
};
|
|
315
291
|
|
|
316
292
|
|
|
317
|
-
action.init({
|
|
318
|
-
name: "createUserNew",
|
|
319
|
-
endEvent: "createUserNew",
|
|
320
|
-
callback: (btn, data) => {
|
|
321
|
-
CoCreateUser.createUser(btn);
|
|
322
|
-
},
|
|
323
|
-
});
|
|
324
|
-
|
|
325
293
|
action.init({
|
|
326
294
|
name: "createUser",
|
|
327
295
|
endEvent: "createUser",
|
|
@@ -334,7 +302,7 @@ action.init({
|
|
|
334
302
|
name: "login",
|
|
335
303
|
endEvent: "login",
|
|
336
304
|
callback: (btn, data) => {
|
|
337
|
-
CoCreateUser.
|
|
305
|
+
CoCreateUser.loginRequest(btn, data);
|
|
338
306
|
},
|
|
339
307
|
});
|
|
340
308
|
|
package/src/server.js
CHANGED
|
@@ -9,47 +9,14 @@ class CoCreateUser {
|
|
|
9
9
|
|
|
10
10
|
init() {
|
|
11
11
|
if (this.wsManager) {
|
|
12
|
-
this.wsManager.on('
|
|
13
|
-
this.wsManager.on('createUser', (socket, data, socketInfo) => this.createUser(socket, data));
|
|
12
|
+
this.wsManager.on('createUser', (socket, data, socketInfo) => this.createUser(socket, data, socketInfo));
|
|
14
13
|
this.wsManager.on('login', (socket, data, socketInfo) => this.login(socket, data, socketInfo))
|
|
15
14
|
this.wsManager.on('usersCurrentOrg', (socket, data, socketInfo) => this.usersCurrentOrg(socket, data, socketInfo))
|
|
16
|
-
this.wsManager.on('
|
|
17
|
-
this.wsManager.on('userStatus', (socket, data, socketInfo) => this.setUserStatus(socket, data, socketInfo))
|
|
15
|
+
this.wsManager.on('userStatus', (socket, data, socketInfo) => this.userStatus(socket, data, socketInfo))
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
async createUserNew(socket, data) {
|
|
23
|
-
const self = this;
|
|
24
|
-
if(!data) return;
|
|
25
|
-
const newOrg_id = data.newOrg_id;
|
|
26
|
-
if (newOrg_id != data.organization_id) {
|
|
27
|
-
try{
|
|
28
|
-
const db = this.dbClient.db(req_data['organization_id']);
|
|
29
|
-
const collection = db.collection(req_data["collection"]);
|
|
30
|
-
const query = {
|
|
31
|
-
"_id": new ObjectId(data["user_id"])
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
collection.find(query).toArray(function(error, result) {
|
|
35
|
-
if(!error && result){
|
|
36
|
-
const newOrgDb = self.dbClient.db(newOrg_id).collection(data['collection']);
|
|
37
|
-
// Create new user in config db users collection
|
|
38
|
-
newOrgDb.insertOne({...result.ops[0], organization_id : newOrg_id}, function(error, result) {
|
|
39
|
-
if(!error && result){
|
|
40
|
-
const response = { ...data, document_id: result.ops[0]._id, data: result.ops[0]}
|
|
41
|
-
self.wsManager.send(socket, 'createUserNew', response, data['organization_id']);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}catch(error){
|
|
47
|
-
console.log('createDocument error', error);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async createUser(socket, data) {
|
|
19
|
+
async createUser(socket, data, socketInfo) {
|
|
53
20
|
const self = this;
|
|
54
21
|
if(!data.data) return;
|
|
55
22
|
|
|
@@ -59,15 +26,20 @@ class CoCreateUser {
|
|
|
59
26
|
collection.insertOne(data.data, function(error, result) {
|
|
60
27
|
if(!error && result){
|
|
61
28
|
const orgDB = data.orgDB;
|
|
29
|
+
data.data['_id'] = result.insertedId;
|
|
62
30
|
// if new orgDb Create new user in new org db users collection
|
|
63
|
-
if (orgDB != data.organization_id) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
anotherCollection.insertOne({...result.ops[0], organization_id : orgDB});
|
|
67
|
-
}
|
|
31
|
+
if (orgDB && orgDB != data.organization_id) {
|
|
32
|
+
const anotherCollection = self.dbClient.db(orgDB).collection(data['collection']);
|
|
33
|
+
anotherCollection.insertOne({...data.data, organization_id : orgDB});
|
|
68
34
|
}
|
|
69
|
-
const response = { ...data, document_id: result.
|
|
70
|
-
self.wsManager.send(socket, 'createUser', response,
|
|
35
|
+
const response = { ...data, document_id: `${result.insertedId}`}
|
|
36
|
+
self.wsManager.send(socket, 'createUser', response, socketInfo);
|
|
37
|
+
|
|
38
|
+
// add new user to platformDB
|
|
39
|
+
if (data.organization_id != process.env.organization_id) {
|
|
40
|
+
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
41
|
+
platformDB.insertOne({...data.data, organization_id: process.env.organization_id});
|
|
42
|
+
}
|
|
71
43
|
}
|
|
72
44
|
});
|
|
73
45
|
}catch(error){
|
|
@@ -82,55 +54,59 @@ class CoCreateUser {
|
|
|
82
54
|
collection: string,
|
|
83
55
|
loginData: object,
|
|
84
56
|
eId: string,
|
|
85
|
-
form_id: string,
|
|
86
57
|
|
|
87
58
|
apiKey: string,
|
|
88
59
|
organization_id: string
|
|
89
60
|
}
|
|
90
61
|
**/
|
|
91
|
-
async login(socket,
|
|
62
|
+
async login(socket, data, socketInfo) {
|
|
92
63
|
const self = this;
|
|
93
64
|
try {
|
|
94
|
-
const {organization_id} =
|
|
65
|
+
const {organization_id} = data
|
|
95
66
|
const selectedDB = organization_id;
|
|
96
|
-
const collection = self.dbClient.db(selectedDB).collection(
|
|
67
|
+
const collection = self.dbClient.db(selectedDB).collection(data["collection"]);
|
|
97
68
|
const query = new Object();
|
|
98
69
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
for (var key in req_data['loginData']) {
|
|
102
|
-
query[key] = req_data['loginData'][key];
|
|
70
|
+
for (var key in data['loginData']) {
|
|
71
|
+
query[key] = data['loginData'][key];
|
|
103
72
|
}
|
|
104
73
|
|
|
105
|
-
collection.
|
|
74
|
+
collection.findOneAndUpdate(query, {$set: {lastLogin: new Date()}}, async function(error, result) {
|
|
106
75
|
let response = {
|
|
107
|
-
eId: req_data['eId'],
|
|
108
|
-
uid: req_data['uid'],
|
|
109
|
-
form_id: req_data['form_id'],
|
|
110
76
|
success: false,
|
|
111
77
|
message: "Login failed",
|
|
112
|
-
status: "failed"
|
|
78
|
+
status: "failed",
|
|
79
|
+
uid: data['uid']
|
|
113
80
|
}
|
|
114
|
-
if (!error && result && result.
|
|
81
|
+
if (!error && result && result.value) {
|
|
115
82
|
let token = null;
|
|
116
83
|
if (self.wsManager.authInstance) {
|
|
117
|
-
token = await self.wsManager.authInstance.generateToken({user_id: result[
|
|
84
|
+
token = await self.wsManager.authInstance.generateToken({user_id: `${result.value['_id']}`});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (token && token != 'null')
|
|
88
|
+
response = { ...response,
|
|
89
|
+
success: true,
|
|
90
|
+
collection: data["collection"],
|
|
91
|
+
document_id: result.value['_id'],
|
|
92
|
+
current_org: result.value['current_org'],
|
|
93
|
+
message: "Login successful",
|
|
94
|
+
status: "success",
|
|
95
|
+
token
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
let user_id = response.document_id;
|
|
99
|
+
const query = {
|
|
100
|
+
"_id": new ObjectId(user_id),
|
|
118
101
|
}
|
|
119
102
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
document_id: result[0]['_id'],
|
|
125
|
-
current_org: result[0]['current_org'],
|
|
126
|
-
message: "Login successful",
|
|
127
|
-
status: "success",
|
|
128
|
-
token
|
|
129
|
-
};
|
|
103
|
+
if (data.organization_id != process.env.organization_id) {
|
|
104
|
+
const platformDB = self.dbClient.db(process.env.organization_id).collection(data['collection']);
|
|
105
|
+
platformDB.updateOne(query, {$set: {lastLogin: new Date()}})
|
|
106
|
+
}
|
|
130
107
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.log('success socket', req_data['organization_id']);
|
|
108
|
+
self.wsManager.send(socket, 'login', response, socketInfo)
|
|
109
|
+
console.log(`${response.message} user_id: ${result.value['_id']}`)
|
|
134
110
|
});
|
|
135
111
|
} catch (error) {
|
|
136
112
|
console.log('login failed', error);
|
|
@@ -145,16 +121,16 @@ class CoCreateUser {
|
|
|
145
121
|
href: string
|
|
146
122
|
}
|
|
147
123
|
**/
|
|
148
|
-
async usersCurrentOrg(socket,
|
|
124
|
+
async usersCurrentOrg(socket, data, socketInfo) {
|
|
149
125
|
try {
|
|
150
126
|
const self = this;
|
|
151
|
-
const {organization_id, db} =
|
|
127
|
+
const {organization_id, db} = data
|
|
152
128
|
const selectedDB = db || organization_id;
|
|
153
|
-
const collection = this.dbClient.db(selectedDB).collection(
|
|
129
|
+
const collection = this.dbClient.db(selectedDB).collection(data["collection"]);
|
|
154
130
|
|
|
155
131
|
let query = new Object();
|
|
156
132
|
|
|
157
|
-
query['_id'] = new ObjectId(
|
|
133
|
+
query['_id'] = new ObjectId(data['user_id']);
|
|
158
134
|
|
|
159
135
|
collection.find(query).toArray(function(error, result) {
|
|
160
136
|
|
|
@@ -167,22 +143,19 @@ class CoCreateUser {
|
|
|
167
143
|
orgCollection.find({"_id": new ObjectId(org_id),}).toArray(function(err, res) {
|
|
168
144
|
if (!err && res && res.length > 0) {
|
|
169
145
|
self.wsManager.send(socket, 'usersCurrentOrg', {
|
|
170
|
-
id: req_data['id'],
|
|
171
|
-
uid: req_data['uid'],
|
|
172
146
|
success: true,
|
|
173
147
|
user_id: result[0]['_id'],
|
|
174
148
|
current_org: result[0]['current_org'],
|
|
175
149
|
apiKey: res[0]['apiKey'],
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}, req_data['organization_id'])
|
|
150
|
+
href: data['href'],
|
|
151
|
+
uid: data['uid']
|
|
152
|
+
}, socketInfo)
|
|
180
153
|
}
|
|
181
154
|
});
|
|
155
|
+
|
|
182
156
|
}
|
|
183
157
|
} else {
|
|
184
158
|
// socket.emit('loginResult', {
|
|
185
|
-
// form_id: data['form_id'],
|
|
186
159
|
// success: false
|
|
187
160
|
// });
|
|
188
161
|
}
|
|
@@ -192,44 +165,13 @@ class CoCreateUser {
|
|
|
192
165
|
}
|
|
193
166
|
}
|
|
194
167
|
|
|
195
|
-
/**
|
|
196
|
-
data = {
|
|
197
|
-
namespace: string,
|
|
198
|
-
collection: string,
|
|
199
|
-
user_id: object,
|
|
200
|
-
|
|
201
|
-
apiKey: string,
|
|
202
|
-
organization_id: string
|
|
203
|
-
}
|
|
204
|
-
**/
|
|
205
|
-
async fetchUser(socket, req_data) {
|
|
206
|
-
const self = this;
|
|
207
|
-
|
|
208
|
-
try {
|
|
209
|
-
const {organization_id, db} = req_data
|
|
210
|
-
const selectedDB = db || organization_id;
|
|
211
|
-
const collection = self.dbClient.db(selectedDB).collection(req_data['collection']);
|
|
212
|
-
const user_id = req_data['user_id'];
|
|
213
|
-
const query = {
|
|
214
|
-
"_id": new ObjectId(user_id),
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
collection.findOne(query, function(error, result) {
|
|
218
|
-
if (!error) {
|
|
219
|
-
self.wsManager.send(socket, 'fetchedUser', result, req_data['organization_id']);
|
|
220
|
-
}
|
|
221
|
-
})
|
|
222
|
-
} catch (error) {
|
|
223
|
-
console.log('fetchUser error')
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
168
|
|
|
227
169
|
/**
|
|
228
170
|
* status: 'on/off/idle'
|
|
229
171
|
*/
|
|
230
|
-
async
|
|
172
|
+
async userStatus(socket, data, socketInfo) {
|
|
231
173
|
const self = this;
|
|
232
|
-
const {info, status} =
|
|
174
|
+
const {info, status} = data;
|
|
233
175
|
|
|
234
176
|
const items = info.split('/');
|
|
235
177
|
|
|
@@ -240,24 +182,26 @@ class CoCreateUser {
|
|
|
240
182
|
if (!items[1]) return;
|
|
241
183
|
|
|
242
184
|
try {
|
|
243
|
-
const {organization_id, db} =
|
|
185
|
+
const {organization_id, db} = data
|
|
244
186
|
const selectedDB = db || organization_id;
|
|
245
187
|
const collection = self.dbClient.db(selectedDB).collection('users');
|
|
246
188
|
const user_id = items[1];
|
|
247
189
|
const query = {
|
|
248
190
|
"_id": new ObjectId(user_id),
|
|
249
191
|
}
|
|
250
|
-
collection.
|
|
192
|
+
collection.updateOne(query, {$set: {status: status}}, function(err, res) {
|
|
251
193
|
if (!err) {
|
|
252
|
-
self.wsManager.broadcast(socket, '', null, '
|
|
194
|
+
self.wsManager.broadcast(socket, '', null, 'updateUserStatus',
|
|
253
195
|
{
|
|
254
196
|
user_id,
|
|
255
197
|
status
|
|
256
|
-
})
|
|
198
|
+
}, socketInfo)
|
|
257
199
|
}
|
|
200
|
+
else
|
|
201
|
+
console.log('err', err)
|
|
258
202
|
})
|
|
259
203
|
} catch (error) {
|
|
260
|
-
console.log('
|
|
204
|
+
console.log('userStatus error')
|
|
261
205
|
}
|
|
262
206
|
}
|
|
263
207
|
}
|
package/demo/index.html
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<title>Users | CoCreateJS</title>
|
|
5
|
-
|
|
6
|
-
<!-- CoCreate Favicon -->
|
|
7
|
-
<link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
|
|
8
|
-
<!-- CoCreate CSS CDN -->
|
|
9
|
-
<link rel="stylesheet" href="https://cdn.cocreate.app/action/latest/CoCreate-action.min.css" type="text/css" />
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
|
|
13
|
-
<script>
|
|
14
|
-
var config = {
|
|
15
|
-
apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
|
|
16
|
-
organization_id: '5de0387b12e200ea63204d6c',
|
|
17
|
-
host: 'ws.cocreate.app'
|
|
18
|
-
}
|
|
19
|
-
</script>
|
|
20
|
-
|
|
21
|
-
<!--<script src="../dist/CoCreate-users.js"></script>-->
|
|
22
|
-
<script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
|
|
23
|
-
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|