Upstream sync
This commit is contained in:
@@ -16,6 +16,12 @@ import (
|
||||
"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"
|
||||
notificationSmsBody = "You have registered as a Visit Reporter for CHM NEMT. Login: https://portal.bcbsinstitute.com Reset PW: https://portal.bcbsinstitute.com/forgot"
|
||||
)
|
||||
|
||||
var (
|
||||
instance *controller
|
||||
once sync.Once
|
||||
@@ -49,44 +55,20 @@ func (c *controller) handle(ctx echo.Context) error {
|
||||
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)
|
||||
if err != nil {
|
||||
return routeutils.ResponseAPIValidationError(ctx, "Invalid password")
|
||||
}
|
||||
user.Pass = string(pass)
|
||||
|
||||
if passwordValidationErrors := validation.ValidatePassword(&user); len(passwordValidationErrors) > 0 {
|
||||
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 validationErrors := validation.ValidateSelfregistration(&user); len(validationErrors) > 0 {
|
||||
return routeutils.ResponseAPICustomValidationError(ctx, "Self registration failed", validationErrors)
|
||||
}
|
||||
|
||||
if len(user.First) != 0 && len(user.Last) != 0 {
|
||||
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)
|
||||
if err != nil {
|
||||
fmt.Println("Error to create organization", err)
|
||||
@@ -139,5 +121,31 @@ func (c *controller) handle(ctx echo.Context) error {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
//Send email notification to Authorized user
|
||||
notification := viewmodel.Notification{
|
||||
Type: applicationservice.NotificationTypeEmail,
|
||||
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)
|
||||
}
|
||||
|
||||
//Send sms notification to Authorized user
|
||||
notification = viewmodel.Notification{
|
||||
Type: applicationservice.NOtificationTypeSMS,
|
||||
To: *user.PhoneNumber,
|
||||
Message: notificationSmsBody,
|
||||
}
|
||||
|
||||
notification, err = c.svc.Notification.SendNotificationWithoutWritingToDatabase(notification)
|
||||
if err != nil {
|
||||
return routeutils.HandleAPIError(ctx, err)
|
||||
}
|
||||
|
||||
return routeutils.ResponseAPIOK(ctx, user)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user