Commit de0f04ec by Torkel Ödegaard

feat(signup): progress on new sign up and email verification flow, #2353

parent c61b22ce
...@@ -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"`
} }
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
) )
func GetPendingOrgInvites(c *middleware.Context) Response { func GetPendingOrgInvites(c *middleware.Context) Response {
query := m.GetTempUsersForOrgQuery{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
......
...@@ -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"})
} }
...@@ -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"`
} }
......
...@@ -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 GetTempUsersForOrgQuery struct { type GetTempUsersQuery struct {
OrgId int64 OrgId int64
Email string
Status TempUserStatus Status TempUserStatus
Result []*TempUserDTO Result []*TempUserDTO
......
...@@ -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:"-"`
......
...@@ -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", GetTempUsersForOrg) bus.AddHandler("sql", GetTempUsersQuery)
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 GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error { func GetTempUsersQuery(query *m.GetTempUsersQuery) 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
} }
......
...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment