forgejo/models/login.go

71 lines
1.3 KiB
Go
Raw Normal View History

2014-04-26 08:21:04 +02:00
package models
2014-05-03 04:48:14 +02:00
import (
"encoding/json"
"time"
2014-04-26 08:21:04 +02:00
2014-05-03 04:48:14 +02:00
"github.com/go-xorm/core"
"github.com/gogits/gogs/modules/auth/ldap"
)
2014-04-26 08:21:04 +02:00
/*const (
LT_PLAIN = iota + 1
LT_LDAP
LT_SMTP
)*/
var _ core.Conversion = &LDAPConfig{}
type LDAPConfig struct {
2014-05-03 04:48:14 +02:00
ldap.Ldapsource
2014-04-26 08:21:04 +02:00
}
// implement
func (cfg *LDAPConfig) FromDB(bs []byte) error {
2014-05-03 04:48:14 +02:00
return json.Unmarshal(bs, &cfg.Ldapsource)
2014-04-26 08:21:04 +02:00
}
func (cfg *LDAPConfig) ToDB() ([]byte, error) {
2014-05-03 04:48:14 +02:00
return json.Marshal(cfg.Ldapsource)
2014-04-26 08:21:04 +02:00
}
type LoginSource struct {
2014-05-03 04:48:14 +02:00
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
2014-04-26 08:21:04 +02:00
}