diff options
author | Unknwon <u@gogs.io> | 2015-09-11 13:32:33 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-09-11 13:32:33 -0400 |
commit | 362d64df0483700ac435c4b05709265378887a4e (patch) | |
tree | fb367bbd236ea7707df0d9d5bbfe5d95a19dca0a /models/login.go | |
parent | 373ef5d15e1c2781bf47750554cb21e4ed5446c1 (diff) | |
download | gitea-362d64df0483700ac435c4b05709265378887a4e.tar.gz gitea-362d64df0483700ac435c4b05709265378887a4e.zip |
#1620 add allowed domains for SMTP auth
Diffstat (limited to 'models/login.go')
-rw-r--r-- | models/login.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/models/login.go b/models/login.go index 33f0f27069..bcff4f9acd 100644 --- a/models/login.go +++ b/models/login.go @@ -67,11 +67,12 @@ func (cfg *LDAPConfig) ToDB() ([]byte, error) { } type SMTPConfig struct { - Auth string - Host string - Port int - TLS bool - SkipVerify bool + Auth string + Host string + Port int + AllowedDomains string `xorm:"TEXT"` + TLS bool + SkipVerify bool } func (cfg *SMTPConfig) FromDB(bs []byte) error { @@ -383,6 +384,16 @@ func SMTPAuth(a smtp.Auth, cfg *SMTPConfig) error { // Create a local user if success // Return the same LoginUserPlain semantic 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 if cfg.Auth == SMTP_PLAIN { 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 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 } |