Merge pull request #113 from gophish/111-force-smtp-from

Added SMTP Validation
pull/138/head
Jordan Wright 2016-02-01 18:43:14 -06:00
commit c73a78bbdf
2 changed files with 17 additions and 6 deletions

View File

@ -60,7 +60,7 @@ func (c *Campaign) Validate() error {
case c.Page.Name == "":
return ErrPageNotSpecified
}
return nil
return c.SMTP.Validate()
}
// SendTestEmailRequest is the structure of a request
@ -84,7 +84,8 @@ func (s *SendTestEmailRequest) Validate() error {
case s.Email == "":
return ErrEmailNotSpecified
}
return nil
// Finally, check the SMTP settings
return s.SMTP.Validate()
}
// UpdateStatus changes the campaign status appropriately

View File

@ -1,5 +1,7 @@
package models
import "errors"
// SMTP contains the attributes needed to handle the sending of campaign emails
type SMTP struct {
SMTPId int64 `json:"-" gorm:"column:smtp_id; primary_key:yes"`
@ -10,18 +12,26 @@ type SMTP struct {
FromAddress string `json:"from_address"`
}
// ErrFromAddressNotSpecified is thrown when there is no "From" address
// specified in the SMTP configuration
var ErrFromAddressNotSpecified = errors.New("No From Address specified")
// ErrHostNotSpecified is thrown when there is no Host specified
// in the SMTP configuration
var ErrHostNotSpecified = errors.New("No SMTP Host specified")
// TableName specifies the database tablename for Gorm to use
func (s SMTP) TableName() string {
return "smtp"
}
// Validate ensures that SMTP configs/connections are valid
func (s *SMTP) Validate() (string, bool) {
func (s *SMTP) Validate() error {
switch {
case s.FromAddress == "":
return "No from address specified", false
return ErrFromAddressNotSpecified
case s.Host == "":
return "No hostname specified", false
return ErrHostNotSpecified
}
return "", true
return nil
}