Upstream sync
This commit is contained in:
@@ -9,21 +9,21 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
firstNameMaxLength = 50
|
||||
lastNameMaxLength = 50
|
||||
emailMaxLength = 150
|
||||
firstNameMaxLength = 50
|
||||
lastNameMaxLength = 50
|
||||
emailMaxLength = 150
|
||||
|
||||
memberNumberValidNumberOfLetters = 3
|
||||
memberNumberValidNumberOfLetters = 3
|
||||
)
|
||||
|
||||
const (
|
||||
formModeVisit = 1
|
||||
formModeRide = 2
|
||||
formModeVisit = 1
|
||||
formModeRide = 2
|
||||
)
|
||||
|
||||
func isAlphabetic(input string) bool {
|
||||
for _, character := range input {
|
||||
if !(characterIsUpperCase(character) || characterIsLowerCase(character)){
|
||||
if !(characterIsUpperCase(character) || characterIsLowerCase(character)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func isAlphabetic(input string) bool {
|
||||
|
||||
func isNumeric(input string) bool {
|
||||
for _, character := range input {
|
||||
if !characterIsNumber(character){
|
||||
if !characterIsNumber(character) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func isNumeric(input string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func isEmailValid (email string) bool {
|
||||
func isEmailValid(email string) bool {
|
||||
validEmailRegex := regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
|
||||
|
||||
return validEmailRegex.MatchString(email)
|
||||
@@ -55,7 +55,7 @@ func isMemberNumberValid(input string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !isNumeric(input[memberNumberValidNumberOfLetters:]){
|
||||
if !isNumeric(input[memberNumberValidNumberOfLetters:]) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -65,19 +65,19 @@ func isMemberNumberValid(input string) bool {
|
||||
func ValidateEligibility(user *viewmodel.User) []errors.ValidationError {
|
||||
var result []errors.ValidationError
|
||||
|
||||
formMode:= formModeVisit // This should be red from request, not hardcoded
|
||||
formMode := formModeVisit // This should be red from request, not hardcoded
|
||||
|
||||
//First name validation
|
||||
if len(user.First) < 1 {
|
||||
result = append(result, errors.ValidationError{Field: "first", Message: "First Name is required"})
|
||||
}
|
||||
|
||||
if !isAlphabetic(user.First){
|
||||
if !isAlphabetic(user.First) {
|
||||
result = append(result, errors.ValidationError{Field: "first", Message: "First Name contains non-alphabetic characters"})
|
||||
}
|
||||
|
||||
if len(user.First) > firstNameMaxLength {
|
||||
result = append(result, errors.ValidationError{Field: "first", Message: "First Name is too long"})
|
||||
result = append(result, errors.ValidationError{Field: "first", Message: "First Name is too long"})
|
||||
}
|
||||
|
||||
//Last name validation
|
||||
@@ -85,66 +85,66 @@ func ValidateEligibility(user *viewmodel.User) []errors.ValidationError {
|
||||
result = append(result, errors.ValidationError{Field: "last", Message: "Last Name is required"})
|
||||
}
|
||||
|
||||
if !isAlphabetic(user.Last){
|
||||
if !isAlphabetic(user.Last) {
|
||||
result = append(result, errors.ValidationError{Field: "last", Message: "Last Name contains non-alphabetic characters"})
|
||||
}
|
||||
|
||||
if len(user.Last) > lastNameMaxLength {
|
||||
result = append(result, errors.ValidationError{Field: "last", Message: "Last Name is too long"})
|
||||
result = append(result, errors.ValidationError{Field: "last", Message: "Last Name is too long"})
|
||||
}
|
||||
|
||||
//Email validation
|
||||
if user.Email != nil {
|
||||
if (formMode==formModeRide) && len(*user.Email) < 1 {
|
||||
if user.Email != nil && len(*user.Email) > 0 {
|
||||
if (formMode == formModeRide) && len(*user.Email) < 1 {
|
||||
result = append(result, errors.ValidationError{Field: "email", Message: "Email is required"})
|
||||
}
|
||||
|
||||
|
||||
if !isEmailValid(*user.Email) {
|
||||
result = append(result, errors.ValidationError{Field: "email", Message: "Email is invalid"})
|
||||
}
|
||||
|
||||
|
||||
if len(*user.Email) > emailMaxLength {
|
||||
result = append(result, errors.ValidationError{Field: "email", Message: "Email is too long"})
|
||||
}
|
||||
}else{
|
||||
if (formMode==formModeRide){
|
||||
} else {
|
||||
if formMode == formModeRide {
|
||||
result = append(result, errors.ValidationError{Field: "email", Message: "Email is required"})
|
||||
}
|
||||
}
|
||||
|
||||
//Gender validation
|
||||
if ((user.Gender != nil) && len(*user.Gender) < 1) || (user.Gender == nil) {
|
||||
result = append(result, errors.ValidationError{Field: "gender", Message: "Member Gender is required"})
|
||||
result = append(result, errors.ValidationError{Field: "gender", Message: "Member Gender is required"})
|
||||
}
|
||||
|
||||
//Member type validation
|
||||
if (user.Type != nil && len(*user.Type) < 1) || (user.Type == nil) {
|
||||
result = append(result, errors.ValidationError{Field: "type", Message: "Member Type is required"})
|
||||
result = append(result, errors.ValidationError{Field: "type", Message: "Member Type is required"})
|
||||
}
|
||||
|
||||
//Member# validation
|
||||
if !isMemberNumberValid(*user.Member){
|
||||
result = append(result, errors.ValidationError{Field: "member", Message: "Member# is invalid"})
|
||||
if !isMemberNumberValid(*user.Member) {
|
||||
result = append(result, errors.ValidationError{Field: "member", Message: "Member# is invalid"})
|
||||
}
|
||||
//Birthdate validation
|
||||
if user.BirthDate == nil {
|
||||
result = append(result, errors.ValidationError{Field: "birthdate", Message: "Choose a Birth Date"})
|
||||
}else{
|
||||
yesterday := time.Now().Add(-1*time.Hour*hoursInDay)
|
||||
result = append(result, errors.ValidationError{Field: "birthdate", Message: "Choose a Birth Date"})
|
||||
} else {
|
||||
yesterday := time.Now().Add(-1 * time.Hour * hoursInDay)
|
||||
if user.BirthDate.After(yesterday) {
|
||||
result = append(result, errors.ValidationError{Field: "birthdate", Message: "Choose a valid Birth Date"})
|
||||
result = append(result, errors.ValidationError{Field: "birthdate", Message: "Choose a valid Birth Date"})
|
||||
}
|
||||
}
|
||||
//Mobile validation
|
||||
if formMode == formModeRide {
|
||||
if (user.PhoneNumber != nil && len(*user.PhoneNumber) < 1) || (user.PhoneNumber == nil) {
|
||||
result = append(result, errors.ValidationError{Field: "phonenumber", Message: "Phone number is required"})
|
||||
result = append(result, errors.ValidationError{Field: "phonenumber", Message: "Phone number is required"})
|
||||
}
|
||||
}
|
||||
//User consent validation
|
||||
if !user.Consent{
|
||||
result = append(result, errors.ValidationError{Field: "consent", Message: "Must be 'Checked'"})
|
||||
if !user.Consent {
|
||||
result = append(result, errors.ValidationError{Field: "consent", Message: "Must be 'Checked'"})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user