mirror of https://github.com/gophish/gophish
commit
c73a78bbdf
|
@ -60,7 +60,7 @@ func (c *Campaign) Validate() error {
|
||||||
case c.Page.Name == "":
|
case c.Page.Name == "":
|
||||||
return ErrPageNotSpecified
|
return ErrPageNotSpecified
|
||||||
}
|
}
|
||||||
return nil
|
return c.SMTP.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendTestEmailRequest is the structure of a request
|
// SendTestEmailRequest is the structure of a request
|
||||||
|
@ -84,7 +84,8 @@ func (s *SendTestEmailRequest) Validate() error {
|
||||||
case s.Email == "":
|
case s.Email == "":
|
||||||
return ErrEmailNotSpecified
|
return ErrEmailNotSpecified
|
||||||
}
|
}
|
||||||
return nil
|
// Finally, check the SMTP settings
|
||||||
|
return s.SMTP.Validate()
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStatus changes the campaign status appropriately
|
// UpdateStatus changes the campaign status appropriately
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package models
|
package models
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
// SMTP contains the attributes needed to handle the sending of campaign emails
|
// SMTP contains the attributes needed to handle the sending of campaign emails
|
||||||
type SMTP struct {
|
type SMTP struct {
|
||||||
SMTPId int64 `json:"-" gorm:"column:smtp_id; primary_key:yes"`
|
SMTPId int64 `json:"-" gorm:"column:smtp_id; primary_key:yes"`
|
||||||
|
@ -10,18 +12,26 @@ type SMTP struct {
|
||||||
FromAddress string `json:"from_address"`
|
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
|
// TableName specifies the database tablename for Gorm to use
|
||||||
func (s SMTP) TableName() string {
|
func (s SMTP) TableName() string {
|
||||||
return "smtp"
|
return "smtp"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate ensures that SMTP configs/connections are valid
|
// Validate ensures that SMTP configs/connections are valid
|
||||||
func (s *SMTP) Validate() (string, bool) {
|
func (s *SMTP) Validate() error {
|
||||||
switch {
|
switch {
|
||||||
case s.FromAddress == "":
|
case s.FromAddress == "":
|
||||||
return "No from address specified", false
|
return ErrFromAddressNotSpecified
|
||||||
case s.Host == "":
|
case s.Host == "":
|
||||||
return "No hostname specified", false
|
return ErrHostNotSpecified
|
||||||
}
|
}
|
||||||
return "", true
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue