Fixed hashing of passwords, Closes #3
This commit is contained in:
+2
-2
@@ -4,7 +4,7 @@ import (
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
func GetAccount(c *middleware.Context) {
|
||||
@@ -59,7 +59,7 @@ func GetOtherAccounts(c *middleware.Context) {
|
||||
err := bus.Dispatch(&query)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(500, utils.DynMap{"message": err.Error()})
|
||||
c.JSON(500, util.DynMap{"message": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+4
-44
@@ -1,13 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
func GetDashboard(c *middleware.Context) {
|
||||
@@ -29,15 +26,13 @@ func DeleteDashboard(c *middleware.Context) {
|
||||
slug := c.Params(":slug")
|
||||
|
||||
query := m.GetDashboardQuery{Slug: slug, AccountId: c.GetAccountId()}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
c.JsonApiErr(404, "Dashboard not found", nil)
|
||||
return
|
||||
}
|
||||
|
||||
cmd := m.DeleteDashboardCommand{Slug: slug, AccountId: c.GetAccountId()}
|
||||
err = bus.Dispatch(&cmd)
|
||||
if err != nil {
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
c.JsonApiErr(500, "Failed to delete dashboard", err)
|
||||
return
|
||||
}
|
||||
@@ -47,41 +42,6 @@ func DeleteDashboard(c *middleware.Context) {
|
||||
c.JSON(200, resp)
|
||||
}
|
||||
|
||||
func Search(c *middleware.Context) {
|
||||
queryText := c.Query("q")
|
||||
result := m.SearchResult{
|
||||
Dashboards: []*m.DashboardSearchHit{},
|
||||
Tags: []*m.DashboardTagCloudItem{},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(queryText, "tags!:") {
|
||||
query := m.GetDashboardTagsQuery{}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get tags from database", err)
|
||||
return
|
||||
}
|
||||
result.Tags = query.Result
|
||||
result.TagsOnly = true
|
||||
} else {
|
||||
searchQueryRegEx, _ := regexp.Compile(`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`)
|
||||
matches := searchQueryRegEx.FindStringSubmatch(queryText)
|
||||
query := m.SearchDashboardsQuery{
|
||||
Title: matches[3],
|
||||
Tag: matches[2],
|
||||
AccountId: c.GetAccountId(),
|
||||
}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Search failed", err)
|
||||
return
|
||||
}
|
||||
result.Dashboards = query.Result
|
||||
}
|
||||
|
||||
c.JSON(200, result)
|
||||
}
|
||||
|
||||
func PostDashboard(c *middleware.Context) {
|
||||
var cmd m.SaveDashboardCommand
|
||||
|
||||
@@ -102,5 +62,5 @@ func PostDashboard(c *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, utils.DynMap{"status": "success", "slug": cmd.Result.Slug})
|
||||
c.JSON(200, util.DynMap{"status": "success", "slug": cmd.Result.Slug})
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy {
|
||||
@@ -21,12 +21,12 @@ func NewReverseProxy(ds *m.DataSource, proxyPath string) *httputil.ReverseProxy
|
||||
reqQueryVals := req.URL.Query()
|
||||
|
||||
if ds.Type == m.DS_INFLUXDB {
|
||||
req.URL.Path = utils.JoinUrlFragments(target.Path, "db/"+ds.Database+"/"+proxyPath)
|
||||
req.URL.Path = util.JoinUrlFragments(target.Path, "db/"+ds.Database+"/"+proxyPath)
|
||||
reqQueryVals.Add("u", ds.User)
|
||||
reqQueryVals.Add("p", ds.Password)
|
||||
req.URL.RawQuery = reqQueryVals.Encode()
|
||||
} else {
|
||||
req.URL.Path = utils.JoinUrlFragments(target.Path, proxyPath)
|
||||
req.URL.Path = util.JoinUrlFragments(target.Path, proxyPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/torkelo/grafana-pro/pkg/log"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
type loginJsonModel struct {
|
||||
@@ -19,7 +19,7 @@ func LoginPost(c *middleware.Context) {
|
||||
var loginModel loginJsonModel
|
||||
|
||||
if !c.JsonBody(&loginModel) {
|
||||
c.JSON(400, utils.DynMap{"status": "bad request"})
|
||||
c.JSON(400, util.DynMap{"message": "bad request"})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@ func LoginPost(c *middleware.Context) {
|
||||
|
||||
account := userQuery.Result
|
||||
|
||||
if loginModel.Password != account.Password {
|
||||
passwordHashed := util.EncodePassword(loginModel.Password, account.Salt)
|
||||
if passwordHashed != account.Password {
|
||||
c.JsonApiErr(401, "Invalid username or password", err)
|
||||
return
|
||||
}
|
||||
@@ -57,5 +58,5 @@ func loginUserWithAccount(account *m.Account, c *middleware.Context) {
|
||||
|
||||
func LogoutPost(c *middleware.Context) {
|
||||
c.Session.Delete("accountId")
|
||||
c.JSON(200, utils.DynMap{"status": "logged out"})
|
||||
c.JSON(200, util.DynMap{"status": "logged out"})
|
||||
}
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
func CreateAccount(c *middleware.Context) {
|
||||
@@ -15,9 +16,10 @@ func CreateAccount(c *middleware.Context) {
|
||||
}
|
||||
|
||||
cmd.Login = cmd.Email
|
||||
err := bus.Dispatch(&cmd)
|
||||
cmd.Salt = util.GetRandomString(10)
|
||||
cmd.Password = util.EncodePassword(cmd.Password, cmd.Salt)
|
||||
|
||||
if err != nil {
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
c.JsonApiErr(500, "failed to create account", err)
|
||||
return
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,12 +6,12 @@ import (
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/components/renderer"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
"github.com/torkelo/grafana-pro/pkg/utils"
|
||||
"github.com/torkelo/grafana-pro/pkg/util"
|
||||
)
|
||||
|
||||
func RenderToPng(c *middleware.Context) {
|
||||
accountId := c.GetAccountId()
|
||||
queryReader := utils.NewUrlQueryReader(c.Req.URL)
|
||||
queryReader := util.NewUrlQueryReader(c.Req.URL)
|
||||
queryParams := "?render&accountId=" + strconv.FormatInt(accountId, 10) + "&" + c.Req.URL.RawQuery
|
||||
|
||||
renderOpts := &renderer.RenderOpts{
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/torkelo/grafana-pro/pkg/bus"
|
||||
"github.com/torkelo/grafana-pro/pkg/middleware"
|
||||
m "github.com/torkelo/grafana-pro/pkg/models"
|
||||
)
|
||||
|
||||
func Search(c *middleware.Context) {
|
||||
queryText := c.Query("q")
|
||||
result := m.SearchResult{
|
||||
Dashboards: []*m.DashboardSearchHit{},
|
||||
Tags: []*m.DashboardTagCloudItem{},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(queryText, "tags!:") {
|
||||
query := m.GetDashboardTagsQuery{}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Failed to get tags from database", err)
|
||||
return
|
||||
}
|
||||
result.Tags = query.Result
|
||||
result.TagsOnly = true
|
||||
} else {
|
||||
searchQueryRegEx, _ := regexp.Compile(`(tags:(\w*)\sAND\s)?(?:title:)?(.*)?`)
|
||||
matches := searchQueryRegEx.FindStringSubmatch(queryText)
|
||||
query := m.SearchDashboardsQuery{
|
||||
Title: matches[3],
|
||||
Tag: matches[2],
|
||||
AccountId: c.GetAccountId(),
|
||||
}
|
||||
err := bus.Dispatch(&query)
|
||||
if err != nil {
|
||||
c.JsonApiErr(500, "Search failed", err)
|
||||
return
|
||||
}
|
||||
result.Dashboards = query.Result
|
||||
}
|
||||
|
||||
c.JSON(200, result)
|
||||
}
|
||||
Reference in New Issue
Block a user