account state changes
This commit is contained in:
@@ -44,6 +44,9 @@ func (a *AccountAPI) verify(r *http.Request) http.HandlerFunc {
|
||||
a.logger.Warn("Failed to save account while verifying account", zap.Error(err))
|
||||
return response.Internal(a.logger, a.Name(), err)
|
||||
}
|
||||
if err := a.sendAccountVerificationCompletedNotification(&user); err != nil {
|
||||
a.logger.Warn("Failed to enqueue account verification notification", zap.Error(err), zap.String("email", user.Login))
|
||||
}
|
||||
|
||||
// TODO: Send verification confirmation email
|
||||
return response.Success(a.logger)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/tech/sendico/pkg/api/http/response"
|
||||
"github.com/tech/sendico/pkg/db/storable"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
snotifications "github.com/tech/sendico/pkg/messaging/notifications/site"
|
||||
"github.com/tech/sendico/pkg/model"
|
||||
"github.com/tech/sendico/pkg/mservice"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
@@ -104,10 +105,52 @@ func (a *AccountAPI) signup(r *http.Request) http.HandlerFunc {
|
||||
if err := a.sendWelcomeEmail(newAccount, verificationToken); err != nil {
|
||||
a.logger.Warn("Failed to send welcome email", zap.Error(err), mzap.StorableRef(newAccount))
|
||||
}
|
||||
if err := a.sendSignupNotification(newAccount, &sr); err != nil {
|
||||
a.logger.Warn("Failed to enqueue signup notification", zap.Error(err), zap.String("login", newAccount.Login))
|
||||
}
|
||||
|
||||
return sresponse.SignUp(a.logger, newAccount)
|
||||
}
|
||||
|
||||
func (a *AccountAPI) sendSignupNotification(account *model.Account, request *srequest.Signup) error {
|
||||
if account == nil || request == nil {
|
||||
return merrors.InvalidArgument("signup notification payload is empty")
|
||||
}
|
||||
|
||||
signupNotification := &model.ContactRequest{
|
||||
Name: accountNotificationName(account),
|
||||
Email: strings.TrimSpace(account.Login),
|
||||
Company: strings.TrimSpace(request.Organization.Name),
|
||||
Topic: model.ContactRequestTopicSignupCompleted,
|
||||
}
|
||||
|
||||
return a.producer.SendMessage(snotifications.ContactRequest(a.Name(), signupNotification))
|
||||
}
|
||||
|
||||
func (a *AccountAPI) sendAccountVerificationCompletedNotification(account *model.Account) error {
|
||||
if account == nil {
|
||||
return merrors.InvalidArgument("account verification notification payload is empty", "account")
|
||||
}
|
||||
|
||||
notification := &model.ContactRequest{
|
||||
Name: accountNotificationName(account),
|
||||
Email: strings.TrimSpace(account.Login),
|
||||
Topic: model.ContactRequestTopicAccountVerificationCompleted,
|
||||
}
|
||||
|
||||
return a.producer.SendMessage(snotifications.ContactRequest(a.Name(), notification))
|
||||
}
|
||||
|
||||
func accountNotificationName(account *model.Account) string {
|
||||
if account == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(strings.Join([]string{
|
||||
strings.TrimSpace(account.Name),
|
||||
strings.TrimSpace(account.LastName),
|
||||
}, " "))
|
||||
}
|
||||
|
||||
func (a *AccountAPI) signupAvailability(r *http.Request) http.HandlerFunc {
|
||||
login := strings.ToLower(strings.TrimSpace(r.URL.Query().Get("login")))
|
||||
if login == "" {
|
||||
|
||||
@@ -17,6 +17,9 @@ func (a *SiteAPI) contactRequest(r *http.Request) http.HandlerFunc {
|
||||
return response.BadRequest(a.logger, a.Name(), "invalid_payload", "Failed to decode contact request payload")
|
||||
}
|
||||
request.Normalize()
|
||||
if request.Topic == "" {
|
||||
request.Topic = model.ContactRequestTopicSiteContact
|
||||
}
|
||||
if err := request.Validate(); err != nil {
|
||||
a.logger.Warn("Contact request validation failed", zap.Error(err))
|
||||
return response.BadPayload(a.logger, a.Name(), err)
|
||||
|
||||
Reference in New Issue
Block a user