[MM-22037] Enable uppercase letters in the email (#13794)
* Enable uppercase letters in the email * Lowercase email on every input * Remove invalid test
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
28ef877876
Коммит
a7854f1b97
@@ -79,6 +79,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.SetInvalidParam("team")
|
c.SetInvalidParam("team")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
team.Email = strings.ToLower(team.Email)
|
||||||
|
|
||||||
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_TEAM) {
|
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_TEAM) {
|
||||||
c.Err = model.NewAppError("createTeam", "api.team.is_team_creation_allowed.disabled.app_error", nil, "", http.StatusForbidden)
|
c.Err = model.NewAppError("createTeam", "api.team.is_team_creation_allowed.disabled.app_error", nil, "", http.StatusForbidden)
|
||||||
@@ -151,6 +152,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
c.SetInvalidParam("team")
|
c.SetInvalidParam("team")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
team.Email = strings.ToLower(team.Email)
|
||||||
|
|
||||||
// The team being updated in the payload must be the same one as indicated in the URL.
|
// The team being updated in the payload must be the same one as indicated in the URL.
|
||||||
if team.Id != c.Params.TeamId {
|
if team.Id != c.Params.TeamId {
|
||||||
@@ -969,6 +971,9 @@ func inviteUsersToTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
emailList := model.ArrayFromJson(r.Body)
|
emailList := model.ArrayFromJson(r.Body)
|
||||||
|
for i := range emailList {
|
||||||
|
emailList[i] = strings.ToLower(emailList[i])
|
||||||
|
}
|
||||||
|
|
||||||
if len(emailList) == 0 {
|
if len(emailList) == 0 {
|
||||||
c.SetInvalidParam("user_email")
|
c.SetInvalidParam("user_email")
|
||||||
@@ -1016,10 +1021,14 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
|
|
||||||
guestsInvite := model.GuestsInviteFromJson(r.Body)
|
guestsInvite := model.GuestsInviteFromJson(r.Body)
|
||||||
|
for i, email := range guestsInvite.Emails {
|
||||||
|
guestsInvite.Emails[i] = strings.ToLower(email)
|
||||||
|
}
|
||||||
if err := guestsInvite.IsValid(); err != nil {
|
if err := guestsInvite.IsValid(); err != nil {
|
||||||
c.Err = err
|
c.Err = err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if graceful {
|
if graceful {
|
||||||
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/app"
|
"github.com/mattermost/mattermost-server/v5/app"
|
||||||
@@ -244,7 +245,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
c.RequireEmail()
|
c.SanitizeEmail()
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1264,6 +1265,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
props := model.MapFromJson(r.Body)
|
props := model.MapFromJson(r.Body)
|
||||||
|
|
||||||
email := props["email"]
|
email := props["email"]
|
||||||
|
email = strings.ToLower(email)
|
||||||
if len(email) == 0 {
|
if len(email) == 0 {
|
||||||
c.SetInvalidParam("email")
|
c.SetInvalidParam("email")
|
||||||
return
|
return
|
||||||
@@ -1625,6 +1627,7 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
props := model.MapFromJson(r.Body)
|
props := model.MapFromJson(r.Body)
|
||||||
|
|
||||||
email := props["email"]
|
email := props["email"]
|
||||||
|
email = strings.ToLower(email)
|
||||||
if len(email) == 0 {
|
if len(email) == 0 {
|
||||||
c.SetInvalidParam("email")
|
c.SetInvalidParam("email")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
|
|||||||
hasUserChanged = true
|
hasUserChanged = true
|
||||||
hasUserEmailVerifiedChanged = true // Changing the email resets email verified to false by default.
|
hasUserEmailVerifiedChanged = true // Changing the email resets email verified to false by default.
|
||||||
user.Email = *data.Email
|
user.Email = *data.Email
|
||||||
|
user.Email = strings.ToLower(user.Email)
|
||||||
}
|
}
|
||||||
|
|
||||||
var password string
|
var password string
|
||||||
|
|||||||
@@ -185,6 +185,7 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
email = strings.ToLower(email)
|
||||||
newUser := model.User{
|
newUser := model.User{
|
||||||
Username: sUser.Username,
|
Username: sUser.Username,
|
||||||
FirstName: firstName,
|
FirstName: firstName,
|
||||||
|
|||||||
@@ -1611,6 +1611,7 @@ func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppErr
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tokenData.Email = strings.ToLower(tokenData.Email)
|
||||||
if err := a.VerifyUserEmail(tokenData.UserId, tokenData.Email); err != nil {
|
if err := a.VerifyUserEmail(tokenData.UserId, tokenData.Email); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/app"
|
"github.com/mattermost/mattermost-server/v5/app"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
@@ -153,6 +154,7 @@ func createTeamCmdF(command *cobra.Command, args []string) error {
|
|||||||
return errors.New("Display Name is required")
|
return errors.New("Display Name is required")
|
||||||
}
|
}
|
||||||
email, _ := command.Flags().GetString("email")
|
email, _ := command.Flags().GetString("email")
|
||||||
|
email = strings.ToLower(email)
|
||||||
useprivate, _ := command.Flags().GetBool("private")
|
useprivate, _ := command.Flags().GetBool("private")
|
||||||
|
|
||||||
teamType := model.TEAM_OPEN
|
teamType := model.TEAM_OPEN
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattermost/mattermost-server/v5/app"
|
"github.com/mattermost/mattermost-server/v5/app"
|
||||||
"github.com/mattermost/mattermost-server/v5/model"
|
"github.com/mattermost/mattermost-server/v5/model"
|
||||||
@@ -340,6 +341,7 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
|
|||||||
if erre != nil || email == "" {
|
if erre != nil || email == "" {
|
||||||
return errors.New("Email is required")
|
return errors.New("Email is required")
|
||||||
}
|
}
|
||||||
|
email = strings.ToLower((email))
|
||||||
password, errp := command.Flags().GetString("password")
|
password, errp := command.Flags().GetString("password")
|
||||||
if errp != nil || password == "" {
|
if errp != nil || password == "" {
|
||||||
return errors.New("Password is required")
|
return errors.New("Password is required")
|
||||||
@@ -572,6 +574,7 @@ func userInviteCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
email := args[0]
|
email := args[0]
|
||||||
|
email = strings.ToLower(email)
|
||||||
if !model.IsValidEmail(email) {
|
if !model.IsValidEmail(email) {
|
||||||
return errors.New("Invalid email")
|
return errors.New("Invalid email")
|
||||||
}
|
}
|
||||||
@@ -640,7 +643,7 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newEmail := args[1]
|
newEmail := args[1]
|
||||||
|
newEmail = strings.ToLower(newEmail)
|
||||||
if !model.IsValidEmail(newEmail) {
|
if !model.IsValidEmail(newEmail) {
|
||||||
return errors.New("Invalid email: '" + newEmail + "'")
|
return errors.New("Invalid email: '" + newEmail + "'")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func userFromGitLabUser(glu *GitLabUser) *model.User {
|
|||||||
user.FirstName = glu.Name
|
user.FirstName = glu.Name
|
||||||
}
|
}
|
||||||
user.Email = glu.Email
|
user.Email = glu.Email
|
||||||
|
user.Email = strings.ToLower(user.Email)
|
||||||
userId := glu.getAuthData()
|
userId := glu.getAuthData()
|
||||||
user.AuthData = &userId
|
user.AuthData = &userId
|
||||||
user.AuthService = model.USER_AUTH_SERVICE_GITLAB
|
user.AuthService = model.USER_AUTH_SERVICE_GITLAB
|
||||||
|
|||||||
@@ -184,16 +184,6 @@ func TestIsValidEmail(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidLower(t *testing.T) {
|
|
||||||
if !IsLower("corey+test@hulen.com") {
|
|
||||||
t.Error("should be valid")
|
|
||||||
}
|
|
||||||
|
|
||||||
if IsLower("Corey+test@hulen.com") {
|
|
||||||
t.Error("should be invalid")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEtag(t *testing.T) {
|
func TestEtag(t *testing.T) {
|
||||||
etag := Etag("hello", 24)
|
etag := Etag("hello", 24)
|
||||||
require.NotEqual(t, "", etag)
|
require.NotEqual(t, "", etag)
|
||||||
|
|||||||
@@ -393,11 +393,11 @@ func (c *Context) RequireChannelName() *Context {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) RequireEmail() *Context {
|
func (c *Context) SanitizeEmail() *Context {
|
||||||
if c.Err != nil {
|
if c.Err != nil {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
c.Params.Email = strings.ToLower(c.Params.Email)
|
||||||
if !model.IsValidEmail(c.Params.Email) {
|
if !model.IsValidEmail(c.Params.Email) {
|
||||||
c.SetInvalidUrlParam("email")
|
c.SetInvalidUrlParam("email")
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user