summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-09-11 12:03:08 -0400
committerUnknwon <u@gogs.io>2015-09-11 12:03:08 -0400
commit121a81a2c554b2de0de89ab7749fe691b5d1aba7 (patch)
treecc0206c03f546734545c3355b09a3e060eeef7e7 /models
parent06174482826e81fb7c4675efff092e2986c4dac0 (diff)
downloadgitea-121a81a2c554b2de0de89ab7749fe691b5d1aba7.tar.gz
gitea-121a81a2c554b2de0de89ab7749fe691b5d1aba7.zip
finish new edit auth UI
Diffstat (limited to 'models')
-rw-r--r--models/login.go39
1 files changed, 34 insertions, 5 deletions
diff --git a/models/login.go b/models/login.go
index abd4fc0334..33f0f27069 100644
--- a/models/login.go
+++ b/models/login.go
@@ -13,6 +13,7 @@ import (
"strings"
"time"
+ "github.com/Unknwon/com"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
@@ -114,6 +115,8 @@ func (source *LoginSource) BeforeSet(colName string, val xorm.Cell) {
source.Cfg = new(SMTPConfig)
case PAM:
source.Cfg = new(PAMConfig)
+ default:
+ panic("unrecognized login source type: " + com.ToStr(*val))
}
}
}
@@ -122,6 +125,33 @@ func (source *LoginSource) TypeName() string {
return LoginNames[source.Type]
}
+func (source *LoginSource) IsLDAP() bool {
+ return source.Type == LDAP
+}
+
+func (source *LoginSource) IsDLDAP() bool {
+ return source.Type == DLDAP
+}
+
+func (source *LoginSource) IsSMTP() bool {
+ return source.Type == SMTP
+}
+
+func (source *LoginSource) IsPAM() bool {
+ return source.Type == PAM
+}
+
+func (source *LoginSource) UseTLS() bool {
+ switch source.Type {
+ case LDAP, DLDAP:
+ return source.LDAP().UseSSL
+ case SMTP:
+ return source.SMTP().TLS
+ }
+
+ return false
+}
+
func (source *LoginSource) LDAP() *LDAPConfig {
return source.Cfg.(*LDAPConfig)
}
@@ -166,15 +196,14 @@ func UpdateSource(source *LoginSource) error {
return err
}
-func DelLoginSource(source *LoginSource) error {
- cnt, err := x.Count(&User{LoginSource: source.ID})
+func DeleteSource(source *LoginSource) error {
+ count, err := x.Count(&User{LoginSource: source.ID})
if err != nil {
return err
- }
- if cnt > 0 {
+ } else if count > 0 {
return ErrAuthenticationUserUsed
}
- _, err = x.Id(source.ID).Delete(&LoginSource{})
+ _, err = x.Id(source.ID).Delete(new(LoginSource))
return err
}