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
e7ce371e
Commit
e7ce371e
authored
Aug 12, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on login && auth
parent
56d449b2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
26 deletions
+55
-26
backend/api/api.go
+2
-19
backend/api/api_dashboard.go
+1
-1
backend/api/api_login.go
+46
-0
backend/api/api_models.go
+5
-5
grafana
+1
-1
No files found.
backend/api/api.go
View file @
e7ce371e
...
...
@@ -55,9 +55,8 @@ func (self *HttpServer) ListenAndServe() {
}
// register default route
self
.
router
.
GET
(
"/"
,
self
.
AuthMiddleware
(),
self
.
index
)
self
.
router
.
GET
(
"/login/*_"
,
self
.
index
)
self
.
router
.
GET
(
"/dashboard/*_"
,
self
.
index
)
self
.
router
.
GET
(
"/"
,
self
.
authMiddleware
(),
self
.
index
)
self
.
router
.
GET
(
"/dashboard/*_"
,
self
.
authMiddleware
(),
self
.
index
)
self
.
router
.
Run
(
":"
+
self
.
port
)
}
...
...
@@ -66,22 +65,6 @@ func (self *HttpServer) index(c *gin.Context) {
c
.
HTML
(
200
,
"index.html"
,
&
indexViewModel
{
title
:
"hello from go"
})
}
func
(
self
*
HttpServer
)
login
(
c
*
gin
.
Context
)
{
c
.
HTML
(
200
,
"login.html"
,
&
indexViewModel
{
title
:
"hello from go"
})
}
func
(
self
*
HttpServer
)
AuthMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
// if session.Values["login"] == nil {
// c.Writer.Header().Set("Location", "/login/login#login")
// c.Abort(302)
// }
session
.
Values
[
"asd"
]
=
1
session
.
Save
(
c
.
Request
,
c
.
Writer
)
}
}
func
CacheHeadersMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
c
.
Writer
.
Header
()
.
Add
(
"Cache-Control"
,
"max-age=0, public, must-revalidate, proxy-revalidate"
)
...
...
backend/api/api_dashboard.go
View file @
e7ce371e
...
...
@@ -41,7 +41,7 @@ func (self *HttpServer) postDashboard(c *gin.Context) {
var
command
saveDashboardCommand
if
c
.
EnsureBody
(
&
command
)
{
err
:=
self
.
store
.
Save
(
&
models
.
Dashboard
{
Data
:
command
.
d
ashboard
})
err
:=
self
.
store
.
Save
(
&
models
.
Dashboard
{
Data
:
command
.
D
ashboard
})
if
err
==
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"saved"
})
return
...
...
backend/api/api_login.go
0 → 100644
View file @
e7ce371e
package
api
import
"github.com/gin-gonic/gin"
func
init
()
{
addRoutes
(
func
(
self
*
HttpServer
)
{
self
.
router
.
GET
(
"/login/*_"
,
self
.
index
)
self
.
router
.
POST
(
"/login"
,
self
.
loginPost
)
})
}
type
loginJsonModel
struct
{
Email
string
`json:"email" binding:"required"`
Password
string
`json:"password" binding:"required"`
Remember
bool
`json:"remember"`
}
func
(
self
*
HttpServer
)
loginPost
(
c
*
gin
.
Context
)
{
var
loginModel
loginJsonModel
if
c
.
EnsureBody
(
&
loginModel
)
{
if
loginModel
.
Email
==
"manu"
&&
loginModel
.
Password
==
"123"
{
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
session
.
Values
[
"login"
]
=
true
session
.
Save
(
c
.
Request
,
c
.
Writer
)
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"you are logged in"
})
}
else
{
c
.
JSON
(
401
,
gin
.
H
{
"status"
:
"unauthorized"
})
}
}
}
func
(
self
*
HttpServer
)
authMiddleware
()
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
session
,
_
:=
sessionStore
.
Get
(
c
.
Request
,
"grafana-session"
)
if
c
.
Request
.
URL
.
Path
!=
"/login"
&&
session
.
Values
[
"login"
]
==
nil
{
c
.
Writer
.
Header
()
.
Set
(
"Location"
,
"/login"
)
c
.
Abort
(
302
)
}
session
.
Save
(
c
.
Request
,
c
.
Writer
)
}
}
backend/api/api_models.go
View file @
e7ce371e
package
api
type
saveDashboardCommand
struct
{
i
d
string
`json:"id"`
t
itle
string
`json:"title"`
d
ashboard
map
[
string
]
interface
{}
I
d
string
`json:"id"`
T
itle
string
`json:"title"`
D
ashboard
map
[
string
]
interface
{}
}
type
errorResponse
struct
{
m
essage
string
`json:"message"`
M
essage
string
`json:"message"`
}
type
indexViewModel
struct
{
...
...
@@ -15,5 +15,5 @@ type indexViewModel struct {
}
func
newErrorResponse
(
message
string
)
*
errorResponse
{
return
&
errorResponse
{
m
essage
:
message
}
return
&
errorResponse
{
M
essage
:
message
}
}
grafana
@
bfe1ef07
Subproject commit
c690d4aae84fc39d7c4bf9a0a820a71f69059b78
Subproject commit
bfe1ef07330fcfcdbc3aa9ddd4eef827ee48f316
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