2014-12-29 06:36:08 -06:00
|
|
|
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"
|
2014-12-29 06:36:08 -06:00
|
|
|
)
|
|
|
|
|
2015-01-27 08:14:53 -06:00
|
|
|
// 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
|
|
|
|
}
|
2014-12-29 06:36:08 -06:00
|
|
|
|
|
|
|
cmd.Login = cmd.Email
|
|
|
|
|
2015-01-08 02:00:00 -06:00
|
|
|
if err := bus.Dispatch(&cmd); err != nil {
|
2015-01-19 11:01:04 -06:00
|
|
|
c.JsonApiErr(500, "failed to create user", err)
|
2014-12-29 06:36:08 -06:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-01-21 02:52:40 -06:00
|
|
|
user := cmd.Result
|
|
|
|
|
|
|
|
loginUserWithUser(&user, c)
|
|
|
|
|
|
|
|
c.JsonOK("User created and logged in")
|
2014-12-29 06:36:08 -06:00
|
|
|
}
|