|
|
@ -70,6 +70,7 @@ type SMTPConfig struct { |
|
|
|
Auth string |
|
|
|
Auth string |
|
|
|
Host string |
|
|
|
Host string |
|
|
|
Port int |
|
|
|
Port int |
|
|
|
|
|
|
|
AllowedDomains string `xorm:"TEXT"` |
|
|
|
TLS bool |
|
|
|
TLS bool |
|
|
|
SkipVerify bool |
|
|
|
SkipVerify bool |
|
|
|
} |
|
|
|
} |
|
|
@ -383,6 +384,16 @@ func SMTPAuth(a smtp.Auth, cfg *SMTPConfig) error { |
|
|
|
// Create a local user if success
|
|
|
|
// Create a local user if success
|
|
|
|
// Return the same LoginUserPlain semantic
|
|
|
|
// Return the same LoginUserPlain semantic
|
|
|
|
func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTPConfig, autoRegister bool) (*User, error) { |
|
|
|
func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTPConfig, autoRegister bool) (*User, error) { |
|
|
|
|
|
|
|
// Verify allowed domains.
|
|
|
|
|
|
|
|
if len(cfg.AllowedDomains) > 0 { |
|
|
|
|
|
|
|
idx := strings.Index(name, "@") |
|
|
|
|
|
|
|
if idx == -1 { |
|
|
|
|
|
|
|
return nil, ErrUserNotExist{0, name} |
|
|
|
|
|
|
|
} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), name[idx+1:]) { |
|
|
|
|
|
|
|
return nil, ErrUserNotExist{0, name} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var auth smtp.Auth |
|
|
|
var auth smtp.Auth |
|
|
|
if cfg.Auth == SMTP_PLAIN { |
|
|
|
if cfg.Auth == SMTP_PLAIN { |
|
|
|
auth = smtp.PlainAuth("", name, passwd, cfg.Host) |
|
|
|
auth = smtp.PlainAuth("", name, passwd, cfg.Host) |
|
|
@ -394,7 +405,8 @@ func LoginUserSMTPSource(u *User, name, passwd string, sourceId int64, cfg *SMTP |
|
|
|
|
|
|
|
|
|
|
|
if err := SMTPAuth(auth, cfg); err != nil { |
|
|
|
if err := SMTPAuth(auth, cfg); err != nil { |
|
|
|
if strings.Contains(err.Error(), "Username and Password not accepted") { |
|
|
|
if strings.Contains(err.Error(), "Username and Password not accepted") { |
|
|
|
return nil, ErrUserNotExist{u.Id, u.Name} |
|
|
|
fmt.Println(err) |
|
|
|
|
|
|
|
return nil, ErrUserNotExist{0, name} |
|
|
|
} |
|
|
|
} |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|