grafana/pkg/api/signup.go

30 lines
617 B
Go
Raw Normal View History

package api
import (
"github.com/torkelo/grafana-pro/pkg/bus"
"github.com/torkelo/grafana-pro/pkg/middleware"
m "github.com/torkelo/grafana-pro/pkg/models"
2015-01-29 08:46:54 -06:00
"github.com/torkelo/grafana-pro/pkg/setting"
)
// POST /api/user/signup
2015-01-21 02:52:40 -06:00
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
2015-01-29 08:46:54 -06:00
if setting.DisableUserSignUp {
c.JsonApiErr(401, "User signup is disabled", nil)
return
}
cmd.Login = cmd.Email
2015-01-08 02:00:00 -06:00
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "failed to create user", err)
return
}
2015-01-21 02:52:40 -06:00
user := cmd.Result
loginUserWithUser(&user, c)
c.JsonOK("User created and logged in")
}