diff options
Diffstat (limited to 'routers/user/setting.go')
-rw-r--r-- | routers/user/setting.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/routers/user/setting.go b/routers/user/setting.go index bb0fa9103e..559e10fd89 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -5,6 +5,7 @@ package user import ( + "io/ioutil" "strings" "github.com/Unknwon/com" @@ -83,6 +84,34 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Redirect(setting.AppSubUrl + "/user/settings") } +// FIXME: limit size. +func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) { + defer ctx.Redirect(setting.AppSubUrl + "/user/settings") + + if form.Avatar != nil { + fr, err := form.Avatar.Open() + if err != nil { + ctx.Flash.Error(err.Error()) + return + } + + data, err := ioutil.ReadAll(fr) + if err != nil { + ctx.Flash.Error(err.Error()) + return + } + if _, ok := base.IsImageFile(data); !ok { + ctx.Flash.Error(ctx.Tr("settings.uploaded_avatar_not_a_image")) + return + } + if err = ctx.User.UploadAvatar(data); err != nil { + ctx.Flash.Error(err.Error()) + return + } + ctx.Flash.Success(ctx.Tr("settings.upload_avatar_success")) + } +} + func SettingsPassword(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("settings") ctx.Data["PageIsUserSettings"] = true |