mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
worked on account creation
This commit is contained in:
parent
eec178458b
commit
9e6df378c3
2
grafana
2
grafana
@ -1 +1 @@
|
||||
Subproject commit d9a33680a686ac6bc1239797278ad03b3c784d1c
|
||||
Subproject commit 9667f324f1db66f7cdfa7ce5b6c9b38c92f41d53
|
18
pkg/api/account.go
Normal file
18
pkg/api/account.go
Normal file
@ -0,0 +1,18 @@
|
||||
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
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user