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
3c8c5319
Commit
3c8c5319
authored
Jan 21, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sign up and login work
parent
4786e0f8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
24 additions
and
43 deletions
+24
-43
grafana
+1
-1
pkg/api/api.go
+2
-2
pkg/api/dtos/models.go
+4
-3
pkg/api/login.go
+4
-20
pkg/api/signup.go
+6
-8
pkg/models/user.go
+7
-7
pkg/services/sqlstore/migrations_test.go
+0
-2
No files found.
grafana
@
8ed92124
Subproject commit
3bf7f6ed5fa348d7983a4ae3bf17d280d5a5ed13
Subproject commit
8ed921240133c8638ecd0b2973bae36cdb5f6ccb
pkg/api/api.go
View file @
3c8c5319
...
@@ -19,7 +19,7 @@ func Register(r *macaron.Macaron) {
...
@@ -19,7 +19,7 @@ func Register(r *macaron.Macaron) {
// not logged in views
// not logged in views
r
.
Get
(
"/"
,
reqSignedIn
,
Index
)
r
.
Get
(
"/"
,
reqSignedIn
,
Index
)
r
.
Post
(
"/logout"
,
LogoutPost
)
r
.
Post
(
"/logout"
,
LogoutPost
)
r
.
Post
(
"/login"
,
LoginPost
)
r
.
Post
(
"/login"
,
bind
(
dtos
.
LoginCommand
{}),
LoginPost
)
r
.
Get
(
"/login/:name"
,
OAuthLogin
)
r
.
Get
(
"/login/:name"
,
OAuthLogin
)
r
.
Get
(
"/login"
,
Index
)
r
.
Get
(
"/login"
,
Index
)
...
@@ -35,7 +35,7 @@ func Register(r *macaron.Macaron) {
...
@@ -35,7 +35,7 @@ func Register(r *macaron.Macaron) {
// sign up
// sign up
r
.
Get
(
"/signup"
,
Index
)
r
.
Get
(
"/signup"
,
Index
)
r
.
P
ost
(
"/api/account/signup"
,
SignUp
)
r
.
P
ut
(
"/api/user/signup"
,
bind
(
m
.
CreateUserCommand
{})
,
SignUp
)
// authed api
// authed api
r
.
Group
(
"/api"
,
func
()
{
r
.
Group
(
"/api"
,
func
()
{
...
...
pkg/api/dtos/models.go
View file @
3c8c5319
...
@@ -8,9 +8,10 @@ import (
...
@@ -8,9 +8,10 @@ import (
m
"github.com/torkelo/grafana-pro/pkg/models"
m
"github.com/torkelo/grafana-pro/pkg/models"
)
)
type
LoginResult
struct
{
type
LoginCommand
struct
{
Status
string
`json:"status"`
User
string
`json:"user" binding:"Required"`
User
CurrentUser
`json:"user"`
Password
string
`json:"password" binding:"Required"`
Remember
bool
`json:"remember"`
}
}
type
CurrentUser
struct
{
type
CurrentUser
struct
{
...
...
pkg/api/login.go
View file @
3c8c5319
...
@@ -9,21 +9,9 @@ import (
...
@@ -9,21 +9,9 @@ import (
"github.com/torkelo/grafana-pro/pkg/util"
"github.com/torkelo/grafana-pro/pkg/util"
)
)
type
loginJsonModel
struct
{
func
LoginPost
(
c
*
middleware
.
Context
,
cmd
dtos
.
LoginCommand
)
{
Email
string
`json:"email" binding:"required"`
Password
string
`json:"password" binding:"required"`
Remember
bool
`json:"remember"`
}
func
LoginPost
(
c
*
middleware
.
Context
)
{
var
loginModel
loginJsonModel
if
!
c
.
JsonBody
(
&
loginModel
)
{
c
.
JSON
(
400
,
util
.
DynMap
{
"message"
:
"bad request"
})
return
}
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
loginModel
.
Email
}
userQuery
:=
m
.
GetUserByLoginQuery
{
LoginOrEmail
:
cmd
.
User
}
err
:=
bus
.
Dispatch
(
&
userQuery
)
err
:=
bus
.
Dispatch
(
&
userQuery
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -33,7 +21,7 @@ func LoginPost(c *middleware.Context) {
...
@@ -33,7 +21,7 @@ func LoginPost(c *middleware.Context) {
user
:=
userQuery
.
Result
user
:=
userQuery
.
Result
passwordHashed
:=
util
.
EncodePassword
(
loginModel
.
Password
,
user
.
Salt
)
passwordHashed
:=
util
.
EncodePassword
(
cmd
.
Password
,
user
.
Salt
)
if
passwordHashed
!=
user
.
Password
{
if
passwordHashed
!=
user
.
Password
{
c
.
JsonApiErr
(
401
,
"Invalid username or password"
,
err
)
c
.
JsonApiErr
(
401
,
"Invalid username or password"
,
err
)
return
return
...
@@ -41,11 +29,7 @@ func LoginPost(c *middleware.Context) {
...
@@ -41,11 +29,7 @@ func LoginPost(c *middleware.Context) {
loginUserWithUser
(
user
,
c
)
loginUserWithUser
(
user
,
c
)
var
resp
=
&
dtos
.
LoginResult
{}
c
.
JsonOK
(
"User logged in"
)
resp
.
Status
=
"Logged in"
resp
.
User
.
Login
=
user
.
Login
c
.
JSON
(
200
,
resp
)
}
}
func
loginUserWithUser
(
user
*
m
.
User
,
c
*
middleware
.
Context
)
{
func
loginUserWithUser
(
user
*
m
.
User
,
c
*
middleware
.
Context
)
{
...
...
pkg/api/signup.go
View file @
3c8c5319
...
@@ -8,13 +8,7 @@ import (
...
@@ -8,13 +8,7 @@ import (
)
)
// POST /api/account/signup
// POST /api/account/signup
func
SignUp
(
c
*
middleware
.
Context
)
{
func
SignUp
(
c
*
middleware
.
Context
,
cmd
m
.
CreateUserCommand
)
{
var
cmd
m
.
CreateUserCommand
if
!
c
.
JsonBody
(
&
cmd
)
{
c
.
JsonApiErr
(
400
,
"Validation error"
,
nil
)
return
}
cmd
.
Login
=
cmd
.
Email
cmd
.
Login
=
cmd
.
Email
cmd
.
Salt
=
util
.
GetRandomString
(
10
)
cmd
.
Salt
=
util
.
GetRandomString
(
10
)
...
@@ -25,5 +19,9 @@ func SignUp(c *middleware.Context) {
...
@@ -25,5 +19,9 @@ func SignUp(c *middleware.Context) {
return
return
}
}
c
.
JsonOK
(
"User created"
)
user
:=
cmd
.
Result
loginUserWithUser
(
&
user
,
c
)
c
.
JsonOK
(
"User created and logged in"
)
}
}
pkg/models/user.go
View file @
3c8c5319
...
@@ -30,13 +30,13 @@ type User struct {
...
@@ -30,13 +30,13 @@ type User struct {
// COMMANDS
// COMMANDS
type
CreateUserCommand
struct
{
type
CreateUserCommand
struct
{
Email
string
Email
string
`json:"email" binding:"Required"`
Login
string
Login
string
`json:"login"`
Name
string
Name
string
`json:"name"`
Company
string
Company
string
`json:"compay"`
Password
string
Password
string
`json:"password" binding:"Required"`
Salt
string
Salt
string
`json:"-"`
IsAdmin
bool
IsAdmin
bool
`json:"-"`
Result
User
`json:"-"`
Result
User
`json:"-"`
}
}
...
...
pkg/services/sqlstore/migrations_test.go
View file @
3c8c5319
...
@@ -20,8 +20,6 @@ func TestMigrations(t *testing.T) {
...
@@ -20,8 +20,6 @@ func TestMigrations(t *testing.T) {
testDBs
:=
[]
sqlutil
.
TestDB
{
testDBs
:=
[]
sqlutil
.
TestDB
{
sqlutil
.
TestDB_Sqlite3
,
sqlutil
.
TestDB_Sqlite3
,
// sqlutil.TestDB_Mysql,
// sqlutil.TestDB_Postgres,
}
}
for
_
,
testDB
:=
range
testDBs
{
for
_
,
testDB
:=
range
testDBs
{
...
...
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