added registration.open to the configuration
This commit is contained in:
parent
83fb9265a3
commit
446fb04d49
4 changed files with 14 additions and 9 deletions
|
@ -32,6 +32,10 @@ you can provide Drone with the path to your configuration file:
|
||||||
The configuration file is in TOML format:
|
The configuration file is in TOML format:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
|
|
||||||
|
[registration]
|
||||||
|
open=true
|
||||||
|
|
||||||
[github]
|
[github]
|
||||||
client=""
|
client=""
|
||||||
secret=""
|
secret=""
|
||||||
|
|
|
@ -70,7 +70,7 @@ DELETE FROM users WHERE user_id=?
|
||||||
|
|
||||||
// SQL statement to check if users exist.
|
// SQL statement to check if users exist.
|
||||||
const confirmUserStmt = `
|
const confirmUserStmt = `
|
||||||
select 0 from users limit 1
|
select 1 from users limit 1
|
||||||
`
|
`
|
||||||
|
|
||||||
// NewUserManager initiales a new UserManager intended to
|
// NewUserManager initiales a new UserManager intended to
|
||||||
|
|
|
@ -16,13 +16,12 @@ type LoginHandler struct {
|
||||||
users database.UserManager
|
users database.UserManager
|
||||||
repos database.RepoManager
|
repos database.RepoManager
|
||||||
perms database.PermManager
|
perms database.PermManager
|
||||||
//conf database.ConfigManager
|
sess session.Session
|
||||||
sess session.Session
|
open bool
|
||||||
remotes database.RemoteManager
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLoginHandler(users database.UserManager, repos database.RepoManager, perms database.PermManager, sess session.Session /*conf database.ConfigManager,*/, remotes database.RemoteManager) *LoginHandler {
|
func NewLoginHandler(users database.UserManager, repos database.RepoManager, perms database.PermManager, sess session.Session, open bool) *LoginHandler {
|
||||||
return &LoginHandler{users, repos, perms /*conf,*/, sess, remotes}
|
return &LoginHandler{users, repos, perms, sess, open}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetLogin gets the login to the 3rd party remote system.
|
// 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
|
// if self-registration is disabled we should
|
||||||
// return a notAuthorized error. the only exception
|
// return a notAuthorized error. the only exception
|
||||||
// is if no users exist yet in the system we'll proceed.
|
// 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{}
|
return notAuthorized{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ var (
|
||||||
|
|
||||||
conf string
|
conf string
|
||||||
prefix string
|
prefix string
|
||||||
|
|
||||||
|
open bool
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -68,6 +70,7 @@ func main() {
|
||||||
flag.IntVar(&workers, "workers", runtime.NumCPU(), "")
|
flag.IntVar(&workers, "workers", runtime.NumCPU(), "")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
config.BoolVar(&open, "registration-open", false)
|
||||||
config.SetPrefix(prefix)
|
config.SetPrefix(prefix)
|
||||||
config.Parse(conf)
|
config.Parse(conf)
|
||||||
|
|
||||||
|
@ -88,7 +91,6 @@ func main() {
|
||||||
commits := database.NewCommitManager(db)
|
commits := database.NewCommitManager(db)
|
||||||
servers := database.NewServerManager(db)
|
servers := database.NewServerManager(db)
|
||||||
remotes := database.NewRemoteManager(db)
|
remotes := database.NewRemoteManager(db)
|
||||||
//configs := database.NewConfigManager(filepath.Join(home, "config.toml"))
|
|
||||||
|
|
||||||
// message broker
|
// message broker
|
||||||
pubsub := pubsub.NewPubSub()
|
pubsub := pubsub.NewPubSub()
|
||||||
|
@ -118,7 +120,7 @@ func main() {
|
||||||
handler.NewUsersHandler(users, sess).Register(router)
|
handler.NewUsersHandler(users, sess).Register(router)
|
||||||
handler.NewUserHandler(users, repos, commits, sess).Register(router)
|
handler.NewUserHandler(users, repos, commits, sess).Register(router)
|
||||||
handler.NewHookHandler(users, repos, commits, remotes, queue).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.NewCommitHandler(users, repos, commits, perms, sess, queue).Register(router)
|
||||||
handler.NewRepoHandler(repos, commits, perms, sess, remotes).Register(router)
|
handler.NewRepoHandler(repos, commits, perms, sess, remotes).Register(router)
|
||||||
handler.NewBadgeHandler(repos, commits).Register(router)
|
handler.NewBadgeHandler(repos, commits).Register(router)
|
||||||
|
|
Loading…
Reference in a new issue