summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-09-06 17:12:02 -0400
committerUnknwon <u@gogs.io>2015-09-06 17:12:02 -0400
commitc38754d432c4244a884ccf2576397eb15552b495 (patch)
tree4a4ccc071f6625c7d143c1d647b4b17d3a7f7fab /routers
parent85f34ba53843177999cb98bad046e9cce22bfc8f (diff)
downloadgitea-c38754d432c4244a884ccf2576397eb15552b495.tar.gz
gitea-c38754d432c4244a884ccf2576397eb15552b495.zip
#1191 allow upload avatar for org
Signed-off-by: Unknwon <u@gogs.io>
Diffstat (limited to 'routers')
-rw-r--r--routers/org/setting.go12
-rw-r--r--routers/user/setting.go40
2 files changed, 34 insertions, 18 deletions
diff --git a/routers/org/setting.go b/routers/org/setting.go
index c6d2db3d97..9e26afa7d4 100644
--- a/routers/org/setting.go
+++ b/routers/org/setting.go
@@ -12,6 +12,7 @@ import (
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
+ "github.com/gogits/gogs/routers/user"
)
const (
@@ -73,6 +74,17 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) {
ctx.Redirect(org.HomeLink() + "/settings")
}
+func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
+ form.Enable = true
+ if err := user.UpdateAvatarSetting(ctx, form, ctx.Org.Organization); err != nil {
+ ctx.Flash.Error(err.Error())
+ } else {
+ ctx.Flash.Success(ctx.Tr("org.settings.update_avatar_success"))
+ }
+
+ ctx.Redirect(ctx.Org.OrgLink + "/settings")
+}
+
func SettingsDelete(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("org.settings")
ctx.Data["PageIsSettingsDelete"] = true
diff --git a/routers/user/setting.go b/routers/user/setting.go
index f2f5a6cd93..c62a123d5b 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -5,6 +5,8 @@
package user
import (
+ "errors"
+ "fmt"
"io/ioutil"
"strings"
@@ -87,45 +89,47 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
}
// FIXME: limit size.
-func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
- defer ctx.Redirect(setting.AppSubUrl + "/user/settings")
-
- ctx.User.UseCustomAvatar = form.Enable
+func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error {
+ ctxUser.UseCustomAvatar = form.Enable
if form.Avatar != nil {
fr, err := form.Avatar.Open()
if err != nil {
- ctx.Flash.Error(err.Error())
- return
+ return fmt.Errorf("Avatar.Open: %v", err)
}
data, err := ioutil.ReadAll(fr)
if err != nil {
- ctx.Flash.Error(err.Error())
- return
+ return fmt.Errorf("ReadAll: %v", err)
}
if _, ok := base.IsImageFile(data); !ok {
- ctx.Flash.Error(ctx.Tr("settings.uploaded_avatar_not_a_image"))
- return
+ return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
}
- if err = ctx.User.UploadAvatar(data); err != nil {
- ctx.Flash.Error(err.Error())
- return
+ if err = ctxUser.UploadAvatar(data); err != nil {
+ return fmt.Errorf("UploadAvatar: %v", err)
}
} else {
// In case no avatar at all.
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) {
- ctx.Flash.Error(ctx.Tr("settings.no_custom_avatar_available"))
- return
+ return errors.New(ctx.Tr("settings.no_custom_avatar_available"))
}
}
- 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())
- 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) {