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-08 02:00:00 -06:00
|
|
|
"github.com/torkelo/grafana-pro/pkg/util"
|
2014-12-29 06:36:08 -06:00
|
|
|
)
|
|
|
|
|
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) {
|
2014-12-29 06:36:08 -06:00
|
|
|
|
|
|
|
cmd.Login = cmd.Email
|
2015-01-08 02:00:00 -06:00
|
|
|
cmd.Salt = util.GetRandomString(10)
|
2015-01-27 05:05:23 -06:00
|
|
|
cmd.Rands = util.GetRandomString(10)
|
2015-01-08 02:00:00 -06:00
|
|
|
cmd.Password = util.EncodePassword(cmd.Password, cmd.Salt)
|
2014-12-29 06:36:08 -06:00
|
|
|
|
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
|
|
|
}
|