From 8d01ba375ac4fdfc75e6c735e432e3ebb2f260c6 Mon Sep 17 00:00:00 2001 From: Andrea Vos Date: Tue, 13 Apr 2021 19:53:54 +0200 Subject: [PATCH] [user] username change - fix error message if too short --- components/Account.vue | 19 ++++++++++--------- server/routes/user.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/Account.vue b/components/Account.vue index 8028aec23..d48b32762 100644 --- a/components/Account.vue +++ b/components/Account.vue @@ -42,7 +42,7 @@

-
+

user.account.changeUsername.header

-
+

user.account.changeEmail.header

@@ -136,7 +136,8 @@ socialProviders, socialConnections: undefined, - saving: false, + savingUsername: false, + savingEmail: false, gravatar, } @@ -157,12 +158,12 @@ async changeUsername() { this.error = ''; - if (this.saving) { return; } - this.saving = true; + if (this.savingUsername) { return; } + this.savingUsername = true; const response = await this.$axios.$post(`/user/change-username`, { username: this.username, }); - this.saving = false; + this.savingUsername = false; if (response.error) { this.error = response.error; @@ -178,14 +179,14 @@ async changeEmail() { this.error = ''; - if (this.saving) { return; } - this.saving = true; + if (this.savingEmail) { return; } + this.savingEmail = true; const response = await this.$axios.$post(`/user/change-email`, { email: this.email, authId: this.changeEmailAuthId, code: this.code, }); - this.saving = false; + this.savingEmail = false; if (response.error) { this.error = response.error; diff --git a/server/routes/user.js b/server/routes/user.js index 07d5cdfdd..8d7c49b28 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -259,7 +259,7 @@ router.post('/user/change-username', async (req, res) => { } if (req.body.username.length < 4 || req.body.username.length > 16 || !req.body.username.match(new RegExp(`^[${USERNAME_CHARS}]+$`))) { - return { error: 'user.account.changeUsername.invalid' } + return res.json({ error: 'user.account.changeUsername.invalid' }); } const dbUser = await req.db.get(SQL`SELECT * FROM users WHERE lower(trim(replace(replace(replace(replace(replace(replace(replace(replace(replace(username, 'Ą', 'ą'), 'Ć', 'ć'), 'Ę', 'ę'), 'Ł', 'ł'), 'Ń', 'ń'), 'Ó', 'ó'), 'Ś', 'ś'), 'Ż', 'ż'), 'Ź', 'ż'))) = ${normalise(req.body.username)}`);