From 05e054f501be1a73d63788468a995f092d279e43 Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 28 Nov 2021 16:33:03 +0100 Subject: [PATCH] feat: improve input validation for register form --- src/helpers/isEmail.ts | 6 +++++ src/i18n/lang/en.json | 6 +++-- src/icons.js | 4 +++ src/views/user/Register.vue | 49 +++++++++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 src/helpers/isEmail.ts diff --git a/src/helpers/isEmail.ts b/src/helpers/isEmail.ts new file mode 100644 index 000000000..08957d0f0 --- /dev/null +++ b/src/helpers/isEmail.ts @@ -0,0 +1,6 @@ +export function isEmail(email: string): Boolean { + const format = /^.+@.+$/ + const match = email.match(format) + + return match === null ? false : match.length > 0 +} diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index 56a4bd113..2aeea991e 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -34,7 +34,6 @@ "email": "E-mail address", "emailPlaceholder": "e.g. frederic{'@'}vikunja.io", "password": "Password", - "passwordRepeat": "Retype your password", "passwordPlaceholder": "e.g. •••••••••••", "forgotPassword": "Forgot your password?", "resetPassword": "Reset your password", @@ -50,7 +49,10 @@ "authenticating": "Authenticating…", "openIdStateError": "State does not match, refusing to continue!", "openIdGeneralError": "An error occured while authenticating against the third party.", - "logout": "Logout" + "logout": "Logout", + "emailInvalid": "Please enter a valid email address.", + "usernameRequired": "Please provide a username.", + "passwordRequired": "Please provide a password." }, "settings": { "title": "Settings", diff --git a/src/icons.js b/src/icons.js index 48ef230c6..89e1d1a3e 100644 --- a/src/icons.js +++ b/src/icons.js @@ -16,6 +16,8 @@ import { faCocktail, faCoffee, faCog, + faEye, + faEyeSlash, faEllipsisH, faEllipsisV, faExclamation, @@ -87,6 +89,8 @@ library.add(faCocktail) library.add(faCoffee) library.add(faCog) library.add(faComments) +library.add(faEye) +library.add(faEyeSlash) library.add(faEllipsisH) library.add(faEllipsisV) library.add(faExclamation) diff --git a/src/views/user/Register.vue b/src/views/user/Register.vue index ef9f4a153..a3a74da74 100644 --- a/src/views/user/Register.vue +++ b/src/views/user/Register.vue @@ -18,8 +18,12 @@ v-focus v-model="credentials.username" @keyup.enter="submit" + @focusout="validateUsername" /> +

+ {{ $t('user.auth.usernameRequired') }} +

@@ -33,12 +37,16 @@ type="email" v-model="credentials.email" @keyup.enter="submit" + @focusout="validateEmail" />
+

+ {{ $t('user.auth.emailInvalid') }} +

-
+
+

+ {{ $t('user.auth.passwordRequired') }} +

@@ -76,6 +88,7 @@ id="register-submit" @click="submit" class="mr-2" + :disabled="!everythingValid" > {{ $t('user.auth.register') }} @@ -89,12 +102,14 @@