@cocreate/users 1.7.29 → 1.8.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 +7 -0
- package/package.json +1 -1
- package/src/client.js +36 -12
- package/src/server.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.8.0](https://github.com/CoCreate-app/CoCreate-users/compare/v1.7.29...v1.8.0) (2022-09-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* login works offline ([cd6a36b](https://github.com/CoCreate-app/CoCreate-users/commit/cd6a36ba14b8dd8e7ecc28c48cedfb9d23880653))
|
|
7
|
+
|
|
1
8
|
## [1.7.29](https://github.com/CoCreate-app/CoCreate-users/compare/v1.7.28...v1.7.29) (2022-09-01)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/*globals CustomEvent, btoa*/
|
|
2
2
|
import crud from '@cocreate/crud-client';
|
|
3
|
-
// import input from '@cocreate/elements';
|
|
4
3
|
import action from '@cocreate/actions';
|
|
5
4
|
import render from '@cocreate/render';
|
|
6
5
|
|
|
@@ -43,9 +42,8 @@ const CoCreateUser = {
|
|
|
43
42
|
loginRequest: function(btn) {
|
|
44
43
|
let form = btn.closest('form');
|
|
45
44
|
let collection = form.getAttribute('collection');
|
|
46
|
-
let
|
|
45
|
+
let query = [];
|
|
47
46
|
|
|
48
|
-
// const inputs = form.querySelectorAll('input, textarea');
|
|
49
47
|
const inputs = form.querySelectorAll('input[name="email"], input[name="password"], input[name="username"]');
|
|
50
48
|
|
|
51
49
|
inputs.forEach((input) => {
|
|
@@ -56,17 +54,43 @@ const CoCreateUser = {
|
|
|
56
54
|
}
|
|
57
55
|
collection = input.getAttribute('collection') || collection;
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
loginData[name] = value;
|
|
61
|
-
}
|
|
57
|
+
query.push({name, value, operator: '$eq'})
|
|
62
58
|
});
|
|
63
59
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
60
|
+
let request = {
|
|
61
|
+
collection,
|
|
62
|
+
filter: {
|
|
63
|
+
query
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const socket = crud.socket.getSocket({})
|
|
68
|
+
if (!socket || !socket.connected || window && !window.navigator.onLine) {
|
|
69
|
+
|
|
70
|
+
crud.readDocuments(request).then((data) => {
|
|
71
|
+
data.data = data.data[0]
|
|
72
|
+
data.data['lastLogin'] = new Date().toISOString()
|
|
73
|
+
|
|
74
|
+
crud.updateDocument(data).then((response) => {
|
|
75
|
+
response['success'] = false
|
|
76
|
+
response['status'] = "Login failed"
|
|
77
|
+
if (response.data) {
|
|
78
|
+
response['success'] = true
|
|
79
|
+
response['status'] = "success"
|
|
80
|
+
this.loginResponse(response)
|
|
81
|
+
} else {
|
|
82
|
+
this.loginResponse(response)
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
} else {
|
|
87
|
+
crud.send('login', {
|
|
88
|
+
"apiKey": window.config.apiKey,
|
|
89
|
+
"organization_id": window.config.organization_id,
|
|
90
|
+
"collection": collection,
|
|
91
|
+
"loginData": query
|
|
92
|
+
});
|
|
93
|
+
}
|
|
70
94
|
},
|
|
71
95
|
|
|
72
96
|
loginResponse: function(data) {
|
package/src/server.js
CHANGED
|
@@ -67,8 +67,8 @@ class CoCreateUser {
|
|
|
67
67
|
const collection = self.dbClient.db(selectedDB).collection(data["collection"]);
|
|
68
68
|
const query = new Object();
|
|
69
69
|
|
|
70
|
-
for (
|
|
71
|
-
query[
|
|
70
|
+
for (let item of data['loginData']) {
|
|
71
|
+
query[item.name] = item.value;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
collection.findOneAndUpdate(query, {$set: {lastLogin: new Date()}}, async function(error, result) {
|