@@ -83,7 +83,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
}
|
||||
return req.config.database
|
||||
.find('_User', query)
|
||||
.then((results) => {
|
||||
.then(results => {
|
||||
if (!results.length) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OBJECT_NOT_FOUND,
|
||||
@@ -96,14 +96,14 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.config.loggerController.warn(
|
||||
"There is a user which email is the same as another user's username, logging in based on username"
|
||||
);
|
||||
user = results.filter((user) => user.username === username)[0];
|
||||
user = results.filter(user => user.username === username)[0];
|
||||
} else {
|
||||
user = results[0];
|
||||
}
|
||||
|
||||
return passwordCrypto.compare(password, user.password);
|
||||
})
|
||||
.then((correct) => {
|
||||
.then(correct => {
|
||||
isValidPassword = correct;
|
||||
const accountLockoutPolicy = new AccountLockout(user, req.config);
|
||||
return accountLockoutPolicy.handleLoginAttempt(isValidPassword);
|
||||
@@ -145,7 +145,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
// Sometimes the authData still has null on that keys
|
||||
// https://github.com/parse-community/parse-server/issues/935
|
||||
if (user.authData) {
|
||||
Object.keys(user.authData).forEach((provider) => {
|
||||
Object.keys(user.authData).forEach(provider => {
|
||||
if (user.authData[provider] === null) {
|
||||
delete user.authData[provider];
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
return resolve(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
return reject(error);
|
||||
});
|
||||
});
|
||||
@@ -181,7 +181,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (
|
||||
!response.results ||
|
||||
response.results.length == 0 ||
|
||||
@@ -282,13 +282,13 @@ export class UsersRouter extends ClassesRouter {
|
||||
|
||||
handleVerifyPassword(req) {
|
||||
return this._authenticateUserFromRequest(req)
|
||||
.then((user) => {
|
||||
.then(user => {
|
||||
// Remove hidden properties.
|
||||
UsersRouter.removeHiddenProperties(user);
|
||||
|
||||
return { response: user };
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
@@ -306,7 +306,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
req.info.clientSDK,
|
||||
req.info.context
|
||||
)
|
||||
.then((records) => {
|
||||
.then(records => {
|
||||
if (records.results && records.results.length) {
|
||||
return rest
|
||||
.del(
|
||||
@@ -383,7 +383,7 @@ export class UsersRouter extends ClassesRouter {
|
||||
response: {},
|
||||
});
|
||||
},
|
||||
(err) => {
|
||||
err => {
|
||||
if (err.code === Parse.Error.OBJECT_NOT_FOUND) {
|
||||
// Return success so that this endpoint can't
|
||||
// be used to enumerate valid emails
|
||||
@@ -414,70 +414,68 @@ export class UsersRouter extends ClassesRouter {
|
||||
);
|
||||
}
|
||||
|
||||
return req.config.database
|
||||
.find('_User', { email: email })
|
||||
.then((results) => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
`No user found with email ${email}`
|
||||
);
|
||||
}
|
||||
const user = results[0];
|
||||
return req.config.database.find('_User', { email: email }).then(results => {
|
||||
if (!results.length || results.length < 1) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.EMAIL_NOT_FOUND,
|
||||
`No user found with email ${email}`
|
||||
);
|
||||
}
|
||||
const user = results[0];
|
||||
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
// remove password field, messes with saving on postgres
|
||||
delete user.password;
|
||||
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OTHER_CAUSE,
|
||||
`Email ${email} is already verified.`
|
||||
);
|
||||
}
|
||||
if (user.emailVerified) {
|
||||
throw new Parse.Error(
|
||||
Parse.Error.OTHER_CAUSE,
|
||||
`Email ${email} is already verified.`
|
||||
);
|
||||
}
|
||||
|
||||
const userController = req.config.userController;
|
||||
return userController.regenerateEmailVerifyToken(user).then(() => {
|
||||
userController.sendVerificationEmail(user);
|
||||
return { response: {} };
|
||||
});
|
||||
const userController = req.config.userController;
|
||||
return userController.regenerateEmailVerifyToken(user).then(() => {
|
||||
userController.sendVerificationEmail(user);
|
||||
return { response: {} };
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
mountRoutes() {
|
||||
this.route('GET', '/users', (req) => {
|
||||
this.route('GET', '/users', req => {
|
||||
return this.handleFind(req);
|
||||
});
|
||||
this.route('POST', '/users', (req) => {
|
||||
this.route('POST', '/users', req => {
|
||||
return this.handleCreate(req);
|
||||
});
|
||||
this.route('GET', '/users/me', (req) => {
|
||||
this.route('GET', '/users/me', req => {
|
||||
return this.handleMe(req);
|
||||
});
|
||||
this.route('GET', '/users/:objectId', (req) => {
|
||||
this.route('GET', '/users/:objectId', req => {
|
||||
return this.handleGet(req);
|
||||
});
|
||||
this.route('PUT', '/users/:objectId', (req) => {
|
||||
this.route('PUT', '/users/:objectId', req => {
|
||||
return this.handleUpdate(req);
|
||||
});
|
||||
this.route('DELETE', '/users/:objectId', (req) => {
|
||||
this.route('DELETE', '/users/:objectId', req => {
|
||||
return this.handleDelete(req);
|
||||
});
|
||||
this.route('GET', '/login', (req) => {
|
||||
this.route('GET', '/login', req => {
|
||||
return this.handleLogIn(req);
|
||||
});
|
||||
this.route('POST', '/login', (req) => {
|
||||
this.route('POST', '/login', req => {
|
||||
return this.handleLogIn(req);
|
||||
});
|
||||
this.route('POST', '/logout', (req) => {
|
||||
this.route('POST', '/logout', req => {
|
||||
return this.handleLogOut(req);
|
||||
});
|
||||
this.route('POST', '/requestPasswordReset', (req) => {
|
||||
this.route('POST', '/requestPasswordReset', req => {
|
||||
return this.handleResetRequest(req);
|
||||
});
|
||||
this.route('POST', '/verificationEmailRequest', (req) => {
|
||||
this.route('POST', '/verificationEmailRequest', req => {
|
||||
return this.handleVerificationEmailRequest(req);
|
||||
});
|
||||
this.route('GET', '/verifyPassword', (req) => {
|
||||
this.route('GET', '/verifyPassword', req => {
|
||||
return this.handleVerifyPassword(req);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user