feat(signup): progress on new sign up and email verification flow, #2353
This commit is contained in:
+2
-1
@@ -43,7 +43,8 @@ func Register(r *macaron.Macaron) {
|
||||
|
||||
// sign up
|
||||
r.Get("/signup", Index)
|
||||
r.Post("/api/user/signup", bind(m.CreateUserCommand{}), wrap(SignUp))
|
||||
r.Post("/api/user/signup", bind(dtos.SignUpForm{}), wrap(SignUp))
|
||||
r.Post("/api/user/signup/step2", bind(dtos.SignUpStep2Form{}), wrap(SignUpStep2))
|
||||
|
||||
// invited
|
||||
r.Get("/api/user/invite/:code", wrap(GetInviteInfoByCode))
|
||||
|
||||
@@ -4,6 +4,14 @@ type SignUpForm struct {
|
||||
Email string `json:"email" binding:"Required"`
|
||||
}
|
||||
|
||||
type SignUpStep2Form struct {
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Username string `json:"username"`
|
||||
Code string `json:"code"`
|
||||
OrgName string `json:"orgName"`
|
||||
}
|
||||
|
||||
type AdminCreateUserForm struct {
|
||||
Email string `json:"email"`
|
||||
Login string `json:"login"`
|
||||
|
||||
+34
-6
@@ -27,7 +27,7 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
|
||||
cmd.Email = form.Email
|
||||
cmd.Status = m.TmpUserSignUpStarted
|
||||
cmd.InvitedByUserId = c.UserId
|
||||
cmd.Code = util.GetRandomString(10)
|
||||
cmd.Code = util.GetRandomString(20)
|
||||
cmd.RemoteAddr = c.Req.RemoteAddr
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
@@ -36,13 +36,41 @@ func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
|
||||
|
||||
// user := cmd.Resu
|
||||
|
||||
bus.Publish(&events.UserSignedUp{Email: form.Email})
|
||||
bus.Publish(&events.SignUpStarted{
|
||||
Email: form.Email,
|
||||
Code: cmd.Code,
|
||||
})
|
||||
|
||||
//
|
||||
// loginUserWithUser(&user, c)
|
||||
//
|
||||
//
|
||||
|
||||
metrics.M_Api_User_SignUpStarted.Inc(1)
|
||||
return ApiSuccess("User created and logged in")
|
||||
|
||||
return Json(200, util.DynMap{"status": "SignUpCreated"})
|
||||
}
|
||||
|
||||
func SignUpStep2(c *middleware.Context, form dtos.SignUpStep2Form) Response {
|
||||
if !setting.AllowUserSignUp {
|
||||
return ApiError(401, "User signup is disabled", nil)
|
||||
}
|
||||
|
||||
query := m.GetTempUserByCodeQuery{Code: form.Code}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
if err == m.ErrTempUserNotFound {
|
||||
return ApiError(404, "Invalid email verification code", nil)
|
||||
}
|
||||
return ApiError(500, "Failed to read temp user", err)
|
||||
}
|
||||
|
||||
tempUser := query.Result
|
||||
if tempUser.Email != form.Email {
|
||||
return ApiError(404, "Email verification code does not match email", nil)
|
||||
}
|
||||
|
||||
existing := m.GetUserByLoginQuery{LoginOrEmail: tempUser.Email}
|
||||
if err := bus.Dispatch(&existing); err == nil {
|
||||
return ApiError(401, "User with same email address already exists", nil)
|
||||
}
|
||||
|
||||
return Json(200, util.DynMap{"status": "SignUpCreated"})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user