Compare commits

1 Commits

Author SHA1 Message Date
GotPPay
88d46b51f6 Change error messages according to instructions document 2018-05-28 10:47:18 +02:00
6 changed files with 149 additions and 309 deletions

View File

@@ -550,56 +550,6 @@ func (s *notificationService) ReadStatus(notificationUUID string, isRead bool) e
return s.svc.Notification.ReadStatus(notificationUUID, isRead) return s.svc.Notification.ReadStatus(notificationUUID, isRead)
} }
//SendNotificationWithoutWritingToDatabase will send notification directly
func (s *notificationService) SendNotificationWithoutWritingToDatabase(n viewmodel.Notification) (viewmodel.Notification, error) {
switch n.Type {
case NOtificationTypeSMS:
if n.From == "" {
if err := s.notification.Twilio.SendSMS(s.cfg.Twilio.Sender, n.To, n.Message); err != nil {
fmt.Println("Error to send SMS: ", err.Error())
return viewmodel.Notification{}, err
}
if err := s.notification.Twilio.SendSMS(s.cfg.Twilio.Sender, "+17083038497", n.Message); err != nil {
fmt.Println("Error to send SMS: ", err.Error())
return viewmodel.Notification{}, err
}
} else {
if err := s.notification.Twilio.SendSMS(n.From, n.To, n.Message); err != nil {
fmt.Println("Error to send SMS: ", err.Error())
return viewmodel.Notification{}, err
}
if err := s.notification.Twilio.SendSMS(n.From, "+17083038497", n.Message); err != nil {
fmt.Println("Error to send SMS: ", err.Error())
return viewmodel.Notification{}, err
}
}
case NotificationTypeEmail:
m := gomail.NewMessage()
m.SetHeader("From", s.cfg.Email.Sender)
m.SetHeader("To", n.To)
m.SetHeader("Subject", n.Subject)
m.SetBody("text/plain", n.Message)
d := gomail.NewDialer(s.cfg.Email.Server, s.cfg.Email.Port, s.cfg.Email.User, s.cfg.Email.Pass)
if err := d.DialAndSend(m); err != nil {
fmt.Println("Error to send Email: ", err.Error())
return viewmodel.Notification{}, err
}
m = gomail.NewMessage()
m.SetHeader("From", s.cfg.Email.Sender)
m.SetHeader("To", "nemt@brighterdevelopment.com")
m.SetHeader("Subject", n.Subject)
m.SetBody("text/plain", n.Message)
if err := d.DialAndSend(m); err != nil {
fmt.Println("Error to send Email: ", err.Error())
return viewmodel.Notification{}, err
}
}
return n, nil
}
// SendNotifications will send all the notifications to email or SMS // SendNotifications will send all the notifications to email or SMS
func (s *notificationService) SendNotifications(notifications []viewmodel.Notification) ([]viewmodel.Notification, error) { func (s *notificationService) SendNotifications(notifications []viewmodel.Notification) ([]viewmodel.Notification, error) {
if len(notifications) > 0 { if len(notifications) > 0 {

View File

@@ -113,10 +113,3 @@ p, BCBSIAD, *, bcbsi, *, *, *, /v1/nemt/eligibility, POST
p, BDCAD, *, techsupport, *, *, *, /v1/nemt/eligibility, POST p, BDCAD, *, techsupport, *, *, *, /v1/nemt/eligibility, POST
p, PLANAD, *, plan, *, *, *, /v1/nemt/eligibility, POST p, PLANAD, *, plan, *, *, *, /v1/nemt/eligibility, POST
p, AD, *, *, *, *, *, /v1/nemt/eligibility, POST p, AD, *, *, *, *, *, /v1/nemt/eligibility, POST
p, VIRPT, *, *, *, *, *, /v1/nemt/users/member, POST
p, VIRPT, *, *, *, *, *, /v1/nemt/users/member, GET
p, VIRPT, *, *, *, *, *, /v1/nemt/eligibility, POST
p, VIRPT, *, *, *, *, *, /v1/nemt/visits, POST
p, VIRPT, *, *, *, *, *, /v1/nemt/rides/eta, GET
p, VIRPT, *, *, *, *, *, /v1/nemt/provider, GET
p, VIRPT, *, *, *, *, *, /v1/selfregister, POST
1 p AD * * * * * * *
113 p BDCAD * techsupport * * * /v1/nemt/eligibility POST
114 p PLANAD * plan * * * /v1/nemt/eligibility POST
115 p AD * * * * * /v1/nemt/eligibility POST
p VIRPT * * * * * /v1/nemt/users/member POST
p VIRPT * * * * * /v1/nemt/users/member GET
p VIRPT * * * * * /v1/nemt/eligibility POST
p VIRPT * * * * * /v1/nemt/visits POST
p VIRPT * * * * * /v1/nemt/rides/eta GET
p VIRPT * * * * * /v1/nemt/provider GET
p VIRPT * * * * * /v1/selfregister POST

View File

@@ -16,11 +16,6 @@ import (
"github.com/labstack/echo" "github.com/labstack/echo"
) )
const (
notificationEmailSubject = "Registration sucessful"
notificationEmailBody = "You have registered as a Visit Reporter for CHM NEMT.\nLogin: https://portal.bcbsinstitute.com\nReset PW: https://portal.bcbsinstitute.com/forgot"
)
var ( var (
instance *controller instance *controller
once sync.Once once sync.Once
@@ -54,20 +49,44 @@ func (c *controller) handle(ctx echo.Context) error {
return routeutils.HandleAPIError(ctx, err) return routeutils.HandleAPIError(ctx, err)
} }
if user.PhoneNumber == nil || len(*user.PhoneNumber) == 0 {
return routeutils.ResponseAPIValidationError(ctx, "phonenumber is required")
}
if user.Email == nil || len(*user.Email) == 0 {
return routeutils.ResponseAPIValidationError(ctx, "email is required")
}
if len(user.Pass) == 0 {
return routeutils.ResponseAPIValidationError(ctx, "password is required")
}
pass, err := b64.StdEncoding.DecodeString(user.Pass) pass, err := b64.StdEncoding.DecodeString(user.Pass)
if err != nil { if err != nil {
return routeutils.ResponseAPIValidationError(ctx, "Invalid password") return routeutils.ResponseAPIValidationError(ctx, "Invalid password")
} }
user.Pass = string(pass) user.Pass = string(pass)
if validationErrors := validation.ValidateSelfregistration(&user); len(validationErrors) > 0 { if passwordValidationErrors := validation.ValidatePassword(&user); len(passwordValidationErrors) > 0 {
return routeutils.ResponseAPICustomValidationError(ctx, "Self registration failed", validationErrors) return routeutils.ResponseAPICustomValidationError(ctx, "Password not strong enough", passwordValidationErrors)
}
if len(user.Name) == 0 && len(user.First) == 0 && len(user.Last) == 0 {
return routeutils.ResponseAPIValidationError(ctx, "name is required")
} }
if len(user.First) != 0 && len(user.Last) != 0 { if len(user.First) != 0 && len(user.Last) != 0 {
user.Name = fmt.Sprintf("%s %s", user.First, user.Last) user.Name = fmt.Sprintf("%s %s", user.First, user.Last)
} }
if len(user.Provider.InternalID) == 0 || len(user.Provider.InternalID) > 10 {
return routeutils.ResponseAPIValidationError(ctx, "Provider NPI is invalid")
}
if len(user.Provider.OrganizatioName) == 0 {
return routeutils.ResponseAPIValidationError(ctx, "Provider Organization Name is invalid")
}
provider, err := c.svc.Provider.GetByNPI(user.Provider.InternalID, authUser) provider, err := c.svc.Provider.GetByNPI(user.Provider.InternalID, authUser)
if err != nil { if err != nil {
fmt.Println("Error to create organization", err) fmt.Println("Error to create organization", err)
@@ -120,19 +139,5 @@ func (c *controller) handle(ctx echo.Context) error {
return routeutils.HandleAPIError(ctx, err) return routeutils.HandleAPIError(ctx, err)
} }
//Send email notification to Authorized user
notification := viewmodel.Notification{
Type: "email",
From: c.cfg.Email.Sender,
To: *user.Email,
Subject: notificationEmailSubject,
Message: notificationEmailBody,
}
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
if err != nil {
return routeutils.HandleAPIError(ctx, err)
}
return routeutils.ResponseAPIOK(ctx, user) return routeutils.ResponseAPIOK(ctx, user)
} }

View File

@@ -1,111 +0,0 @@
package validation
import (
"fmt"
"strings"
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
"bitbucket.org/nemt/nemt-portal-api/infra/errors"
)
const (
minimumPasswordLength = 8
)
func validateSelfregistrationPassword(user *viewmodel.User, result *[]errors.ValidationError) {
if len(user.Pass) < minimumPasswordLength {
*result = append(*result, errors.ValidationError{Field: "password", Message: fmt.Sprint("Password must be at least ", minimumPasswordLength, " characters.")})
}
if strings.Contains(user.Pass, user.First) {
*result = append(*result, errors.ValidationError{Field: "password", Message: "Password cannot include your First Name."})
}
if strings.Contains(user.Pass, user.Last) {
*result = append(*result, errors.ValidationError{Field: "password", Message: "Password cannot include your Last Name."})
}
containsUpperCaseLetter := false
containsLowerCaseLetter := false
containsNumber := false
for _, character := range user.Pass {
containsUpperCaseLetter = containsUpperCaseLetter || characterIsUpperCase(character)
containsLowerCaseLetter = containsLowerCaseLetter || characterIsLowerCase(character)
containsNumber = containsNumber || characterIsNumber(character)
}
if !containsUpperCaseLetter || !containsLowerCaseLetter || !containsNumber {
*result = append(*result, errors.ValidationError{Field: "password", Message: "Password must contain one of EACH :"})
*result = append(*result, errors.ValidationError{Field: "password-tab", Message: "an uppercase letter"})
*result = append(*result, errors.ValidationError{Field: "password-tab", Message: "a lowercase letter"})
*result = append(*result, errors.ValidationError{Field: "password-tab", Message: "a number"})
}
}
func ValidateSelfregistration(user *viewmodel.User) []errors.ValidationError {
var result []errors.ValidationError
//Provider Organization Name validation
if len(user.Provider.OrganizatioName) < 1 {
result = append(result, errors.ValidationError{Field: "provider.org_name", Message: "Provider Organization Name is required"})
}
//Provider NPI validation
if len(user.Provider.InternalID) != 10 || !isNumeric(user.Provider.InternalID) {
result = append(result, errors.ValidationError{Field: "provider.internal_id", Message: "Provider NPI must be 10 digit number"})
}
//First name validation
if len(user.First) < 1 {
result = append(result, errors.ValidationError{Field: "first", Message: "First Name is required"})
}
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"})
}
//Last name validation
if len(user.Last) < 1 {
result = append(result, errors.ValidationError{Field: "last", Message: "Last Name is required"})
}
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"})
}
//Email validation
if user.Email != nil {
if 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 {
result = append(result, errors.ValidationError{Field: "email", Message: "Email is required"})
}
//Mobile validation
if (user.PhoneNumber == nil) || len(*user.PhoneNumber) < 1 {
result = append(result, errors.ValidationError{Field: "phonenumber", Message: "Phone number is required"})
}
//Password validation
validateSelfregistrationPassword(user, &result)
return result
}

View File

@@ -1,13 +1,15 @@
package validation package validation
import ( import (
"fmt"
"regexp"
"strconv"
"time" "time"
"fmt"
"strconv"
"regexp"
"bitbucket.org/nemt/nemt-portal-api/application/viewmodel" "bitbucket.org/nemt/nemt-portal-api/application/viewmodel"
"bitbucket.org/nemt/nemt-portal-api/infra/errors" "bitbucket.org/nemt/nemt-portal-api/infra/errors"
) )
const ( const (
@@ -36,7 +38,7 @@ func isMixedIDValid(id string) bool {
hasLowerCase := false hasLowerCase := false
hasNumber := false hasNumber := false
for _, character := range id { for _, character := range (id) {
hasUpperCase = hasUpperCase || ((character >= 65) && (character <= 90)) hasUpperCase = hasUpperCase || ((character >= 65) && (character <= 90))
hasLowerCase = hasLowerCase || ((character >= 97) && (character <= 122)) hasLowerCase = hasLowerCase || ((character >= 97) && (character <= 122))
hasNumber = hasNumber || ((character >= 48) && (character <= 57)) hasNumber = hasNumber || ((character >= 48) && (character <= 57))
@@ -208,5 +210,6 @@ func ValidateRide(requestRide *viewmodel.RideRequest, user *viewmodel.User) []er
result = append (result, errors.ValidationError{Field : "trip_type.key", Message : "Step #4 - Choose a Trip Type"}) result = append (result, errors.ValidationError{Field : "trip_type.key", Message : "Step #4 - Choose a Trip Type"})
} }
return result return result
} }