grafana/pkg/api/signup.go

29 lines
656 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-08 02:00:00 -06:00
"github.com/torkelo/grafana-pro/pkg/util"
)
2015-01-14 03:19:45 -06:00
// POST /api/account/signup
2015-01-21 02:52:40 -06:00
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) {
cmd.Login = cmd.Email
2015-01-08 02:00:00 -06:00
cmd.Salt = util.GetRandomString(10)
cmd.Rands = util.GetRandomString(10)
2015-01-08 02:00:00 -06:00
cmd.Password = util.EncodePassword(cmd.Password, cmd.Salt)
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")
}