You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/models/login.go

71 lines
1.3 KiB

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