fix(comments): validator for emails, remove prefixes, allow length 1

This commit is contained in:
Sabe Jones 2018-10-26 16:25:15 -05:00
parent 8b81e38538
commit 5299c8d406
5 changed files with 19 additions and 34 deletions

View file

@ -82,6 +82,7 @@
import hello from 'hellojs';
import { setUpAxios } from 'client/libs/auth';
import debounce from 'lodash/debounce';
import validator from 'validator';
import facebookSquareIcon from 'assets/svg/facebook-square.svg';
import googleIcon from 'assets/svg/google.svg';
@ -115,13 +116,13 @@ export default {
computed: {
emailValid () {
if (this.email.length <= 3) return false;
return this.validateEmail(this.email);
return validator.isEmail(this.email);
},
emailInvalid () {
return !this.emailValid;
},
usernameValid () {
if (this.username.length <= 3) return false;
if (this.username.length < 1) return false;
return this.usernameIssues.length === 0;
},
usernameInvalid () {
@ -143,7 +144,7 @@ export default {
methods: {
// eslint-disable-next-line func-names
validateUsername: debounce(function (username) {
if (username.length <= 3) {
if (username.length < 1) {
return;
}
this.$store.dispatch('auth:verifyUsername', {
@ -156,10 +157,6 @@ export default {
}
});
}, 500),
validateEmail (email) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},
// @TODO: Abstract hello in to action or lib
async socialAuth (network) {
try {

View file

@ -295,6 +295,7 @@
import axios from 'axios';
import hello from 'hellojs';
import debounce from 'lodash/debounce';
import validator from 'validator';
import gryphon from 'assets/svg/gryphon.svg';
import habiticaIcon from 'assets/svg/habitica-logo.svg';
@ -340,18 +341,18 @@ export default {
},
emailValid () {
if (this.email.length <= 3) return false;
return this.validateEmail(this.email);
return validator.isEmail(this.email);
},
emailInvalid () {
if (this.email.length <= 3) return false;
return !this.emailValid;
},
usernameValid () {
if (this.username.length <= 3) return false;
if (this.username.length < 1) return false;
return this.usernameIssues.length === 0;
},
usernameInvalid () {
if (this.username.length <= 3) return false;
if (this.username.length < 1) return false;
return !this.usernameValid;
},
passwordConfirmValid () {
@ -415,10 +416,6 @@ export default {
}
});
}, 500),
validateEmail (email) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},
async register () {
// @TODO do not use alert
if (!this.email) {

View file

@ -54,9 +54,6 @@
padding-right: 2rem;
}
.modal-dialog {
-webkit-transform: translate(-5%, calc(50vh - 60%));
-ms-transform: translate(0, 50vh) translate(-5%, -60%);
-o-transform: translate(-5%, calc(50vh - 60%));
transform: translate(0, 50vh) translate(-5%, -60%);
}
}
@ -162,23 +159,23 @@
user: 'user.data',
}),
displayNameInvalid () {
if (this.temporaryDisplayName.length <= 1) return false;
if (this.temporaryDisplayName.length < 1) return false;
return !this.displayNameValid;
},
displayNameValid () {
if (this.temporaryDisplayName.length <= 1) return false;
if (this.temporaryDisplayName.length < 1) return false;
return this.displayNameIssues.length === 0;
},
usernameCannotSubmit () {
if (this.temporaryUsername.length <= 1) return true;
if (this.temporaryUsername.length < 1) return true;
return !this.usernameValid || !this.displayNameValid;
},
usernameInvalid () {
if (this.temporaryUsername.length <= 1) return false;
if (this.temporaryUsername.length < 1) return false;
return !this.usernameValid;
},
usernameValid () {
if (this.temporaryUsername.length <= 1) return false;
if (this.temporaryUsername.length < 1) return false;
return this.usernameIssues.length === 0;
},
},

View file

@ -560,6 +560,7 @@
<script>
import hello from 'hellojs';
import debounce from 'lodash/debounce';
import validator from 'validator';
import googlePlay from 'assets/images/home/google-play-badge.svg';
import iosAppStore from 'assets/images/home/ios-app-store.svg';
import iphones from 'assets/images/home/iphones.svg';
@ -626,18 +627,18 @@
computed: {
emailValid () {
if (this.email.length <= 3) return false;
return this.validateEmail(this.email);
return validator.isEmail(this.email);
},
emailInvalid () {
if (this.email.length <= 3) return false;
return !this.validateEmail(this.email);
return !validator.isEmail(this.email);
},
usernameValid () {
if (this.username.length <= 3) return false;
if (this.username.length < 1) return false;
return this.usernameIssues.length === 0;
},
usernameInvalid () {
if (this.username.length <= 3) return false;
if (this.username.length < 1) return false;
return !this.usernameValid;
},
passwordConfirmValid () {
@ -655,13 +656,9 @@
},
},
methods: {
validateEmail (email) {
let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},
// eslint-disable-next-line func-names
validateUsername: debounce(function (username) {
if (username.length <= 3) {
if (username.length < 1) {
return;
}
this.$store.dispatch('auth:verifyUsername', {

View file

@ -25,9 +25,6 @@
<style lang="scss">
#yesterdaily___BV_modal_outer_ {
.modal-dialog {
-webkit-transform: translate(-5%, calc(50vh - 60%));
-ms-transform: translate(0, 50vh) translate(-5%, -60%);
-o-transform: translate(-5%, calc(50vh - 60%));
transform: translate(0, 50vh) translate(-5%, -60%);
}
}