diff options
author | Unknwon <joe2010xtmf@163.com> | 2014-11-21 10:58:08 -0500 |
---|---|---|
committer | Unknwon <joe2010xtmf@163.com> | 2014-11-21 10:58:08 -0500 |
commit | 55dfe2c97876a8af5db0fb071f002e33fb686128 (patch) | |
tree | c43f8eb741f1dd69b62888202582e4894a5da66d /routers | |
parent | 3c3f7c2a56ba18d7210cc40e33e64da5219ef990 (diff) | |
download | gitea-55dfe2c97876a8af5db0fb071f002e33fb686128.tar.gz gitea-55dfe2c97876a8af5db0fb071f002e33fb686128.zip |
custom avatar upload
Diffstat (limited to 'routers')
-rw-r--r-- | routers/user/home.go | 7 | ||||
-rw-r--r-- | routers/user/setting.go | 29 |
2 files changed, 36 insertions, 0 deletions
diff --git a/routers/user/home.go b/routers/user/home.go index 031872fca9..1bb9701104 100644 --- a/routers/user/home.go +++ b/routers/user/home.go @@ -100,6 +100,13 @@ func Dashboard(ctx *middleware.Context) { continue } } + // FIXME: cache results? + u, err := models.GetUserByName(act.ActUserName) + if err != nil { + ctx.Handle(500, "GetUserByName", err) + return + } + act.ActAvatar = u.AvatarLink() feeds = append(feeds, act) } ctx.Data["Feeds"] = feeds 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 |