mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-07-11 22:46:47 +00:00
Verify username as valid if user is re-checking their current name (#10737)
* Verify username as valid if user is re-checking their current name * Fix lint error and existingUser check.
This commit is contained in:
parent
8682cf1cf7
commit
52fbb8f899
1 changed files with 6 additions and 2 deletions
|
|
@ -73,6 +73,8 @@ api.verifyUsername = {
|
|||
method: 'POST',
|
||||
url: '/user/auth/verify-username',
|
||||
async handler (req, res) {
|
||||
const user = res.locals.user;
|
||||
|
||||
req.checkBody({
|
||||
username: {
|
||||
notEmpty: {errorMessage: res.t('missingUsername')},
|
||||
|
|
@ -84,8 +86,10 @@ api.verifyUsername = {
|
|||
|
||||
const issues = verifyUsername(req.body.username, res);
|
||||
|
||||
const count = await User.count({ 'auth.local.lowerCaseUsername': req.body.username.toLowerCase() });
|
||||
if (count > 0) issues.push(res.t('usernameTaken'));
|
||||
const existingUser = await User.findOne({ 'auth.local.lowerCaseUsername': req.body.username.toLowerCase() }, {auth: 1}).exec();
|
||||
if (existingUser && existingUser._id !== user._id) {
|
||||
issues.push(res.t('usernameTaken'));
|
||||
}
|
||||
|
||||
if (issues.length > 0) {
|
||||
res.respond(200, { isUsable: false, issues });
|
||||
|
|
|
|||
Loading…
Reference in a new issue