mirror of
https://github.com/grafana/grafana.git
synced 2024-12-27 09:21:35 -06:00
feat(signup): progress on new sign up and email verification flow, #2353
This commit is contained in:
parent
c61b22cefb
commit
de0f04ec3c
@ -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"`
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
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 {
|
||||
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
|
||||
|
@ -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"})
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
|
||||
|
@ -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 GetTempUsersForOrgQuery struct {
|
||||
type GetTempUsersQuery struct {
|
||||
OrgId int64
|
||||
Email string
|
||||
Status TempUserStatus
|
||||
|
||||
Result []*TempUserDTO
|
||||
|
@ -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:"-"`
|
||||
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func init() {
|
||||
bus.AddHandler("sql", CreateTempUser)
|
||||
bus.AddHandler("sql", GetTempUsersForOrg)
|
||||
bus.AddHandler("sql", GetTempUsersQuery)
|
||||
bus.AddHandler("sql", UpdateTempUserStatus)
|
||||
bus.AddHandler("sql", GetTempUserByCode)
|
||||
}
|
||||
@ -49,8 +49,8 @@ func CreateTempUser(cmd *m.CreateTempUserCommand) error {
|
||||
})
|
||||
}
|
||||
|
||||
func GetTempUsersForOrg(query *m.GetTempUsersForOrgQuery) error {
|
||||
var rawSql = `SELECT
|
||||
func GetTempUsersQuery(query *m.GetTempUsersQuery) 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
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user