@cocreate/users 1.10.14 → 1.10.15

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 CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.10.15](https://github.com/CoCreate-app/CoCreate-users/compare/v1.10.14...v1.10.15) (2022-12-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies ([4730a5d](https://github.com/CoCreate-app/CoCreate-users/commit/4730a5d9261d08631547598a5c2125a7de6a8ce3))
7
+ * renamed createUser to signUp, login to signIn and logout to signOut ([9d2ee52](https://github.com/CoCreate-app/CoCreate-users/commit/9d2ee52e795556aef3f947ce97aa63d59173b23d))
8
+
1
9
  ## [1.10.14](https://github.com/CoCreate-app/CoCreate-users/compare/v1.10.13...v1.10.14) (2022-11-28)
2
10
 
3
11
 
@@ -1,14 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <title>Login | CoCreateJS</title>
4
+ <title>signIn | CoCreateJS</title>
5
5
 
6
6
  <link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
7
7
  <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
8
8
  </head>
9
9
 
10
10
  <body style='background-image: url("https://cdn.cocreate.app/background.png");'>
11
- <a href="./logout.html" session="true" hidden></a>
11
+ <a href="./signout.html" session="true" hidden></a>
12
12
 
13
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
14
 
@@ -34,7 +34,7 @@
34
34
  <input type="password" name='password' placeholder="Password" class="floating-label">
35
35
  </floating-label>
36
36
 
37
- <button actions="login" href="logout.html" class="outline">Login</button>
37
+ <button actions="signIn" href="signout.html" class="outline">Sign In</button>
38
38
 
39
39
  <a show='#forgotpass' hide='#signin'>Forgot Password</a>
40
40
  </div>
@@ -58,7 +58,7 @@
58
58
  <a>Send Email</a>
59
59
  </button>
60
60
 
61
- <a show='#signin' hide='#forgotpass'>login</a>
61
+ <a show='#signin' hide='#forgotpass'>Sign In</a>
62
62
  </div>
63
63
  </form>
64
64
 
@@ -66,7 +66,7 @@
66
66
  </div>
67
67
 
68
68
  <div class="position:fixed!important bottom:15px right:15px">
69
- <div template_id="login" class="template card margin:5px padding:10px {{status}}">
69
+ <div template_id="signIn" class="template card margin:5px padding:10px {{status}}">
70
70
  <span class="{{type}}">{{message}}</span><a actions="removeElement"> X</a>
71
71
  </div>
72
72
 
@@ -1,14 +1,14 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
3
  <head>
4
- <title>Logout | CoCreateJS</title>
4
+ <title>Sign Out | CoCreateJS</title>
5
5
 
6
6
  <link rel="icon" href="https://cdn.cocreate.app/favicon.ico" type="image/ico" sizes="16x16">
7
7
  <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
8
8
  </head>
9
9
 
10
10
  <body style='background-image: url("https://cdn.cocreate.app/background.png");'>
11
- <a href="./login.html" session="false" hidden></a>
11
+ <a href="./signin.html" session="false" hidden></a>
12
12
 
13
13
  <div class="justify-content:center align-items:center overflow:auto display:flex flex-wrap:wrap position:absolute width:100% height:100%">
14
14
  <div class="flex-grow:1 min-width:300px max-width:400px margin:15px">
@@ -21,7 +21,7 @@
21
21
  </div>
22
22
  </div>
23
23
  <div class="padding:25px background:gainsboro text-align:left">
24
- <button actions="logout" href="./login.html">Logout</button>
24
+ <button actions="signOut" href="./signin.html">Sign Out</button>
25
25
  </div>
26
26
  </div>
27
27
  </div>
package/demo/signup.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <meta charset="utf-8">
6
6
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
7
  <meta name="viewport" content="width=device-width, initial-scale=1">
8
- <title>Sign up | CoCreate</title>
8
+ <title>Sign Up | CoCreate</title>
9
9
  <link rel="icon" type="image/png" sizes="32x32" href="assets/favicon.ico">
10
10
  <link rel="stylesheet" href="../index.css" collection="files" document_id="60e4f9714792bff869f1bde5" name="src" type="text/css"/>
11
11
  </head>
@@ -75,7 +75,7 @@
75
75
  <small id="errorUconfirmpassword" class="text-danger"></small>
76
76
 
77
77
  <div class="display:flex">
78
- <button type="button" class="outline red-white startAnimation" actions="validate, createUser, login" href="logout.html">
78
+ <button type="button" class="outline red-white startAnimation" actions="validate, signUp, signIn" href="signout.html">
79
79
  Sign Up
80
80
  </button>
81
81
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/users",
3
- "version": "1.10.14",
3
+ "version": "1.10.15",
4
4
  "description": "A simple users component in vanilla javascript. Easily configured using HTML5 attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "users",
@@ -61,11 +61,11 @@
61
61
  "webpack-log": "^3.0.1"
62
62
  },
63
63
  "dependencies": {
64
- "@cocreate/actions": "^1.5.26",
65
- "@cocreate/crud-client": "^1.15.8",
66
- "@cocreate/docs": "^1.4.8",
67
- "@cocreate/element-prototype": "^1.1.13",
68
- "@cocreate/render": "^1.16.13",
64
+ "@cocreate/actions": "^1.5.27",
65
+ "@cocreate/crud-client": "^1.15.10",
66
+ "@cocreate/docs": "^1.4.10",
67
+ "@cocreate/element-prototype": "^1.1.15",
68
+ "@cocreate/render": "^1.16.14",
69
69
  "mongodb": "^4.4.0"
70
70
  }
71
71
  }
package/src/client.js CHANGED
@@ -16,18 +16,18 @@ const CoCreateUser = {
16
16
 
17
17
  initSocket: function() {
18
18
  const self = this;
19
- crud.listen('createUser', function(data) {
19
+ crud.listen('signUp', function(data) {
20
20
  self.setDocumentId('users', data.document[0]._id);
21
- document.dispatchEvent(new CustomEvent('createUser', {
21
+ document.dispatchEvent(new CustomEvent('signUp', {
22
22
  detail: data
23
23
  }));
24
24
  });
25
25
  crud.listen('fetchedUser', this.checkPermissions);
26
- crud.listen('login', (instance) => self.loginResponse(instance));
26
+ crud.listen('signIn', (instance) => self.signInResponse(instance));
27
27
  crud.listen('updateUserStatus', this.updateUserStatus);
28
28
  },
29
29
 
30
- loginRequest: function(btn) {
30
+ signInRequest: function(btn) {
31
31
  let form = btn.closest('form');
32
32
  let collection = form.getAttribute('collection');
33
33
  let query = [];
@@ -48,7 +48,7 @@ const CoCreateUser = {
48
48
  let request = {
49
49
  collection,
50
50
  document: {
51
- lastLogin: new Date().toISOString(),
51
+ lastSignIn: new Date().toISOString(),
52
52
  current_org: crud.socket.config.organization_id
53
53
  },
54
54
  filter: {
@@ -60,22 +60,23 @@ const CoCreateUser = {
60
60
  if (!socket[0] || !socket[0].connected || window && !window.navigator.onLine) {
61
61
  crud.updateDocument(request).then((response) => {
62
62
  response['success'] = false
63
- response['status'] = "Login failed"
63
+ response['status'] = "signIn failed"
64
64
  if (response.document) {
65
65
  response['success'] = true
66
66
  response['status'] = "success"
67
- this.loginResponse(response)
67
+ this.signInResponse(response)
68
68
  } else {
69
- this.loginResponse(response)
69
+ this.signInResponse(response)
70
70
  }
71
71
  })
72
72
  } else {
73
73
  // ToDo: can be depreciated if we have another means of token generation
74
- crud.socket.send('login', request);
74
+ request.broadcastBrowser = false
75
+ crud.socket.send('signIn', request);
75
76
  }
76
77
  },
77
78
 
78
- loginResponse: function(data) {
79
+ signInResponse: function(data) {
79
80
  let { success, status, message, token } = data;
80
81
 
81
82
  if (success) {
@@ -85,8 +86,8 @@ const CoCreateUser = {
85
86
  window.localStorage.setItem('user_id', data.document[0]['_id']);
86
87
  window.localStorage.setItem("token", token);
87
88
  document.cookie = `token=${token};path=/`;
88
- message = "Succesful Login";
89
- document.dispatchEvent(new CustomEvent('login', {
89
+ message = "Succesful signIn";
90
+ document.dispatchEvent(new CustomEvent('signIn', {
90
91
  detail: {}
91
92
  }));
92
93
  }
@@ -94,9 +95,9 @@ const CoCreateUser = {
94
95
  message = "The email or password you entered is incorrect";
95
96
 
96
97
  render.data({
97
- selector: "[template_id='login']",
98
+ selector: "[template_id='signIn']",
98
99
  data: {
99
- type: 'login',
100
+ type: 'signIn',
100
101
  status,
101
102
  message,
102
103
  success
@@ -104,7 +105,7 @@ const CoCreateUser = {
104
105
  });
105
106
  },
106
107
 
107
- logout: (btn) => {
108
+ signOut: (btn) => {
108
109
  self = this;
109
110
  window.localStorage.removeItem("user_id");
110
111
  window.localStorage.removeItem("token");
@@ -116,7 +117,7 @@ const CoCreateUser = {
116
117
  new Date(0).toUTCString();
117
118
 
118
119
  // Todo: replace with Custom event system
119
- document.dispatchEvent(new CustomEvent('logout'));
120
+ document.dispatchEvent(new CustomEvent('signOut'));
120
121
  },
121
122
 
122
123
  initChangeOrg: () => {
@@ -145,7 +146,7 @@ const CoCreateUser = {
145
146
  window.localStorage.setItem('organization_id', data.document[0]['current_org']);
146
147
  window.localStorage.setItem('host', crud.socket.config.host);
147
148
 
148
- document.dispatchEvent(new CustomEvent('logIn'));
149
+ document.dispatchEvent(new CustomEvent('signIn'));
149
150
  window.location.reload();
150
151
 
151
152
  })
@@ -244,7 +245,7 @@ const CoCreateUser = {
244
245
  }
245
246
  },
246
247
 
247
- createUser: function(btn) {
248
+ signUp: function(btn) {
248
249
  let form = btn.closest("form");
249
250
  if (!form) return;
250
251
  let org_id = "";
@@ -283,7 +284,7 @@ const CoCreateUser = {
283
284
  data.organization_id = org_id
284
285
  crud.createDocument(request).then((response) => {
285
286
 
286
- document.dispatchEvent(new CustomEvent('createUser', {
287
+ document.dispatchEvent(new CustomEvent('signUp', {
287
288
  detail: response
288
289
  }));
289
290
 
@@ -291,10 +292,11 @@ const CoCreateUser = {
291
292
  })
292
293
  } else {
293
294
  // ToDo: creates user in platformdb
294
- crud.socket.send('createUser', {
295
+ crud.socket.send('signUp', {
295
296
  collection: 'users',
296
297
  ...data,
297
- orgDB: org_id
298
+ orgDB: org_id,
299
+ broadcastBrowser: false
298
300
  });
299
301
  }
300
302
  },
@@ -302,26 +304,26 @@ const CoCreateUser = {
302
304
 
303
305
 
304
306
  action.init({
305
- name: "createUser",
306
- endEvent: "createUser",
307
+ name: "signUp",
308
+ endEvent: "signUp",
307
309
  callback: (btn, data) => {
308
- CoCreateUser.createUser(btn);
310
+ CoCreateUser.signUp(btn);
309
311
  },
310
312
  });
311
313
 
312
314
  action.init({
313
- name: "login",
314
- endEvent: "login",
315
+ name: "signIn",
316
+ endEvent: "signIn",
315
317
  callback: (btn, data) => {
316
- CoCreateUser.loginRequest(btn, data);
318
+ CoCreateUser.signInRequest(btn, data);
317
319
  },
318
320
  });
319
321
 
320
322
  action.init({
321
- name: "logout",
322
- endEvent: "logout",
323
+ name: "signOut",
324
+ endEvent: "signOut",
323
325
  callback: (btn, data) => {
324
- CoCreateUser.logout(btn, data);
326
+ CoCreateUser.signOut(btn, data);
325
327
  },
326
328
  });
327
329
 
package/src/server.js CHANGED
@@ -7,13 +7,13 @@ class CoCreateUser {
7
7
 
8
8
  init() {
9
9
  if (this.wsManager) {
10
- this.wsManager.on('createUser', (socket, data) => this.createUser(socket, data));
11
- this.wsManager.on('login', (socket, data) => this.login(socket, data))
10
+ this.wsManager.on('signUp', (socket, data) => this.signUp(socket, data));
11
+ this.wsManager.on('signIn', (socket, data) => this.signIn(socket, data))
12
12
  this.wsManager.on('userStatus', (socket, data) => this.userStatus(socket, data))
13
13
  }
14
14
  }
15
15
 
16
- async createUser(socket, data) {
16
+ async signUp(socket, data) {
17
17
  const self = this;
18
18
  if (!data.document) return;
19
19
 
@@ -29,7 +29,7 @@ class CoCreateUser {
29
29
  self.crud.createDocument(Data)
30
30
  }
31
31
 
32
- self.wsManager.send(socket, 'createUser', data);
32
+ self.wsManager.send(socket, 'signUp', data);
33
33
 
34
34
  // add new user to platformDB
35
35
  if (data.organization_id != process.env.organization_id) {
@@ -48,23 +48,22 @@ class CoCreateUser {
48
48
 
49
49
  /**
50
50
  data = {
51
- namespace: string,
51
+ namespace: string,
52
52
  collection: string,
53
- loginData: object,
54
- eId: string,
55
-
53
+ data: object,
54
+ eId: string,
56
55
  apiKey: string,
57
56
  organization_id: string
58
57
  }
59
58
  **/
60
- async login(socket, data) {
59
+ async signIn(socket, data) {
61
60
  const self = this;
62
61
  try {
63
62
  this.crud.updateDocument(data).then(async (data) => {
64
63
  let response = {
65
64
  ...data,
66
65
  success: false,
67
- message: "Login failed",
66
+ message: "signIn failed",
68
67
  status: "failed"
69
68
  }
70
69
 
@@ -77,7 +76,7 @@ class CoCreateUser {
77
76
  if (token && token != 'null')
78
77
  response = { ...response,
79
78
  success: true,
80
- message: "Login successful",
79
+ message: "signIn successful",
81
80
  status: "success",
82
81
  userStatus: 'on',
83
82
  token
@@ -87,18 +86,18 @@ class CoCreateUser {
87
86
  if (data.organization_id != process.env.organization_id) {
88
87
  let Data = {organization_id: process.env.organization_id}
89
88
  Data.document['_id'] = data.document[0]._id
90
- Data.document['lastLogin'] = data.document[0].lastLogin
89
+ Data.document['lastsignIn'] = data.document[0].lastsignIn
91
90
  Data.document['organization_id'] = process.env.organization_id
92
91
  crud.updateDocument(Data)
93
92
  }
94
93
 
95
94
  }
96
- self.wsManager.send(socket, 'login', response)
95
+ self.wsManager.send(socket, 'signIn', response)
97
96
  self.wsManager.broadcast(socket, 'updateUserStatus', data)
98
97
  })
99
98
 
100
99
  } catch (error) {
101
- console.log('login failed', error);
100
+ console.log('signIn failed', error);
102
101
  }
103
102
  }
104
103