Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
4eefa734
Commit
4eefa734
authored
Nov 20, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Progress on account and dashboard save/load
parent
00b4d233
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
68 additions
and
8 deletions
+68
-8
pkg/middleware/auth.go
+1
-0
pkg/routes/api/api_dashboard.go
+2
-3
pkg/routes/api/api_register.go
+38
-0
pkg/routes/index.go
+4
-0
pkg/routes/login/login_oauth.go
+1
-1
pkg/stores/sqlstore/sqlstore.go
+1
-0
pkg/stores/sqlstore/sqlstore_accounts.go
+7
-3
pkg/stores/sqlstore/sqlstore_dashboards.go
+11
-1
pkg/utils/json.go
+3
-0
No files found.
pkg/middleware/auth.go
View file @
4eefa734
...
...
@@ -6,6 +6,7 @@ import (
"github.com/Unknwon/macaron"
"github.com/macaron-contrib/session"
"github.com/torkelo/grafana-pro/pkg/models"
)
...
...
pkg/routes/api/api_dashboard.go
View file @
4eefa734
package
api
import
(
"github.com/gin-gonic/gin"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/routes/apimodel"
"github.com/torkelo/grafana-pro/pkg/utils"
)
func
GetDashboard
(
c
*
middleware
.
Context
)
{
...
...
@@ -88,5 +87,5 @@ func PostDashboard(c *middleware.Context) {
return
}
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"success"
,
"slug"
:
dashboard
.
Slug
})
c
.
JSON
(
200
,
utils
.
DynMap
{
"status"
:
"success"
,
"slug"
:
dashboard
.
Slug
})
}
pkg/routes/api/api_register.go
0 → 100644
View file @
4eefa734
package
api
import
(
"github.com/torkelo/grafana-pro/pkg/log"
"github.com/torkelo/grafana-pro/pkg/middleware"
"github.com/torkelo/grafana-pro/pkg/models"
"github.com/torkelo/grafana-pro/pkg/utils"
)
type
registerAccountJsonModel
struct
{
Email
string
`json:"email" binding:"required"`
Password
string
`json:"password" binding:"required"`
Password2
bool
`json:"remember2"`
}
func
CreateAccount
(
c
*
middleware
.
Context
)
{
var
registerModel
registerAccountJsonModel
if
!
c
.
JsonBody
(
&
registerModel
)
{
c
.
JSON
(
400
,
utils
.
DynMap
{
"status"
:
"bad request"
})
return
}
account
:=
models
.
Account
{
Login
:
registerModel
.
Email
,
Email
:
registerModel
.
Email
,
Password
:
registerModel
.
Password
,
}
err
:=
models
.
CreateAccount
(
&
account
)
if
err
!=
nil
{
log
.
Error
(
2
,
"Failed to create user account, email: %v, error: %v"
,
registerModel
.
Email
,
err
)
c
.
JSON
(
500
,
utils
.
DynMap
{
"status"
:
"failed to create account"
})
return
}
c
.
JSON
(
200
,
utils
.
DynMap
{
"status"
:
"ok"
})
}
pkg/routes/index.go
View file @
4eefa734
...
...
@@ -20,6 +20,10 @@ func Register(m *macaron.Macaron) {
m
.
Get
(
"/login"
,
Index
)
m
.
Get
(
"/login/:name"
,
login
.
OAuthLogin
)
// user register
m
.
Get
(
"/register/*_"
,
Index
)
m
.
Post
(
"/api/account"
,
api
.
CreateAccount
)
// dashboards
m
.
Get
(
"/dashboard/*"
,
auth
,
Index
)
m
.
Get
(
"/api/dashboards/:slug"
,
auth
,
api
.
GetDashboard
)
...
...
pkg/routes/login/login_oauth.go
View file @
4eefa734
...
...
@@ -53,7 +53,7 @@ func OAuthLogin(ctx *middleware.Context) {
// create account if missing
if
err
==
models
.
ErrAccountNotFound
{
account
=
&
models
.
Account
{
Login
:
userInfo
.
Login
,
Login
:
userInfo
.
Email
,
Email
:
userInfo
.
Email
,
Name
:
userInfo
.
Name
,
Company
:
userInfo
.
Company
,
...
...
pkg/stores/sqlstore/sqlstore.go
View file @
4eefa734
...
...
@@ -35,6 +35,7 @@ func Init() {
models
.
GetDashboard
=
GetDashboard
models
.
SaveDashboard
=
SaveDashboard
models
.
SearchQuery
=
SearchQuery
models
.
DeleteDashboard
=
DeleteDashboard
}
func
LoadModelsConfig
()
{
...
...
pkg/stores/sqlstore/sqlstore_accounts.go
View file @
4eefa734
...
...
@@ -27,8 +27,8 @@ func CreateAccount(account *models.Account) error {
func
GetAccount
(
id
int64
)
(
*
models
.
Account
,
error
)
{
var
err
error
account
:=
&
models
.
Account
{
Id
:
id
}
has
,
err
:=
x
.
Get
(
account
)
var
account
models
.
Account
has
,
err
:=
x
.
Id
(
id
)
.
Get
(
&
account
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -36,7 +36,11 @@ func GetAccount(id int64) (*models.Account, error) {
return
nil
,
models
.
ErrAccountNotFound
}
return
account
,
nil
if
account
.
UsingAccountId
==
0
{
account
.
UsingAccountId
=
account
.
Id
}
return
&
account
,
nil
}
func
GetAccountByLogin
(
emailOrLogin
string
)
(
*
models
.
Account
,
error
)
{
...
...
pkg/stores/sqlstore/sqlstore_dashboards.go
View file @
4eefa734
...
...
@@ -47,8 +47,18 @@ func SearchQuery(query string, accountId int64) ([]*models.SearchResult, error)
sess
:=
x
.
Limit
(
100
,
0
)
.
Where
(
"account_id=?"
,
accountId
)
sess
.
Table
(
"Dashboard"
)
var
results
[]
*
models
.
SearchResult
results
:=
make
([]
*
models
.
SearchResult
,
0
)
err
:=
sess
.
Find
(
&
results
)
return
results
,
err
}
func
DeleteDashboard
(
slug
string
,
accountId
int64
)
error
{
sess
:=
x
.
NewSession
()
defer
sess
.
Close
()
rawSql
:=
"DELETE FROM Dashboard WHERE account_id=? and slug=?"
_
,
err
:=
sess
.
Exec
(
rawSql
,
accountId
,
slug
)
return
err
}
pkg/utils/json.go
0 → 100644
View file @
4eefa734
package
utils
type
DynMap
map
[
string
]
interface
{}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment