summaryrefslogtreecommitdiffstats
path: root/models/login.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/login.go')
-rw-r--r--models/login.go55
1 files changed, 46 insertions, 9 deletions
diff --git a/models/login.go b/models/login.go
index e8dbfc2725..6d9e54943f 100644
--- a/models/login.go
+++ b/models/login.go
@@ -1,9 +1,12 @@
package models
-import
+import (
+ "encoding/json"
+ "time"
-// Login types.
-"github.com/go-xorm/core"
+ "github.com/go-xorm/core"
+ "github.com/gogits/gogs/modules/auth/ldap"
+)
/*const (
LT_PLAIN = iota + 1
@@ -14,20 +17,54 @@ import
var _ core.Conversion = &LDAPConfig{}
type LDAPConfig struct {
+ ldap.Ldapsource
}
// implement
func (cfg *LDAPConfig) FromDB(bs []byte) error {
- return nil
+ return json.Unmarshal(bs, &cfg.Ldapsource)
}
func (cfg *LDAPConfig) ToDB() ([]byte, error) {
- return nil, nil
+ return json.Marshal(cfg.Ldapsource)
}
type LoginSource struct {
- Id int64
- Type int
- Name string
- Cfg LDAPConfig
+ Id int64
+ Type int
+ Name string
+ IsActived bool
+ Cfg core.Conversion `xorm:"TEXT"`
+ Created time.Time `xorm:"created"`
+ Updated time.Time `xorm:"updated"`
+}
+
+func GetAuths() ([]*LoginSource, error) {
+ var auths = make([]*LoginSource, 0)
+ err := orm.Find(&auths)
+ return auths, err
+}
+
+func AddLDAPSource(name string, cfg *LDAPConfig) error {
+ _, err := orm.Insert(&LoginSource{Type: LT_LDAP,
+ Name: name,
+ IsActived: true,
+ Cfg: cfg,
+ })
+ return err
+}
+
+func UpdateLDAPSource(id int64, name string, cfg *LDAPConfig) error {
+ _, err := orm.AllCols().Id(id).Update(&LoginSource{
+ Id: id,
+ Type: LT_LDAP,
+ Name: name,
+ Cfg: cfg,
+ })
+ return err
+}
+
+func DelLoginSource(id int64) error {
+ _, err := orm.Id(id).Delete(&LoginSource{})
+ return err
}