mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
simplify code
This commit is contained in:
@@ -20,7 +20,7 @@ let api = {};
|
|||||||
* @apiParam {String} password Password for the new user account
|
* @apiParam {String} password Password for the new user account
|
||||||
* @apiParam {String} passwordConfirmation Password confirmation
|
* @apiParam {String} passwordConfirmation Password confirmation
|
||||||
*
|
*
|
||||||
* @apiSuccess {Object} user The user profile
|
* @apiSuccess {Object} user The user object
|
||||||
*
|
*
|
||||||
* @apiUse NotAuthorized
|
* @apiUse NotAuthorized
|
||||||
*/
|
*/
|
||||||
@@ -66,23 +66,12 @@ api.registerLocal = {
|
|||||||
// So we can search for it in the database and then reject the choosen username if 1 or more results are found
|
// So we can search for it in the database and then reject the choosen username if 1 or more results are found
|
||||||
let lowerCaseUsername = username.toLowerCase();
|
let lowerCaseUsername = username.toLowerCase();
|
||||||
|
|
||||||
Q.all([
|
// Search for duplicates using lowercase version of username
|
||||||
// Search for duplicates using lowercase version of username
|
User.findOne({$or: [
|
||||||
User.findOne({$or: [
|
{'auth.local.email': email},
|
||||||
{'auth.local.email': email},
|
{'auth.local.lowerCaseUsername': lowerCaseUsername},
|
||||||
{'auth.local.lowerCaseUsername': lowerCaseUsername},
|
]}, {'auth.local': 1})
|
||||||
]}, {'auth.local': 1})
|
.exec()
|
||||||
.exec(),
|
|
||||||
|
|
||||||
// If the request is made by an authenticated Facebook user, find it
|
|
||||||
// TODO move to a separate route
|
|
||||||
// TODO automatically merge?
|
|
||||||
/* User.findOne({
|
|
||||||
_id: req.headers['x-api-user'],
|
|
||||||
apiToken: req.headers['x-api-key']
|
|
||||||
}, {auth:1})
|
|
||||||
.exec(); */
|
|
||||||
])
|
|
||||||
.then((results) => {
|
.then((results) => {
|
||||||
if (results[0]) {
|
if (results[0]) {
|
||||||
if (email === results[0].auth.local.email) return next(new NotAuthorized(res.t('emailTaken')));
|
if (email === results[0].auth.local.email) return next(new NotAuthorized(res.t('emailTaken')));
|
||||||
@@ -186,9 +175,7 @@ api.loginLocal = {
|
|||||||
|
|
||||||
if (!isValidPassword) return next(new NotAuthorized(res.t('invalidLoginCredentials')));
|
if (!isValidPassword) return next(new NotAuthorized(res.t('invalidLoginCredentials')));
|
||||||
|
|
||||||
res
|
res.status(200).json({id: user._id, apiToken: user.apiToken});
|
||||||
.status(200)
|
|
||||||
.json({id: user._id, apiToken: user.apiToken});
|
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user