From 446fb04d499ba6efc65cf5f26074e175b56d9c3d Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 4 Sep 2014 20:53:32 -0700 Subject: [PATCH] added registration.open to the configuration --- README.md | 4 ++++ server/database/user.go | 2 +- server/handler/login.go | 11 +++++------ server/main.go | 6 ++++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0c212ebe..b333dc7d 100644 --- a/README.md +++ b/README.md @@ -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="" diff --git a/server/database/user.go b/server/database/user.go index 11e4858e..05183bc4 100644 --- a/server/database/user.go +++ b/server/database/user.go @@ -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 diff --git a/server/handler/login.go b/server/handler/login.go index 4b7990af..7e37bafd 100644 --- a/server/handler/login.go +++ b/server/handler/login.go @@ -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{} } diff --git a/server/main.go b/server/main.go index 6a78748d..473786d2 100644 --- a/server/main.go +++ b/server/main.go @@ -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)