[MM-22037] Enable uppercase letters in the email (#13794)

* Enable uppercase letters in the email

* Lowercase email on every input

* Remove invalid test
Этот коммит содержится в:
Shota Gvinepadze
2020-02-12 17:51:45 +04:00
коммит произвёл GitHub
родитель 28ef877876
Коммит a7854f1b97
10 изменённых файлов: 25 добавлений и 14 удалений

Просмотреть файл

@@ -79,6 +79,7 @@ func createTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetInvalidParam("team")
return
}
team.Email = strings.ToLower(team.Email)
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)
@@ -151,6 +152,7 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.SetInvalidParam("team")
return
}
team.Email = strings.ToLower(team.Email)
// The team being updated in the payload must be the same one as indicated in the URL.
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)
for i := range emailList {
emailList[i] = strings.ToLower(emailList[i])
}
if len(emailList) == 0 {
c.SetInvalidParam("user_email")
@@ -1016,10 +1021,14 @@ func inviteGuestsToChannels(c *Context, w http.ResponseWriter, r *http.Request)
}
guestsInvite := model.GuestsInviteFromJson(r.Body)
for i, email := range guestsInvite.Emails {
guestsInvite.Emails[i] = strings.ToLower(email)
}
if err := guestsInvite.IsValid(); err != nil {
c.Err = err
return
}
if graceful {
invitesWithError, err := c.App.InviteGuestsToChannelsGracefully(c.Params.TeamId, guestsInvite, c.App.Session.UserId)
if err != nil {

Просмотреть файл

@@ -10,6 +10,7 @@ import (
"io/ioutil"
"net/http"
"strconv"
"strings"
"time"
"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) {
c.RequireEmail()
c.SanitizeEmail()
if c.Err != nil {
return
}
@@ -1264,6 +1265,7 @@ func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
email := props["email"]
email = strings.ToLower(email)
if len(email) == 0 {
c.SetInvalidParam("email")
return
@@ -1625,6 +1627,7 @@ func sendVerificationEmail(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.MapFromJson(r.Body)
email := props["email"]
email = strings.ToLower(email)
if len(email) == 0 {
c.SetInvalidParam("email")
return

Просмотреть файл

@@ -309,6 +309,7 @@ func (a *App) importUser(data *UserImportData, dryRun bool) *model.AppError {
hasUserChanged = true
hasUserEmailVerifiedChanged = true // Changing the email resets email verified to false by default.
user.Email = *data.Email
user.Email = strings.ToLower(user.Email)
}
var password string

Просмотреть файл

@@ -185,6 +185,7 @@ func (a *App) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *
continue
}
email = strings.ToLower(email)
newUser := model.User{
Username: sUser.Username,
FirstName: firstName,

Просмотреть файл

@@ -1611,6 +1611,7 @@ func (a *App) VerifyEmailFromToken(userSuppliedTokenString string) *model.AppErr
return err
}
tokenData.Email = strings.ToLower(tokenData.Email)
if err := a.VerifyUserEmail(tokenData.UserId, tokenData.Email); err != nil {
return err
}

Просмотреть файл

@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"sort"
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"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")
}
email, _ := command.Flags().GetString("email")
email = strings.ToLower(email)
useprivate, _ := command.Flags().GetBool("private")
teamType := model.TEAM_OPEN

Просмотреть файл

@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"strings"
"github.com/mattermost/mattermost-server/v5/app"
"github.com/mattermost/mattermost-server/v5/model"
@@ -340,6 +341,7 @@ func userCreateCmdF(command *cobra.Command, args []string) error {
if erre != nil || email == "" {
return errors.New("Email is required")
}
email = strings.ToLower((email))
password, errp := command.Flags().GetString("password")
if errp != nil || password == "" {
return errors.New("Password is required")
@@ -572,6 +574,7 @@ func userInviteCmdF(command *cobra.Command, args []string) error {
}
email := args[0]
email = strings.ToLower(email)
if !model.IsValidEmail(email) {
return errors.New("Invalid email")
}
@@ -640,7 +643,7 @@ func updateUserEmailCmdF(command *cobra.Command, args []string) error {
}
newEmail := args[1]
newEmail = strings.ToLower(newEmail)
if !model.IsValidEmail(newEmail) {
return errors.New("Invalid email: '" + newEmail + "'")
}

Просмотреть файл

@@ -47,6 +47,7 @@ func userFromGitLabUser(glu *GitLabUser) *model.User {
user.FirstName = glu.Name
}
user.Email = glu.Email
user.Email = strings.ToLower(user.Email)
userId := glu.getAuthData()
user.AuthData = &userId
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) {
etag := Etag("hello", 24)
require.NotEqual(t, "", etag)

Просмотреть файл

@@ -393,11 +393,11 @@ func (c *Context) RequireChannelName() *Context {
return c
}
func (c *Context) RequireEmail() *Context {
func (c *Context) SanitizeEmail() *Context {
if c.Err != nil {
return c
}
c.Params.Email = strings.ToLower(c.Params.Email)
if !model.IsValidEmail(c.Params.Email) {
c.SetInvalidUrlParam("email")
}