From a4d4dcfa9cd482a064271a7da3c42541931c392b Mon Sep 17 00:00:00 2001 From: Pig Fang Date: Mon, 8 Jul 2019 13:10:34 +0800 Subject: [PATCH] Optimize form validation --- resources/assets/src/components/Captcha.vue | 1 + resources/assets/src/views/auth/Forgot.vue | 17 +------ resources/assets/src/views/auth/Login.vue | 17 +------ resources/assets/src/views/auth/Register.vue | 45 ++++--------------- resources/assets/src/views/auth/Reset.vue | 18 +++----- .../assets/tests/views/auth/Forgot.test.ts | 10 ----- .../assets/tests/views/auth/Login.test.ts | 9 ---- .../assets/tests/views/auth/Register.test.ts | 33 -------------- .../assets/tests/views/auth/Reset.test.ts | 14 ------ resources/misc/changelogs/en/4.4.0.md | 1 + resources/misc/changelogs/zh_CN/4.4.0.md | 1 + 11 files changed, 21 insertions(+), 145 deletions(-) diff --git a/resources/assets/src/components/Captcha.vue b/resources/assets/src/components/Captcha.vue index 90fc6513..d3640a93 100644 --- a/resources/assets/src/components/Captcha.vue +++ b/resources/assets/src/components/Captcha.vue @@ -18,6 +18,7 @@ type="text" class="form-control" :placeholder="$t('auth.captcha')" + required > diff --git a/resources/assets/src/views/auth/Forgot.vue b/resources/assets/src/views/auth/Forgot.vue index 1316559b..759bbc4b 100644 --- a/resources/assets/src/views/auth/Forgot.vue +++ b/resources/assets/src/views/auth/Forgot.vue @@ -7,6 +7,7 @@ type="email" class="form-control" :placeholder="$t('auth.email')" + required > @@ -14,7 +15,6 @@
{{ successMsg }}
-
{{ infoMsg }}
{{ warningMsg }}
@@ -59,7 +59,6 @@ export default { data: () => ({ email: '', successMsg: '', - infoMsg: '', warningMsg: '', pending: false, }), @@ -67,30 +66,16 @@ export default { async submit() { const { email } = this - if (!email) { - this.infoMsg = this.$t('auth.emptyEmail') - this.$refs.email.focus() - return - } - - if (!/\S+@\S+\.\S+/.test(email)) { - this.infoMsg = this.$t('auth.invalidEmail') - this.$refs.email.focus() - return - } - this.pending = true const { code, message } = await this.$http.post( '/auth/forgot', { email, captcha: await this.$refs.captcha.execute() } ) if (code === 0) { - this.infoMsg = '' this.warningMsg = '' this.successMsg = message this.pending = false } else { - this.infoMsg = '' this.warningMsg = message this.pending = false this.$refs.captcha.refresh() diff --git a/resources/assets/src/views/auth/Login.vue b/resources/assets/src/views/auth/Login.vue index a2d88b09..cacd8524 100644 --- a/resources/assets/src/views/auth/Login.vue +++ b/resources/assets/src/views/auth/Login.vue @@ -6,6 +6,7 @@ v-model="identification" class="form-control" :placeholder="$t('auth.identification')" + required >
@@ -16,13 +17,13 @@ type="password" class="form-control" :placeholder="$t('auth.password')" + required >