2014-11-21 09:43:04 -06:00
|
|
|
package dtos
|
2014-10-05 14:13:01 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/torkelo/grafana-pro/pkg/models"
|
|
|
|
)
|
|
|
|
|
2014-11-21 09:43:04 -06:00
|
|
|
type LoginResult struct {
|
|
|
|
Status string `json:"status"`
|
|
|
|
User CurrentUser `json:"user"`
|
2014-10-05 14:13:01 -05:00
|
|
|
}
|
|
|
|
|
2014-11-21 09:43:04 -06:00
|
|
|
type CurrentUser struct {
|
2014-10-05 14:13:01 -05:00
|
|
|
Login string `json:"login"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
GravatarUrl string `json:"gravatarUrl"`
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:43:04 -06:00
|
|
|
type AccountInfo struct {
|
|
|
|
Email string `json:"email"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Collaborators []*Collaborator `json:"collaborators"`
|
|
|
|
}
|
|
|
|
|
2014-11-24 01:04:41 -06:00
|
|
|
type OtherAccount struct {
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Role string `json:"role"`
|
|
|
|
IsUsing bool `json:"isUsing"`
|
|
|
|
}
|
|
|
|
|
2014-11-21 09:43:04 -06:00
|
|
|
type Collaborator struct {
|
|
|
|
AccountId int64 `json:"accountId"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Role string `json:"role"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCurrentUser(account *models.Account) *CurrentUser {
|
|
|
|
model := &CurrentUser{}
|
2014-10-05 14:13:01 -05:00
|
|
|
if account != nil {
|
|
|
|
model.Login = account.Login
|
|
|
|
model.Email = account.Email
|
|
|
|
model.GravatarUrl = getGravatarUrl(account.Email)
|
|
|
|
}
|
|
|
|
return model
|
|
|
|
}
|
|
|
|
|
|
|
|
func getGravatarUrl(text string) string {
|
|
|
|
hasher := md5.New()
|
|
|
|
hasher.Write([]byte(strings.ToLower(text)))
|
|
|
|
return fmt.Sprintf("https://secure.gravatar.com/avatar/%x?s=90&default=mm", hasher.Sum(nil))
|
|
|
|
}
|