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
40ff57d8
Commit
40ff57d8
authored
Sep 20, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Account stuff
parent
cdabe503
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
42 additions
and
24 deletions
+42
-24
pkg/api/api.go
+1
-1
pkg/api/api_account.go
+6
-2
pkg/api/api_auth.go
+2
-2
pkg/api/api_login.go
+1
-1
pkg/api/api_register.go
+2
-2
pkg/api/api_routing.go
+2
-2
pkg/models/account.go
+2
-2
pkg/stores/rethinkdb_accounts.go
+18
-5
pkg/stores/rethinkdb_test.go
+4
-4
pkg/stores/store.go
+4
-3
No files found.
pkg/api/api.go
View file @
40ff57d8
...
...
@@ -64,7 +64,7 @@ func (self *HttpServer) index(c *gin.Context) {
viewModel
:=
&
IndexDto
{}
userAccount
,
_
:=
c
.
Get
(
"userAccount"
)
if
userAccount
!=
nil
{
viewModel
.
User
.
Login
=
userAccount
.
(
*
models
.
User
Account
)
.
Login
viewModel
.
User
.
Login
=
userAccount
.
(
*
models
.
Account
)
.
Login
}
c
.
HTML
(
200
,
"index.html"
,
viewModel
)
...
...
pkg/api/api_account.go
View file @
40ff57d8
...
...
@@ -20,7 +20,7 @@ func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
return
}
collaborator
,
err
:=
self
.
store
.
Get
UserAccount
Login
(
model
.
Email
)
collaborator
,
err
:=
self
.
store
.
Get
AccountBy
Login
(
model
.
Email
)
if
err
!=
nil
{
c
.
JSON
(
404
,
gin
.
H
{
"status"
:
"Collaborator not found"
})
return
...
...
@@ -39,7 +39,11 @@ func (self *HttpServer) addCollaborator(c *gin.Context, auth *authContext) {
return
}
self
.
store
.
SaveUserAccount
(
userAccount
)
err
=
self
.
store
.
UpdateAccount
(
userAccount
)
if
err
!=
nil
{
c
.
JSON
(
500
,
gin
.
H
{
"status"
:
err
.
Error
()})
return
}
c
.
JSON
(
200
,
gin
.
H
{
"status"
:
"Collaborator added"
})
}
pkg/api/api_auth.go
View file @
40ff57d8
...
...
@@ -6,8 +6,8 @@ import (
)
type
authContext
struct
{
account
*
models
.
User
Account
userAccount
*
models
.
User
Account
account
*
models
.
Account
userAccount
*
models
.
Account
}
func
(
auth
*
authContext
)
getAccountId
()
int
{
...
...
pkg/api/api_login.go
View file @
40ff57d8
...
...
@@ -24,7 +24,7 @@ func (self *HttpServer) loginPost(c *gin.Context) {
return
}
account
,
err
:=
self
.
store
.
Get
UserAccount
Login
(
loginModel
.
Email
)
account
,
err
:=
self
.
store
.
Get
AccountBy
Login
(
loginModel
.
Email
)
if
err
!=
nil
{
c
.
JSON
(
400
,
gin
.
H
{
"status"
:
"some error"
})
}
...
...
pkg/api/api_register.go
View file @
40ff57d8
...
...
@@ -27,14 +27,14 @@ func (self *HttpServer) registerUserPost(c *gin.Context) {
return
}
account
:=
models
.
User
Account
{
account
:=
models
.
Account
{
UserName
:
registerModel
.
Email
,
Login
:
registerModel
.
Email
,
Email
:
registerModel
.
Email
,
Password
:
registerModel
.
Password
,
}
err
:=
self
.
store
.
SaveUser
Account
(
&
account
)
err
:=
self
.
store
.
Create
Account
(
&
account
)
if
err
!=
nil
{
log
.
Error
(
"Failed to create user account, email: %v, error: %v"
,
registerModel
.
Email
,
err
)
c
.
JSON
(
500
,
gin
.
H
{
"status"
:
"failed to create account"
})
...
...
pkg/api/api_routing.go
View file @
40ff57d8
...
...
@@ -13,8 +13,8 @@ var routeHandlers = make([]routeHandlerRegisterFn, 0)
func
getRouteHandlerWrapper
(
handler
routeHandlerFn
)
gin
.
HandlerFunc
{
return
func
(
c
*
gin
.
Context
)
{
authContext
:=
authContext
{
account
:
c
.
MustGet
(
"usingAccount"
)
.
(
*
models
.
User
Account
),
userAccount
:
c
.
MustGet
(
"userAccount"
)
.
(
*
models
.
User
Account
),
account
:
c
.
MustGet
(
"usingAccount"
)
.
(
*
models
.
Account
),
userAccount
:
c
.
MustGet
(
"userAccount"
)
.
(
*
models
.
Account
),
}
handler
(
c
,
&
authContext
)
}
...
...
pkg/models/account.go
View file @
40ff57d8
...
...
@@ -12,7 +12,7 @@ type CollaboratorLink struct {
CreatedOn
time
.
Time
}
type
User
Account
struct
{
type
Account
struct
{
Id
int
`gorethink:"id"`
UserName
string
Login
string
...
...
@@ -25,7 +25,7 @@ type UserAccount struct {
ModifiedOn
time
.
Time
}
func
(
account
*
User
Account
)
AddCollaborator
(
accountId
int
)
error
{
func
(
account
*
Account
)
AddCollaborator
(
accountId
int
)
error
{
for
_
,
collaborator
:=
range
account
.
Collaborators
{
if
collaborator
.
AccountId
==
accountId
{
return
errors
.
New
(
"Collaborator already exists"
)
...
...
pkg/stores/rethinkdb_accounts.go
View file @
40ff57d8
...
...
@@ -25,7 +25,7 @@ func (self *rethinkStore) getNextAccountId() (int, error) {
return
int
(
change
.
NewValue
.
(
map
[
string
]
interface
{})[
"NextAccountId"
]
.
(
float64
)),
nil
}
func
(
self
*
rethinkStore
)
SaveUserAccount
(
account
*
models
.
User
Account
)
error
{
func
(
self
*
rethinkStore
)
CreateAccount
(
account
*
models
.
Account
)
error
{
accountId
,
err
:=
self
.
getNextAccountId
()
if
err
!=
nil
{
return
err
...
...
@@ -46,14 +46,14 @@ func (self *rethinkStore) SaveUserAccount(account *models.UserAccount) error {
return
nil
}
func
(
self
*
rethinkStore
)
Get
UserAccountLogin
(
emailOrName
string
)
(
*
models
.
User
Account
,
error
)
{
func
(
self
*
rethinkStore
)
Get
AccountByLogin
(
emailOrName
string
)
(
*
models
.
Account
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
GetAllByIndex
(
"AccountLogin"
,
[]
interface
{}{
emailOrName
})
.
Run
(
self
.
session
)
if
err
!=
nil
{
return
nil
,
err
}
var
account
models
.
User
Account
var
account
models
.
Account
err
=
resp
.
One
(
&
account
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Not found"
)
...
...
@@ -62,14 +62,14 @@ func (self *rethinkStore) GetUserAccountLogin(emailOrName string) (*models.UserA
return
&
account
,
nil
}
func
(
self
*
rethinkStore
)
GetAccount
(
id
int
)
(
*
models
.
User
Account
,
error
)
{
func
(
self
*
rethinkStore
)
GetAccount
(
id
int
)
(
*
models
.
Account
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
id
)
.
Run
(
self
.
session
)
if
err
!=
nil
{
return
nil
,
err
}
var
account
models
.
User
Account
var
account
models
.
Account
err
=
resp
.
One
(
&
account
)
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"Not found"
)
...
...
@@ -78,6 +78,19 @@ func (self *rethinkStore) GetAccount(id int) (*models.UserAccount, error) {
return
&
account
,
nil
}
func
(
self
*
rethinkStore
)
UpdateAccount
(
account
*
models
.
Account
)
error
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Update
(
account
)
.
RunWrite
(
self
.
session
)
if
err
!=
nil
{
return
err
}
if
resp
.
Replaced
!=
1
{
return
errors
.
New
(
"Could not fund account to uodate"
)
}
return
nil
}
func
(
self
*
rethinkStore
)
getNextDashboardNumber
(
accountId
int
)
(
int
,
error
)
{
resp
,
err
:=
r
.
Table
(
"accounts"
)
.
Get
(
accountId
)
.
Update
(
map
[
string
]
interface
{}{
"NextDashboardId"
:
r
.
Row
.
Field
(
"NextDashboardId"
)
.
Add
(
1
),
...
...
pkg/stores/rethinkdb_test.go
View file @
40ff57d8
...
...
@@ -35,8 +35,8 @@ func TestRethinkStore(t *testing.T) {
})
Convey
(
"can create account"
,
t
,
func
()
{
account
:=
&
models
.
User
Account
{
UserName
:
"torkelo"
,
Email
:
"mupp"
,
Login
:
"test@test.com"
}
err
:=
store
.
SaveUser
Account
(
account
)
account
:=
&
models
.
Account
{
UserName
:
"torkelo"
,
Email
:
"mupp"
,
Login
:
"test@test.com"
}
err
:=
store
.
Create
Account
(
account
)
So
(
err
,
ShouldBeNil
)
So
(
account
.
Id
,
ShouldNotEqual
,
0
)
...
...
@@ -46,8 +46,8 @@ func TestRethinkStore(t *testing.T) {
})
Convey
(
"can get next dashboard id"
,
t
,
func
()
{
account
:=
&
models
.
User
Account
{
UserName
:
"torkelo"
,
Email
:
"mupp"
}
err
:=
store
.
SaveUser
Account
(
account
)
account
:=
&
models
.
Account
{
UserName
:
"torkelo"
,
Email
:
"mupp"
}
err
:=
store
.
Create
Account
(
account
)
dashId
,
err
:=
store
.
getNextDashboardNumber
(
account
.
Id
)
So
(
err
,
ShouldBeNil
)
So
(
dashId
,
ShouldEqual
,
1
)
...
...
pkg/stores/store.go
View file @
40ff57d8
...
...
@@ -9,9 +9,10 @@ type Store interface {
SaveDashboard
(
dash
*
models
.
Dashboard
)
error
DeleteDashboard
(
slug
string
,
accountId
int
)
error
Query
(
query
string
,
acccountId
int
)
([]
*
models
.
SearchResult
,
error
)
SaveUserAccount
(
acccount
*
models
.
UserAccount
)
error
GetUserAccountLogin
(
emailOrName
string
)
(
*
models
.
UserAccount
,
error
)
GetAccount
(
id
int
)
(
*
models
.
UserAccount
,
error
)
CreateAccount
(
acccount
*
models
.
Account
)
error
UpdateAccount
(
acccount
*
models
.
Account
)
error
GetAccountByLogin
(
emailOrName
string
)
(
*
models
.
Account
,
error
)
GetAccount
(
id
int
)
(
*
models
.
Account
,
error
)
Close
()
}
...
...
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