2014-11-21 23:43:04 +08:00
|
|
|
package dtos
|
2014-10-06 03:13:01 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/md5"
|
|
|
|
"fmt"
|
2017-12-21 04:20:12 +08:00
|
|
|
"regexp"
|
2014-10-06 03:13:01 +08:00
|
|
|
"strings"
|
|
|
|
|
2016-03-12 06:28:33 +08:00
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
2015-02-05 17:37:13 +08:00
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
2016-02-21 06:51:22 +08:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2014-10-06 03:13:01 +08:00
|
|
|
)
|
|
|
|
|
2016-03-10 17:31:10 +08:00
|
|
|
type AnyId struct {
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
}
|
|
|
|
|
2015-01-21 16:52:40 +08:00
|
|
|
type LoginCommand struct {
|
|
|
|
User string `json:"user" binding:"Required"`
|
|
|
|
Password string `json:"password" binding:"Required"`
|
|
|
|
Remember bool `json:"remember"`
|
2014-10-06 03:13:01 +08:00
|
|
|
}
|
|
|
|
|
2014-11-21 23:43:04 +08:00
|
|
|
type CurrentUser struct {
|
2018-04-30 21:34:31 +08:00
|
|
|
IsSignedIn bool `json:"isSignedIn"`
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
Login string `json:"login"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
LightTheme bool `json:"lightTheme"`
|
|
|
|
OrgCount int `json:"orgCount"`
|
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
OrgName string `json:"orgName"`
|
|
|
|
OrgRole m.RoleType `json:"orgRole"`
|
|
|
|
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
|
|
|
|
GravatarUrl string `json:"gravatarUrl"`
|
|
|
|
Timezone string `json:"timezone"`
|
|
|
|
Locale string `json:"locale"`
|
|
|
|
HelpFlags1 m.HelpFlags1 `json:"helpFlags1"`
|
|
|
|
HasEditPermissionInFolders bool `json:"hasEditPermissionInFolders"`
|
2014-10-06 03:13:01 +08:00
|
|
|
}
|
|
|
|
|
2016-09-28 00:17:39 +08:00
|
|
|
type MetricRequest struct {
|
|
|
|
From string `json:"from"`
|
|
|
|
To string `json:"to"`
|
|
|
|
Queries []*simplejson.Json `json:"queries"`
|
2019-06-25 14:52:17 +08:00
|
|
|
Debug bool `json:"debug"`
|
2015-01-06 16:11:00 +08:00
|
|
|
}
|
|
|
|
|
2015-02-03 00:17:57 +08:00
|
|
|
type UserStars struct {
|
|
|
|
DashboardIds map[string]bool `json:"dashboardIds"`
|
|
|
|
}
|
|
|
|
|
2015-01-16 21:32:18 +08:00
|
|
|
func GetGravatarUrl(text string) string {
|
2018-03-28 04:52:29 +08:00
|
|
|
if setting.DisableGravatar {
|
2018-06-04 22:03:59 +08:00
|
|
|
return setting.AppSubUrl + "/public/img/user_profile.png"
|
2018-03-28 04:52:29 +08:00
|
|
|
}
|
|
|
|
|
2015-01-16 21:32:18 +08:00
|
|
|
if text == "" {
|
|
|
|
return ""
|
2014-10-06 03:13:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
hasher := md5.New()
|
|
|
|
hasher.Write([]byte(strings.ToLower(text)))
|
2016-02-21 06:51:22 +08:00
|
|
|
return fmt.Sprintf(setting.AppSubUrl+"/avatar/%x", hasher.Sum(nil))
|
2014-10-06 03:13:01 +08:00
|
|
|
}
|
2017-12-21 04:20:12 +08:00
|
|
|
|
|
|
|
func GetGravatarUrlWithDefault(text string, defaultText string) string {
|
|
|
|
if text != "" {
|
|
|
|
return GetGravatarUrl(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
text = reg.ReplaceAllString(defaultText, "") + "@localhost"
|
|
|
|
|
|
|
|
return GetGravatarUrl(text)
|
|
|
|
}
|