Commit 04d03f73 by Torkel Ödegaard

Added disable user sign up feature

parent d95c5e66
......@@ -59,7 +59,7 @@ login_remember_days = 7
cookie_username = grafana_user
cookie_remember_name = grafana_remember
; disable user signup / registration
; disable_user_signup = false, not implemented yet
disable_user_signup = false
[account.single]
; Enable this feature to auto assign new users to a single account, suitable for NON multi tenant setups
......
Subproject commit 3b5c813be71c4816f3c2ef40e4c1439a8026236f
Subproject commit 740709da0493536269adfe1cafd0b93d975b02a2
......@@ -18,7 +18,7 @@ func Register(r *macaron.Macaron) {
// not logged in views
r.Get("/", reqSignedIn, Index)
r.Post("/logout", LogoutPost)
r.Get("/logout", Logout)
r.Post("/login", bind(dtos.LoginCommand{}), LoginPost)
r.Get("/login/:name", OAuthLogin)
r.Get("/login", LoginView)
......
......@@ -25,6 +25,7 @@ func LoginView(c *middleware.Context) {
settings := c.Data["Settings"].(map[string]interface{})
settings["googleAuthEnabled"] = setting.OAuthService.Google
settings["githubAuthEnabled"] = setting.OAuthService.GitHub
settings["disableUserSignUp"] = setting.DisableUserSignUp
// Check auto-login.
uname := c.GetCookie(setting.CookieUserName)
......@@ -122,9 +123,9 @@ func loginUserWithUser(user *m.User, c *middleware.Context) {
c.Session.Set(middleware.SESS_KEY_USERID, user.Id)
}
func LogoutPost(c *middleware.Context) {
func Logout(c *middleware.Context) {
c.SetCookie(setting.CookieUserName, "", -1, setting.AppSubUrl+"/")
c.SetCookie(setting.CookieRememberName, "", -1, setting.AppSubUrl+"/")
c.Session.Destory(c.Context)
c.JsonOK("logged out")
c.Redirect(setting.AppSubUrl + "/login")
}
......@@ -56,6 +56,11 @@ func OAuthLogin(ctx *middleware.Context) {
// create account if missing
if err == m.ErrUserNotFound {
if setting.DisableUserSignUp {
ctx.Redirect(setting.AppSubUrl + "/login")
return
}
cmd := m.CreateUserCommand{
Login: userInfo.Email,
Email: userInfo.Email,
......
......@@ -4,10 +4,15 @@ import (
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/setting"
)
// POST /api/user/signup
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
if setting.DisableUserSignUp {
c.JsonApiErr(401, "User signup is disabled", nil)
return
}
cmd.Login = cmd.Email
......
......@@ -36,6 +36,8 @@ var CmdWeb = cli.Command{
}
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
......
......@@ -83,7 +83,7 @@ func GetContextHandler() macaron.Handler {
func (ctx *Context) Handle(status int, title string, err error) {
if err != nil {
log.Error(4, "%s: %v", title, err)
if macaron.Env != macaron.PROD {
if setting.Env != setting.PROD {
ctx.Data["ErrorMsg"] = err
}
}
......
......@@ -63,6 +63,7 @@ var (
LogInRememberDays int
CookieUserName string
CookieRememberName string
DisableUserSignUp bool
// single account
SingleAccountMode bool
......@@ -196,6 +197,7 @@ func NewConfigContext() {
LogInRememberDays = security.Key("login_remember_days").MustInt()
CookieUserName = security.Key("cookie_username").String()
CookieRememberName = security.Key("cookie_remember_name").String()
DisableUserSignUp = security.Key("disable_user_signup").MustBool(false)
// admin
AdminUser = security.Key("admin_user").String()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment