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
Hide 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 {
Email
string
`json:"email"`
Name
string
`json:"name"`
Username
string
`json:"username"`
Password
string
`json:"password"`
Code
string
`json:"code"`
OrgName
string
`json:"orgName"`
}
...
...
pkg/api/org_invite.go
View file @
de0f04ec
...
...
@@ -14,7 +14,7 @@ import (
)
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
{
return
ApiError
(
500
,
"Failed to get invites from db"
,
err
)
...
...
@@ -172,10 +172,8 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
user
:=
cmd
.
Result
bus
.
Publish
(
&
events
.
SignUpCompleted
{
Id
:
user
.
Id
,
Name
:
user
.
Name
,
Name
:
user
.
NameOrFallback
(),
Email
:
user
.
Email
,
Login
:
user
.
Login
,
})
// add to org
...
...
pkg/api/signup.go
View file @
de0f04ec
...
...
@@ -34,15 +34,11 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
return
ApiError
(
500
,
"Failed to create signup"
,
err
)
}
// user := cmd.Resu
bus
.
Publish
(
&
events
.
SignUpStarted
{
Email
:
form
.
Email
,
Code
:
cmd
.
Code
,
})
// loginUserWithUser(&user, c)
metrics
.
M_Api_User_SignUpStarted
.
Inc
(
1
)
return
Json
(
200
,
util
.
DynMap
{
"status"
:
"SignUpCreated"
})
...
...
@@ -72,5 +68,33 @@ func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
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"
})
}
pkg/events/events.go
View file @
de0f04ec
...
...
@@ -78,9 +78,7 @@ type SignUpStarted struct {
type
SignUpCompleted
struct
{
Timestamp
time
.
Time
`json:"timestamp"`
Id
int64
`json:"id"`
Name
string
`json:"name"`
Login
string
`json:"login"`
Email
string
`json:"email"`
}
...
...
pkg/models/temp_user.go
View file @
de0f04ec
...
...
@@ -16,7 +16,6 @@ const (
TmpUserSignUpStarted
TempUserStatus
=
"SignUpStarted"
TmpUserInvitePending
TempUserStatus
=
"InvitePending"
TmpUserCompleted
TempUserStatus
=
"Completed"
TmpUserEmailPending
TempUserStatus
=
"EmailPending"
TmpUserRevoked
TempUserStatus
=
"Revoked"
)
...
...
@@ -61,8 +60,9 @@ type UpdateTempUserStatusCommand struct {
Status
TempUserStatus
}
type
GetTempUsers
ForOrg
Query
struct
{
type
GetTempUsersQuery
struct
{
OrgId
int64
Email
string
Status
TempUserStatus
Result
[]
*
TempUserDTO
...
...
pkg/models/user.go
View file @
de0f04ec
...
...
@@ -48,6 +48,7 @@ type CreateUserCommand struct {
Login
string
`json:"login"`
Name
string
`json:"name"`
Company
string
`json:"compay"`
OrgName
string
`json:"orgName"`
Password
string
`json:"password" binding:"Required"`
IsAdmin
bool
`json:"-"`
...
...
pkg/services/sqlstore/temp_user.go
View file @
de0f04ec
...
...
@@ -10,7 +10,7 @@ import (
func
init
()
{
bus
.
AddHandler
(
"sql"
,
CreateTempUser
)
bus
.
AddHandler
(
"sql"
,
GetTempUsers
ForOrg
)
bus
.
AddHandler
(
"sql"
,
GetTempUsers
Query
)
bus
.
AddHandler
(
"sql"
,
UpdateTempUserStatus
)
bus
.
AddHandler
(
"sql"
,
GetTempUserByCode
)
}
...
...
@@ -49,8 +49,8 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
})
}
func
GetTempUsers
ForOrg
(
query
*
m
.
GetTempUsersForOrg
Query
)
error
{
var
rawSql
=
`SELECT
func
GetTempUsers
Query
(
query
*
m
.
GetTempUsers
Query
)
error
{
rawSql
:
=
`SELECT
tu.id as id,
tu.org_id as org_id,
tu.email as email,
...
...
@@ -66,10 +66,23 @@ func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
u.email as invited_by_email
FROM `
+
dialect
.
Quote
(
"temp_user"
)
+
` as tu
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
)
sess
:=
x
.
Sql
(
rawSql
,
query
.
OrgId
,
string
(
query
.
Status
)
)
sess
:=
x
.
Sql
(
rawSql
,
params
...
)
err
:=
sess
.
Find
(
&
query
.
Result
)
return
err
}
...
...
pkg/services/sqlstore/temp_user_test.go
View file @
de0f04ec
...
...
@@ -25,8 +25,16 @@ func TestTempUserCommandsAndQueries(t *testing.T) {
So
(
err
,
ShouldBeNil
)
Convey
(
"Should be able to get temp users by org id"
,
func
()
{
query
:=
m
.
GetTempUsersForOrgQuery
{
OrgId
:
2256
,
Status
:
m
.
TmpUserInvitePending
}
err
=
GetTempUsersForOrg
(
&
query
)
query
:=
m
.
GetTempUsersQuery
{
OrgId
:
2256
,
Status
:
m
.
TmpUserInvitePending
}
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
(
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