Commit d25624a8 by Torkel Ödegaard

feat(signup): began work on new / alternate signup flow that includes email verification, #2353

parent 7e44a8ed
package dtos package dtos
type SignUpForm struct {
Email string `json:"email" binding:"Required"`
}
type AdminCreateUserForm struct { type AdminCreateUserForm struct {
Email string `json:"email"` Email string `json:"email"`
Login string `json:"login"` Login string `json:"login"`
......
...@@ -171,7 +171,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor ...@@ -171,7 +171,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
user := cmd.Result user := cmd.Result
bus.Publish(&events.UserSignedUp{ bus.Publish(&events.SignUpCompleted{
Id: user.Id, Id: user.Id,
Name: user.Name, Name: user.Name,
Email: user.Email, Email: user.Email,
...@@ -199,7 +199,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor ...@@ -199,7 +199,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
loginUserWithUser(&user, c) loginUserWithUser(&user, c)
metrics.M_Api_User_SignUp.Inc(1) metrics.M_Api_User_SignUpCompleted.Inc(1)
metrics.M_Api_User_SignUpInvite.Inc(1) metrics.M_Api_User_SignUpInvite.Inc(1)
return ApiSuccess("User created and logged in") return ApiSuccess("User created and logged in")
......
package api package api
import ( import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/metrics" "github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware" "github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models" m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting" "github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
) )
// POST /api/user/signup // POST /api/user/signup
func SignUp(c *middleware.Context, cmd m.CreateUserCommand) Response { func SignUp(c *middleware.Context, form dtos.SignUpForm) Response {
if !setting.AllowUserSignUp { if !setting.AllowUserSignUp {
return ApiError(401, "User signup is disabled", nil) return ApiError(401, "User signup is disabled", nil)
} }
cmd.Login = cmd.Email existing := m.GetUserByLoginQuery{LoginOrEmail: form.Email}
if err := bus.Dispatch(&existing); err == nil {
return ApiError(401, "User with same email address already exists", nil)
}
cmd := m.CreateTempUserCommand{}
cmd.OrgId = -1
cmd.Email = form.Email
cmd.Status = m.TmpUserSignUpStarted
cmd.InvitedByUserId = c.UserId
cmd.Code = util.GetRandomString(10)
cmd.RemoteAddr = c.Req.RemoteAddr
if err := bus.Dispatch(&cmd); err != nil { if err := bus.Dispatch(&cmd); err != nil {
return ApiError(500, "failed to create user", err) return ApiError(500, "Failed to create signup", err)
} }
user := cmd.Result // user := cmd.Resu
bus.Publish(&events.UserSignedUp{
Id: user.Id,
Name: user.Name,
Email: user.Email,
Login: user.Login,
})
loginUserWithUser(&user, c) bus.Publish(&events.UserSignedUp{Email: form.Email})
metrics.M_Api_User_SignUp.Inc(1) //
// loginUserWithUser(&user, c)
//
//
metrics.M_Api_User_SignUpStarted.Inc(1)
return ApiSuccess("User created and logged in") return ApiSuccess("User created and logged in")
} }
...@@ -78,6 +78,14 @@ type UserSignedUp struct { ...@@ -78,6 +78,14 @@ type UserSignedUp struct {
Email string `json:"email"` Email string `json:"email"`
} }
type SignUpCompleted struct {
Timestamp time.Time `json:"timestamp"`
Id int64 `json:"id"`
Name string `json:"name"`
Login string `json:"login"`
Email string `json:"email"`
}
type UserUpdated struct { type UserUpdated struct {
Timestamp time.Time `json:"timestamp"` Timestamp time.Time `json:"timestamp"`
Id int64 `json:"id"` Id int64 `json:"id"`
......
...@@ -13,7 +13,8 @@ var ( ...@@ -13,7 +13,8 @@ var (
M_Api_Status_500 = NewComboCounterRef("api.status.500") M_Api_Status_500 = NewComboCounterRef("api.status.500")
M_Api_Status_404 = NewComboCounterRef("api.status.404") M_Api_Status_404 = NewComboCounterRef("api.status.404")
M_Api_User_SignUp = NewComboCounterRef("api.user.signup") M_Api_User_SignUpStarted = NewComboCounterRef("api.user.signup_started")
M_Api_User_SignUpCompleted = NewComboCounterRef("api.user.signup_completed")
M_Api_User_SignUpInvite = NewComboCounterRef("api.user.signup_invite") M_Api_User_SignUpInvite = NewComboCounterRef("api.user.signup_invite")
M_Api_Dashboard_Get = NewComboCounterRef("api.dashboard.get") M_Api_Dashboard_Get = NewComboCounterRef("api.dashboard.get")
M_Api_Dashboard_Post = NewComboCounterRef("api.dashboard.post") M_Api_Dashboard_Post = NewComboCounterRef("api.dashboard.post")
......
...@@ -13,6 +13,7 @@ var ( ...@@ -13,6 +13,7 @@ var (
type TempUserStatus string type TempUserStatus string
const ( const (
TmpUserSignUpStarted TempUserStatus = "SignUpStarted"
TmpUserInvitePending TempUserStatus = "InvitePending" TmpUserInvitePending TempUserStatus = "InvitePending"
TmpUserCompleted TempUserStatus = "Completed" TmpUserCompleted TempUserStatus = "Completed"
TmpUserEmailPending TempUserStatus = "EmailPending" TmpUserEmailPending TempUserStatus = "EmailPending"
......
...@@ -131,7 +131,7 @@ func userSignedUpHandler(evt *events.UserSignedUp) error { ...@@ -131,7 +131,7 @@ func userSignedUpHandler(evt *events.UserSignedUp) error {
To: []string{evt.Email}, To: []string{evt.Email},
Template: tmplWelcomeOnSignUp, Template: tmplWelcomeOnSignUp,
Data: map[string]interface{}{ Data: map[string]interface{}{
"Name": evt.Login, "Email": evt.Email,
}, },
}) })
} }
...@@ -79,6 +79,7 @@ var ( ...@@ -79,6 +79,7 @@ var (
AllowUserOrgCreate bool AllowUserOrgCreate bool
AutoAssignOrg bool AutoAssignOrg bool
AutoAssignOrgRole string AutoAssignOrgRole string
RequireEmailValidation bool
// Http auth // Http auth
AdminUser string AdminUser string
......
<div class="container"> <div class="container">
<div class="login-page-background">
</div>
<div class="login-box"> <div class="login-box">
......
<div class="container"> <div class="container">
<div class="login-page-background"> <div class="signup-page-background">
</div> </div>
<div class="login-box"> <div class="login-box">
......
...@@ -93,7 +93,7 @@ ...@@ -93,7 +93,7 @@
} }
} }
.login-page-background { .signup-page-background {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
...@@ -101,8 +101,8 @@ ...@@ -101,8 +101,8 @@
bottom: 0; bottom: 0;
height: 100%; height: 100%;
width: 100%; width: 100%;
background-image: url(/img/background_tease.jpg); background-image: url(../img/background_tease.jpg);
opacity: 0.05; opacity: 0.3;
z-index: -1; z-index: -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