[MM-13839] Check for password when updating the eMail (#10207)

* Check for password when updating the eMail

* Require password for email change

* Enhance unit testing

* Restructure error handling for update email path

* govet
Этот коммит содержится в:
Daniel Schalla
2019-02-02 00:06:49 +01:00
коммит произвёл Carlos Tadeu Panato Junior
родитель 9a3dc21adc
Коммит 85c60f1402
5 изменённых файлов: 72 добавлений и 9 удалений

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

@@ -685,13 +685,13 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth {
ouser, err := c.App.GetUser(user.Id)
if err != nil {
c.Err = err
return
}
ouser, err := c.App.GetUser(user.Id)
if err != nil {
c.Err = err
return
}
if c.App.Session.IsOAuth {
if ouser.Email != user.Email {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
c.Err.DetailedError += ", attempted email update by oauth app"
@@ -699,6 +699,15 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
// If eMail update is attempted by the currently logged in user, check if correct password was provided
if user.Email != "" && ouser.Email != user.Email && c.App.Session.UserId == c.Params.UserId {
err = c.App.DoubleCheckPassword(ouser, user.Password)
if err != nil {
c.SetInvalidParam("password")
return
}
}
ruser, err := c.App.UpdateUserAsUser(user, c.IsSystemAdmin())
if err != nil {
c.Err = err
@@ -745,6 +754,19 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
// If eMail update is attempted by the currently logged in user, check if correct password was provided
if patch.Email != nil && ouser.Email != *patch.Email && c.App.Session.UserId == c.Params.UserId {
if patch.Password == nil {
c.SetInvalidParam("password")
return
}
if err = c.App.DoubleCheckPassword(ouser, *patch.Password); err != nil {
c.SetInvalidParam("password")
return
}
}
ruser, err := c.App.PatchUser(c.Params.UserId, patch, c.IsSystemAdmin())
if err != nil {
c.Err = err