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
de0f04ec
Commit
de0f04ec
authored
Aug 28, 2015
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(signup): progress on new sign up and email verification flow, #2353
parent
c61b22ce
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
62 additions
and
19 deletions
+62
-19
pkg/api/dtos/user.go
+1
-0
pkg/api/org_invite.go
+2
-4
pkg/api/signup.go
+28
-4
pkg/events/events.go
+0
-2
pkg/models/temp_user.go
+2
-2
pkg/models/user.go
+1
-0
pkg/services/sqlstore/temp_user.go
+18
-5
pkg/services/sqlstore/temp_user_test.go
+10
-2
No files found.
pkg/api/dtos/user.go
View file @
de0f04ec
...
@@ -8,6 +8,7 @@ type SignUpStep2Form struct {
...
@@ -8,6 +8,7 @@ type SignUpStep2Form struct {
Email
string
`json:"email"`
Email
string
`json:"email"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Username
string
`json:"username"`
Username
string
`json:"username"`
Password
string
`json:"password"`
Code
string
`json:"code"`
Code
string
`json:"code"`
OrgName
string
`json:"orgName"`
OrgName
string
`json:"orgName"`
}
}
...
...
pkg/api/org_invite.go
View file @
de0f04ec
...
@@ -14,7 +14,7 @@ import (
...
@@ -14,7 +14,7 @@ import (
)
)
func
GetPendingOrgInvites
(
c
*
middleware
.
Context
)
Response
{
func
GetPendingOrgInvites
(
c
*
middleware
.
Context
)
Response
{
query
:=
m
.
GetTempUsers
ForOrg
Query
{
OrgId
:
c
.
OrgId
,
Status
:
m
.
TmpUserInvitePending
}
query
:=
m
.
GetTempUsersQuery
{
OrgId
:
c
.
OrgId
,
Status
:
m
.
TmpUserInvitePending
}
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to get invites from db"
,
err
)
return
ApiError
(
500
,
"Failed to get invites from db"
,
err
)
...
@@ -172,10 +172,8 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
...
@@ -172,10 +172,8 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
user
:=
cmd
.
Result
user
:=
cmd
.
Result
bus
.
Publish
(
&
events
.
SignUpCompleted
{
bus
.
Publish
(
&
events
.
SignUpCompleted
{
Id
:
user
.
Id
,
Name
:
user
.
NameOrFallback
(),
Name
:
user
.
Name
,
Email
:
user
.
Email
,
Email
:
user
.
Email
,
Login
:
user
.
Login
,
})
})
// add to org
// add to org
...
...
pkg/api/signup.go
View file @
de0f04ec
...
@@ -34,15 +34,11 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
...
@@ -34,15 +34,11 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
return
ApiError
(
500
,
"Failed to create signup"
,
err
)
return
ApiError
(
500
,
"Failed to create signup"
,
err
)
}
}
// user := cmd.Resu
bus
.
Publish
(
&
events
.
SignUpStarted
{
bus
.
Publish
(
&
events
.
SignUpStarted
{
Email
:
form
.
Email
,
Email
:
form
.
Email
,
Code
:
cmd
.
Code
,
Code
:
cmd
.
Code
,
})
})
// loginUserWithUser(&user, c)
metrics
.
M_Api_User_SignUpStarted
.
Inc
(
1
)
metrics
.
M_Api_User_SignUpStarted
.
Inc
(
1
)
return
Json
(
200
,
util
.
DynMap
{
"status"
:
"SignUpCreated"
})
return
Json
(
200
,
util
.
DynMap
{
"status"
:
"SignUpCreated"
})
...
@@ -72,5 +68,33 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
...
@@ -72,5 +68,33 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
return
ApiError
(
401
,
"User with same email address already exists"
,
nil
)
return
ApiError
(
401
,
"User with same email address already exists"
,
nil
)
}
}
// create user
createUserCmd
:=
m
.
CreateUserCommand
{
Email
:
tempUser
.
Email
,
Login
:
form
.
Username
,
Name
:
form
.
Name
,
Password
:
form
.
Password
,
OrgName
:
form
.
OrgName
,
}
if
err
:=
bus
.
Dispatch
(
&
createUserCmd
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to create user"
,
err
)
}
user
:=
createUserCmd
.
Result
bus
.
Publish
(
&
events
.
SignUpCompleted
{
Email
:
user
.
Email
,
Name
:
user
.
NameOrFallback
(),
})
// check for pending invites
invitesQuery
:=
m
.
GetTempUsersQuery
{
Email
:
tempUser
.
Email
,
Status
:
m
.
TmpUserInvitePending
}
if
err
:=
bus
.
Dispatch
(
&
invitesQuery
);
err
!=
nil
{
return
ApiError
(
500
,
"Failed to query database for invites"
,
err
)
}
loginUserWithUser
(
&
user
,
c
)
metrics
.
M_Api_User_SignUpCompleted
.
Inc
(
1
)
return
Json
(
200
,
util
.
DynMap
{
"status"
:
"SignUpCreated"
})
return
Json
(
200
,
util
.
DynMap
{
"status"
:
"SignUpCreated"
})
}
}
pkg/events/events.go
View file @
de0f04ec
...
@@ -78,9 +78,7 @@ type SignUpStarted struct {
...
@@ -78,9 +78,7 @@ type SignUpStarted struct {
type
SignUpCompleted
struct
{
type
SignUpCompleted
struct
{
Timestamp
time
.
Time
`json:"timestamp"`
Timestamp
time
.
Time
`json:"timestamp"`
Id
int64
`json:"id"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Login
string
`json:"login"`
Email
string
`json:"email"`
Email
string
`json:"email"`
}
}
...
...
pkg/models/temp_user.go
View file @
de0f04ec
...
@@ -16,7 +16,6 @@ const (
...
@@ -16,7 +16,6 @@ const (
TmpUserSignUpStarted
TempUserStatus
=
"SignUpStarted"
TmpUserSignUpStarted
TempUserStatus
=
"SignUpStarted"
TmpUserInvitePending
TempUserStatus
=
"InvitePending"
TmpUserInvitePending
TempUserStatus
=
"InvitePending"
TmpUserCompleted
TempUserStatus
=
"Completed"
TmpUserCompleted
TempUserStatus
=
"Completed"
TmpUserEmailPending
TempUserStatus
=
"EmailPending"
TmpUserRevoked
TempUserStatus
=
"Revoked"
TmpUserRevoked
TempUserStatus
=
"Revoked"
)
)
...
@@ -61,8 +60,9 @@ type UpdateTempUserStatusCommand struct {
...
@@ -61,8 +60,9 @@ type UpdateTempUserStatusCommand struct {
Status
TempUserStatus
Status
TempUserStatus
}
}
type
GetTempUsers
ForOrg
Query
struct
{
type
GetTempUsersQuery
struct
{
OrgId
int64
OrgId
int64
Email
string
Status
TempUserStatus
Status
TempUserStatus
Result
[]
*
TempUserDTO
Result
[]
*
TempUserDTO
...
...
pkg/models/user.go
View file @
de0f04ec
...
@@ -48,6 +48,7 @@ type CreateUserCommand struct {
...
@@ -48,6 +48,7 @@ type CreateUserCommand struct {
Login
string
`json:"login"`
Login
string
`json:"login"`
Name
string
`json:"name"`
Name
string
`json:"name"`
Company
string
`json:"compay"`
Company
string
`json:"compay"`
OrgName
string
`json:"orgName"`
Password
string
`json:"password" binding:"Required"`
Password
string
`json:"password" binding:"Required"`
IsAdmin
bool
`json:"-"`
IsAdmin
bool
`json:"-"`
...
...
pkg/services/sqlstore/temp_user.go
View file @
de0f04ec
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
func
init
()
{
func
init
()
{
bus
.
AddHandler
(
"sql"
,
CreateTempUser
)
bus
.
AddHandler
(
"sql"
,
CreateTempUser
)
bus
.
AddHandler
(
"sql"
,
GetTempUsers
ForOrg
)
bus
.
AddHandler
(
"sql"
,
GetTempUsers
Query
)
bus
.
AddHandler
(
"sql"
,
UpdateTempUserStatus
)
bus
.
AddHandler
(
"sql"
,
UpdateTempUserStatus
)
bus
.
AddHandler
(
"sql"
,
GetTempUserByCode
)
bus
.
AddHandler
(
"sql"
,
GetTempUserByCode
)
}
}
...
@@ -49,8 +49,8 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
...
@@ -49,8 +49,8 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
})
})
}
}
func
GetTempUsers
ForOrg
(
query
*
m
.
GetTempUsersForOrg
Query
)
error
{
func
GetTempUsers
Query
(
query
*
m
.
GetTempUsers
Query
)
error
{
var
rawSql
=
`SELECT
rawSql
:
=
`SELECT
tu.id as id,
tu.id as id,
tu.org_id as org_id,
tu.org_id as org_id,
tu.email as email,
tu.email as email,
...
@@ -66,10 +66,23 @@ func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
...
@@ -66,10 +66,23 @@ func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
u.email as invited_by_email
u.email as invited_by_email
FROM `
+
dialect
.
Quote
(
"temp_user"
)
+
` as tu
FROM `
+
dialect
.
Quote
(
"temp_user"
)
+
` as tu
LEFT OUTER JOIN `
+
dialect
.
Quote
(
"user"
)
+
` as u on u.id = tu.invited_by_user_id
LEFT OUTER JOIN `
+
dialect
.
Quote
(
"user"
)
+
` as u on u.id = tu.invited_by_user_id
WHERE tu.org_id=? AND tu.status =? ORDER BY tu.created desc`
WHERE tu.status=?`
params
:=
[]
interface
{}{
string
(
query
.
Status
)}
if
query
.
OrgId
>
0
{
rawSql
+=
` AND tu.org_id=?`
params
=
append
(
params
,
query
.
OrgId
)
}
if
query
.
Email
!=
""
{
rawSql
+=
` AND tu.email=?`
params
=
append
(
params
,
query
.
Email
)
}
rawSql
+=
" ORDER BY tu.created desc"
query
.
Result
=
make
([]
*
m
.
TempUserDTO
,
0
)
query
.
Result
=
make
([]
*
m
.
TempUserDTO
,
0
)
sess
:=
x
.
Sql
(
rawSql
,
query
.
OrgId
,
string
(
query
.
Status
)
)
sess
:=
x
.
Sql
(
rawSql
,
params
...
)
err
:=
sess
.
Find
(
&
query
.
Result
)
err
:=
sess
.
Find
(
&
query
.
Result
)
return
err
return
err
}
}
...
...
pkg/services/sqlstore/temp_user_test.go
View file @
de0f04ec
...
@@ -25,8 +25,16 @@ func TestTempUserCommandsAndQueries(t *testing.T) {
...
@@ -25,8 +25,16 @@ func TestTempUserCommandsAndQueries(t *testing.T) {
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
Convey
(
"Should be able to get temp users by org id"
,
func
()
{
Convey
(
"Should be able to get temp users by org id"
,
func
()
{
query
:=
m
.
GetTempUsersForOrgQuery
{
OrgId
:
2256
,
Status
:
m
.
TmpUserInvitePending
}
query
:=
m
.
GetTempUsersQuery
{
OrgId
:
2256
,
Status
:
m
.
TmpUserInvitePending
}
err
=
GetTempUsersForOrg
(
&
query
)
err
=
GetTempUsersQuery
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
})
Convey
(
"Should be able to get temp users by email"
,
func
()
{
query
:=
m
.
GetTempUsersQuery
{
Email
:
"e@as.co"
,
Status
:
m
.
TmpUserInvitePending
}
err
=
GetTempUsersQuery
(
&
query
)
So
(
err
,
ShouldBeNil
)
So
(
err
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
...
...
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