aboutsummaryrefslogtreecommitdiff
path: root/src/server/ApiManagers/UserManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/ApiManagers/UserManager.ts')
-rw-r--r--src/server/ApiManagers/UserManager.ts25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/server/ApiManagers/UserManager.ts b/src/server/ApiManagers/UserManager.ts
index 8b7994eac..0431b9bcf 100644
--- a/src/server/ApiManagers/UserManager.ts
+++ b/src/server/ApiManagers/UserManager.ts
@@ -7,6 +7,8 @@ import { Opt } from '../../fields/Doc';
import { WebSocket } from '../websocket';
import { resolvedPorts } from '../server_Initialization';
import { DashVersion } from '../../fields/DocSymbols';
+import { Utils } from '../../Utils';
+import { check, validationResult } from 'express-validator';
export const timeMap: { [id: string]: number } = {};
interface ActivityUnit {
@@ -32,7 +34,7 @@ export default class UserManager extends ApiManager {
secureHandler: async ({ user, req, res }) => {
const result: any = {};
user.cacheDocumentIds = req.body.cacheDocumentIds;
- user.save(err => {
+ user.save().then(undefined, err => {
if (err) {
result.error = [{ msg: 'Error while caching documents' }];
}
@@ -49,7 +51,7 @@ export default class UserManager extends ApiManager {
method: Method.GET,
subscription: '/getUserDocumentIds',
secureHandler: ({ res, user }) => res.send({ userDocumentId: user.userDocumentId, linkDatabaseId: user.linkDatabaseId, sharingDocumentId: user.sharingDocumentId }),
- publicHandler: ({ res }) => res.send({ userDocumentId: '__guest__', linkDatabaseId: 3, sharingDocumentId: 2 }),
+ publicHandler: ({ res }) => res.send({ userDocumentId: Utils.GuestID(), linkDatabaseId: 3, sharingDocumentId: 2 }),
});
register({
@@ -81,7 +83,7 @@ export default class UserManager extends ApiManager {
resolvedPorts,
})
),
- publicHandler: ({ res }) => res.send(JSON.stringify({ id: '__guest__', email: 'guest' })),
+ publicHandler: ({ res }) => res.send(JSON.stringify({ userDocumentId: Utils.GuestID(), email: 'guest', resolvedPorts })),
});
register({
@@ -107,15 +109,18 @@ export default class UserManager extends ApiManager {
return;
}
- req.assert('new_pass', 'Password must be at least 4 characters long').len({ min: 4 });
- req.assert('new_confirm', 'Passwords do not match').equals(new_pass);
+ check('new_pass', 'Password must be at least 4 characters long')
+ .run(req)
+ .then(chcekcres => console.log(chcekcres)); //.len({ min: 4 });
+ check('new_confirm', 'Passwords do not match')
+ .run(req)
+ .then(theres => console.log(theres)); //.equals(new_pass);
if (curr_pass === new_pass) {
result.error = [{ msg: 'Current and new password are the same' }];
}
- // was there error in validating new passwords?
- if (req.validationErrors()) {
- // was there error?
- result.error = req.validationErrors();
+ if (validationResult(req).array().length) {
+ // was there error in validating new passwords?
+ result.error = validationResult(req);
}
// will only change password if there are no errors.
@@ -125,7 +130,7 @@ export default class UserManager extends ApiManager {
user.passwordResetExpires = undefined;
}
- user.save(err => {
+ user.save().then(undefined, err => {
if (err) {
result.error = [{ msg: 'Error while saving new password' }];
}