|
|
@ -5,6 +5,8 @@ |
|
|
|
package user |
|
|
|
package user |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"io/ioutil" |
|
|
|
"io/ioutil" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
|
@ -87,45 +89,47 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// FIXME: limit size.
|
|
|
|
// FIXME: limit size.
|
|
|
|
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { |
|
|
|
func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error { |
|
|
|
defer ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
ctxUser.UseCustomAvatar = form.Enable |
|
|
|
|
|
|
|
|
|
|
|
ctx.User.UseCustomAvatar = form.Enable |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.Avatar != nil { |
|
|
|
if form.Avatar != nil { |
|
|
|
fr, err := form.Avatar.Open() |
|
|
|
fr, err := form.Avatar.Open() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Flash.Error(err.Error()) |
|
|
|
return fmt.Errorf("Avatar.Open: %v", err) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
data, err := ioutil.ReadAll(fr) |
|
|
|
data, err := ioutil.ReadAll(fr) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
ctx.Flash.Error(err.Error()) |
|
|
|
return fmt.Errorf("ReadAll: %v", err) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if _, ok := base.IsImageFile(data); !ok { |
|
|
|
if _, ok := base.IsImageFile(data); !ok { |
|
|
|
ctx.Flash.Error(ctx.Tr("settings.uploaded_avatar_not_a_image")) |
|
|
|
return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if err = ctx.User.UploadAvatar(data); err != nil { |
|
|
|
if err = ctxUser.UploadAvatar(data); err != nil { |
|
|
|
ctx.Flash.Error(err.Error()) |
|
|
|
return fmt.Errorf("UploadAvatar: %v", err) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// In case no avatar at all.
|
|
|
|
// In case no avatar at all.
|
|
|
|
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) { |
|
|
|
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) { |
|
|
|
ctx.Flash.Error(ctx.Tr("settings.no_custom_avatar_available")) |
|
|
|
return errors.New(ctx.Tr("settings.no_custom_avatar_available")) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.UpdateUser(ctx.User); err != nil { |
|
|
|
if err := models.UpdateUser(ctxUser); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("UpdateUser: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { |
|
|
|
|
|
|
|
if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil { |
|
|
|
ctx.Flash.Error(err.Error()) |
|
|
|
ctx.Flash.Error(err.Error()) |
|
|
|
return |
|
|
|
} else { |
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.update_avatar_success")) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ctx.Flash.Success(ctx.Tr("settings.update_avatar_success")) |
|
|
|
ctx.Redirect(setting.AppSubUrl + "/user/settings") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func SettingsEmails(ctx *middleware.Context) { |
|
|
|
func SettingsEmails(ctx *middleware.Context) { |
|
|
|