mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
more account stuff
This commit is contained in:
parent
992efda7f6
commit
015c929bd7
@ -5,11 +5,27 @@ import "github.com/gin-gonic/gin"
|
|||||||
func init() {
|
func init() {
|
||||||
addRoutes(func(self *HttpServer) {
|
addRoutes(func(self *HttpServer) {
|
||||||
self.addRoute("POST", "/api/account/collaborators/add", self.addCollaborator)
|
self.addRoute("POST", "/api/account/collaborators/add", self.addCollaborator)
|
||||||
|
self.addRoute("GET", "/api/account/", self.getAccount)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
type addCollaboratorDto struct {
|
func (self *HttpServer) getAccount(c *gin.Context, auth *authContext) {
|
||||||
Email string `json:"email" binding:"required"`
|
var account = auth.userAccount
|
||||||
|
|
||||||
|
model := accountInfoDto{
|
||||||
|
Login: account.Login,
|
||||||
|
Email: account.Email,
|
||||||
|
AccountName: account.AccountName,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, collaborator := range account.Collaborators {
|
||||||
|
model.Collaborators = append(model.Collaborators, &collaboratorInfoDto{
|
||||||
|
AccountId: collaborator.AccountId,
|
||||||
|
Role: collaborator.Role,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, model)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
|
func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
|
||||||
|
18
pkg/api/api_dtos.go
Normal file
18
pkg/api/api_dtos.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package api
|
||||||
|
|
||||||
|
type accountInfoDto struct {
|
||||||
|
Login string `json:"login"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
AccountName string `json:"accountName"`
|
||||||
|
Collaborators []*collaboratorInfoDto `json:"collaborators"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type collaboratorInfoDto struct {
|
||||||
|
AccountId int `json:"accountId"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Role string `json:"role"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type addCollaboratorDto struct {
|
||||||
|
Email string `json:"email" binding:"required"`
|
||||||
|
}
|
@ -28,7 +28,6 @@ func (self *HttpServer) registerUserPost(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
account := models.Account{
|
account := models.Account{
|
||||||
UserName: registerModel.Email,
|
|
||||||
Login: registerModel.Email,
|
Login: registerModel.Email,
|
||||||
Email: registerModel.Email,
|
Email: registerModel.Email,
|
||||||
Password: registerModel.Password,
|
Password: registerModel.Password,
|
||||||
|
@ -14,15 +14,17 @@ type CollaboratorLink struct {
|
|||||||
|
|
||||||
type Account struct {
|
type Account struct {
|
||||||
Id int `gorethink:"id"`
|
Id int `gorethink:"id"`
|
||||||
UserName string
|
Version int
|
||||||
Login string
|
Login string
|
||||||
Email string
|
Email string
|
||||||
|
AccountName string
|
||||||
Password string
|
Password string
|
||||||
NextDashboardId int
|
NextDashboardId int
|
||||||
UsingAccountId int
|
UsingAccountId int
|
||||||
Collaborators []CollaboratorLink
|
Collaborators []CollaboratorLink
|
||||||
CreatedOn time.Time
|
CreatedOn time.Time
|
||||||
ModifiedOn time.Time
|
ModifiedOn time.Time
|
||||||
|
LastLoginOn time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func (account *Account) AddCollaborator(accountId int) error {
|
func (account *Account) AddCollaborator(accountId int) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user