added registration.open to the configuration

This commit is contained in:
Brad Rydzewski 2014-09-04 20:53:32 -07:00
parent 83fb9265a3
commit 446fb04d49
4 changed files with 14 additions and 9 deletions

View file

@ -32,6 +32,10 @@ you can provide Drone with the path to your configuration file:
The configuration file is in TOML format:
```toml
[registration]
open=true
[github]
client=""
secret=""

View file

@ -70,7 +70,7 @@ DELETE FROM users WHERE user_id=?
// SQL statement to check if users exist.
const confirmUserStmt = `
select 0 from users limit 1
select 1 from users limit 1
`
// NewUserManager initiales a new UserManager intended to

View file

@ -16,13 +16,12 @@ type LoginHandler struct {
users database.UserManager
repos database.RepoManager
perms database.PermManager
//conf database.ConfigManager
sess session.Session
remotes database.RemoteManager
sess session.Session
open bool
}
func NewLoginHandler(users database.UserManager, repos database.RepoManager, perms database.PermManager, sess session.Session /*conf database.ConfigManager,*/, remotes database.RemoteManager) *LoginHandler {
return &LoginHandler{users, repos, perms /*conf,*/, sess, remotes}
func NewLoginHandler(users database.UserManager, repos database.RepoManager, perms database.PermManager, sess session.Session, open bool) *LoginHandler {
return &LoginHandler{users, repos, perms, sess, open}
}
// GetLogin gets the login to the 3rd party remote system.
@ -51,7 +50,7 @@ func (h *LoginHandler) GetLogin(w http.ResponseWriter, r *http.Request) error {
// if self-registration is disabled we should
// return a notAuthorized error. the only exception
// is if no users exist yet in the system we'll proceed.
if h.users.Exist() {
if h.open == false && h.users.Exist() {
return notAuthorized{}
}

View file

@ -53,6 +53,8 @@ var (
conf string
prefix string
open bool
)
func main() {
@ -68,6 +70,7 @@ func main() {
flag.IntVar(&workers, "workers", runtime.NumCPU(), "")
flag.Parse()
config.BoolVar(&open, "registration-open", false)
config.SetPrefix(prefix)
config.Parse(conf)
@ -88,7 +91,6 @@ func main() {
commits := database.NewCommitManager(db)
servers := database.NewServerManager(db)
remotes := database.NewRemoteManager(db)
//configs := database.NewConfigManager(filepath.Join(home, "config.toml"))
// message broker
pubsub := pubsub.NewPubSub()
@ -118,7 +120,7 @@ func main() {
handler.NewUsersHandler(users, sess).Register(router)
handler.NewUserHandler(users, repos, commits, sess).Register(router)
handler.NewHookHandler(users, repos, commits, remotes, queue).Register(router)
handler.NewLoginHandler(users, repos, perms, sess, remotes).Register(router)
handler.NewLoginHandler(users, repos, perms, sess, open).Register(router)
handler.NewCommitHandler(users, repos, commits, perms, sess, queue).Register(router)
handler.NewRepoHandler(repos, commits, perms, sess, remotes).Register(router)
handler.NewBadgeHandler(repos, commits).Register(router)