Commit d25624a8 by Torkel Ödegaard

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

parent 7e44a8ed
package dtos
type SignUpForm struct {
Email string `json:"email" binding:"Required"`
}
type AdminCreateUserForm struct {
Email string `json:"email"`
Login string `json:"login"`
......
......@@ -171,7 +171,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
user := cmd.Result
bus.Publish(&events.UserSignedUp{
bus.Publish(&events.SignUpCompleted{
Id: user.Id,
Name: user.Name,
Email: user.Email,
......@@ -199,7 +199,7 @@ func CompleteInvite(c *middleware.Context, completeInvite dtos.CompleteInviteFor
loginUserWithUser(&user, c)
metrics.M_Api_User_SignUp.Inc(1)
metrics.M_Api_User_SignUpCompleted.Inc(1)
metrics.M_Api_User_SignUpInvite.Inc(1)
return ApiSuccess("User created and logged in")
......
package api
import (
"github.com/grafana/grafana/pkg/api/dtos"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/events"
"github.com/grafana/grafana/pkg/metrics"
"github.com/grafana/grafana/pkg/middleware"
m "github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util"
)
// 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 {
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 {
return ApiError(500, "failed to create user", err)
return ApiError(500, "Failed to create signup", err)
}
user := cmd.Result
bus.Publish(&events.UserSignedUp{
Id: user.Id,
Name: user.Name,
Email: user.Email,
Login: user.Login,
})
// user := cmd.Resu
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")
}
......@@ -78,6 +78,14 @@ type UserSignedUp struct {
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 {
Timestamp time.Time `json:"timestamp"`
Id int64 `json:"id"`
......
......@@ -13,14 +13,15 @@ var (
M_Api_Status_500 = NewComboCounterRef("api.status.500")
M_Api_Status_404 = NewComboCounterRef("api.status.404")
M_Api_User_SignUp = NewComboCounterRef("api.user.signup")
M_Api_User_SignUpInvite = NewComboCounterRef("api.user.signup_invite")
M_Api_Dashboard_Get = NewComboCounterRef("api.dashboard.get")
M_Api_Dashboard_Post = NewComboCounterRef("api.dashboard.post")
M_Api_Admin_User_Create = NewComboCounterRef("api.admin.user_create")
M_Api_Login_Post = NewComboCounterRef("api.login.post")
M_Api_Login_OAuth = NewComboCounterRef("api.login.oauth")
M_Api_Org_Create = NewComboCounterRef("api.org.create")
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_Dashboard_Get = NewComboCounterRef("api.dashboard.get")
M_Api_Dashboard_Post = NewComboCounterRef("api.dashboard.post")
M_Api_Admin_User_Create = NewComboCounterRef("api.admin.user_create")
M_Api_Login_Post = NewComboCounterRef("api.login.post")
M_Api_Login_OAuth = NewComboCounterRef("api.login.oauth")
M_Api_Org_Create = NewComboCounterRef("api.org.create")
M_Api_Dashboard_Snapshot_Create = NewComboCounterRef("api.dashboard_snapshot.create")
M_Api_Dashboard_Snapshot_External = NewComboCounterRef("api.dashboard_snapshot.external")
......
......@@ -13,6 +13,7 @@ var (
type TempUserStatus string
const (
TmpUserSignUpStarted TempUserStatus = "SignUpStarted"
TmpUserInvitePending TempUserStatus = "InvitePending"
TmpUserCompleted TempUserStatus = "Completed"
TmpUserEmailPending TempUserStatus = "EmailPending"
......
......@@ -131,7 +131,7 @@ func userSignedUpHandler(evt *events.UserSignedUp) error {
To: []string{evt.Email},
Template: tmplWelcomeOnSignUp,
Data: map[string]interface{}{
"Name": evt.Login,
"Email": evt.Email,
},
})
}
......@@ -75,10 +75,11 @@ var (
EmailCodeValidMinutes int
// User settings
AllowUserSignUp bool
AllowUserOrgCreate bool
AutoAssignOrg bool
AutoAssignOrgRole string
AllowUserSignUp bool
AllowUserOrgCreate bool
AutoAssignOrg bool
AutoAssignOrgRole string
RequireEmailValidation bool
// Http auth
AdminUser string
......
<div class="container">
<div class="login-page-background">
</div>
<div class="login-box">
......
<div class="container">
<div class="login-page-background">
<div class="signup-page-background">
</div>
<div class="login-box">
......
......@@ -93,7 +93,7 @@
}
}
.login-page-background {
.signup-page-background {
position: fixed;
top: 0;
left: 0;
......@@ -101,8 +101,8 @@
bottom: 0;
height: 100%;
width: 100%;
background-image: url(/img/background_tease.jpg);
opacity: 0.05;
background-image: url(../img/background_tease.jpg);
opacity: 0.3;
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