Commit 9e6df378 by Torkel Ödegaard

worked on account creation

parent eec17845
Subproject commit d9a33680a686ac6bc1239797278ad03b3c784d1c
Subproject commit 9667f324f1db66f7cdfa7ce5b6c9b38c92f41d53
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"
)
func CreateAccount(c *middleware.Context, cmd m.CreateAccountCommand) {
cmd.UserId = c.UserId
if err := bus.Dispatch(&cmd); err != nil {
c.JsonApiErr(500, "Failed to create account", nil)
return
}
c.JsonOK("Account created")
}
......@@ -49,6 +49,7 @@ func Register(r *macaron.Macaron) {
// account
r.Group("/account", func() {
r.Put("/", bind(m.CreateAccountCommand{}), CreateAccount)
r.Put("/users", bind(m.AddAccountUserCommand{}), AddAccountUser)
r.Get("/users", GetAccountUsers)
r.Delete("/users/:id", RemoveAccountUser)
......
......@@ -21,8 +21,10 @@ type Account struct {
// COMMANDS
type CreateAccountCommand struct {
Name string `json:"name"`
Name string `json:"name" binding:"Required"`
// initial admin user for account
UserId int64 `json:"-"`
Result Account `json:"-"`
}
......
......@@ -24,8 +24,22 @@ func CreateAccount(cmd *m.CreateAccountCommand) error {
Updated: time.Now(),
}
_, err := sess.Insert(&account)
if _, err := sess.Insert(&account); err != nil {
return err
}
// create inital admin account user
user := m.AccountUser{
AccountId: account.Id,
UserId: cmd.UserId,
Role: m.ROLE_ADMIN,
Created: time.Now(),
Updated: time.Now(),
}
_, err := sess.Insert(&user)
cmd.Result = account
return err
})
}
......
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