[V3-911] fixed registration mandatory fields validation (#937)

This commit is contained in:
Nikolay Yurchenko 2018-12-27 14:05:38 +02:00 committed by GitHub
parent 4346cd060f
commit 472341da23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 18 deletions

View File

@ -5,7 +5,6 @@ declare type RegisterData = {
firstName: string,
firstNameError: string,
lastName: string,
lastNameError: string,
email: string,
emailError: string,
password: string,

View File

@ -1,8 +1,14 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
export function validateEmail(email: string) : boolean {
export function validateEmail(email: string): boolean {
const rgx = /.*@.*\..*$/;
return rgx.test(email);
}
export function validatePassword(password: string): boolean {
const rgx = /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]+){6,}$/;
return rgx.test(password);
}

View File

@ -28,7 +28,6 @@
class="full-input"
label="Last Name"
placeholder="Enter Last Name"
:error="lastNameError"
@setData="setLastName">
</HeaderedInput>
<HeaderedInput
@ -78,7 +77,7 @@ import { Component, Vue } from 'vue-property-decorator';
import HeaderedInput from '@/components/common/HeaderedInput.vue';
import Checkbox from '@/components/common/Checkbox.vue';
import Button from '@/components/common/Button.vue';
import { validateEmail } from '@/utils/validation';
import { validateEmail, validatePassword } from '@/utils/validation';
import ROUTES from '../utils/constants/routerConstants';
import { createUserRequest } from '@/api/users';
@ -95,7 +94,6 @@ import { createUserRequest } from '@/api/users';
},
setLastName: function (value: string) {
this.$data.lastName = value;
this.$data.lastNameError = '';
},
setPassword: function (value: string) {
this.$data.password = value;
@ -111,23 +109,21 @@ import { createUserRequest } from '@/api/users';
},
onCreateClick: async function () {
let hasError = false;
const firstName = this.$data.firstName.trim();
const email = this.$data.email.trim();
const lastName = this.$data.lastName.trim();
if (!this.$data.firstName) {
if (!firstName) {
this.$data.firstNameError = 'Invalid First Name';
hasError = true;
}
if (!this.$data.lastName) {
this.$data.lastNameError = 'Invalid Last Name';
hasError = true;
}
if (!this.$data.email || !validateEmail(this.$data.email)) {
if (!validateEmail(email)) {
this.$data.emailError = 'Invalid Email';
hasError = true;
}
if (!this.$data.password) {
if (!validatePassword(this.$data.password)) {
this.$data.passwordError = 'Invalid Password';
hasError = true;
}
@ -145,10 +141,9 @@ import { createUserRequest } from '@/api/users';
if (hasError) return;
let user = {
id: '',
email: this.$data.email,
firstName: this.$data.firstName,
lastName: this.$data.lastName,
email,
firstName,
lastName,
};
let response = await createUserRequest(user, this.$data.password);
@ -167,7 +162,6 @@ import { createUserRequest } from '@/api/users';
firstName: '',
firstNameError: '',
lastName: '',
lastNameError: '',
email: '',
emailError: '',
password: '',