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 /modules | |
parent | 3c3f7c2a56ba18d7210cc40e33e64da5219ef990 (diff) | |
download | gitea-55dfe2c97876a8af5db0fb071f002e33fb686128.tar.gz gitea-55dfe2c97876a8af5db0fb071f002e33fb686128.zip |
custom avatar upload
Diffstat (limited to 'modules')
-rw-r--r-- | modules/auth/user_form.go | 10 | ||||
-rw-r--r-- | modules/avatar/avatar.go | 2 | ||||
-rw-r--r-- | modules/setting/setting.go | 10 |
3 files changed, 18 insertions, 4 deletions
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go index 6046a8d1ee..afdd8be0c9 100644 --- a/modules/auth/user_form.go +++ b/modules/auth/user_form.go @@ -5,6 +5,8 @@ package auth import ( + "mime/multipart" + "github.com/Unknwon/macaron" "github.com/macaron-contrib/binding" ) @@ -86,6 +88,14 @@ func (f *UpdateProfileForm) Validate(ctx *macaron.Context, errs binding.Errors) return validate(errs, ctx.Data, f, ctx.Locale) } +type UploadAvatarForm struct { + Avatar *multipart.FileHeader `form:"avatar" binding:"Required"` +} + +func (f *UploadAvatarForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} + type ChangePasswordForm struct { OldPassword string `form:"old_password" binding:"Required;MinSize(6);MaxSize(255)"` Password string `form:"password" binding:"Required;MinSize(6);MaxSize(255)"` diff --git a/modules/avatar/avatar.go b/modules/avatar/avatar.go index fb198da149..144fda387e 100644 --- a/modules/avatar/avatar.go +++ b/modules/avatar/avatar.go @@ -121,7 +121,7 @@ func (this *Avatar) Encode(wr io.Writer, size int) (err error) { if img, err = decodeImageFile(imgPath); err != nil { return } - m := resize.Resize(uint(size), 0, img, resize.Lanczos3) + m := resize.Resize(uint(size), 0, img, resize.NearestNeighbor) return jpeg.Encode(wr, m, nil) } diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 0f293b6905..49bd11c4c2 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -66,9 +66,10 @@ var ( ScriptType string // Picture settings. - PictureService string - GravatarSource string - DisableGravatar bool + PictureService string + AvatarUploadPath string + GravatarSource string + DisableGravatar bool // Log settings. LogRootPath string @@ -259,6 +260,9 @@ func NewConfigContext() { ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash") PictureService = Cfg.MustValueRange("picture", "SERVICE", "server", []string{"server"}) + AvatarUploadPath = Cfg.MustValue("picture", "AVATAR_UPLOAD_PATH", "data/avatars") + os.MkdirAll(AvatarUploadPath, os.ModePerm) + switch Cfg.MustValue("picture", "GRAVATAR_SOURCE", "gravatar") { case "duoshuo": GravatarSource = "http://gravatar.duoshuo.com/avatar/" |