parent
85f34ba538
commit
c38754d432
|
@ -406,6 +406,7 @@ func runWeb(ctx *cli.Context) {
|
|||
m.Group("/settings", func() {
|
||||
m.Combo("").Get(org.Settings).
|
||||
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
||||
m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), org.SettingsAvatar)
|
||||
|
||||
m.Group("/hooks", func() {
|
||||
m.Get("", org.Webhooks)
|
||||
|
|
|
@ -656,6 +656,7 @@ settings.location = Location
|
|||
settings.update_settings = Update Settings
|
||||
settings.update_setting_success = Organization settings has been updated successfully.
|
||||
settings.change_orgname_prompt = This change will affect how links relate to the organization.
|
||||
settings.update_avatar_success = Organization avatar setting has been updated successfully.
|
||||
settings.delete = Delete Organization
|
||||
settings.delete_account = Delete This Organization
|
||||
settings.delete_prompt = The organization will be permanently removed, and this <strong>CANNOT</strong> be undone!
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
ctx.Flash.Error(err.Error())
|
||||
return
|
||||
if err := models.UpdateUser(ctxUser); err != nil {
|
||||
return fmt.Errorf("UpdateUser: %v", err)
|
||||
}
|
||||
|
||||
ctx.Flash.Success(ctx.Tr("settings.update_avatar_success"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
||||
if err := UpdateAvatarSetting(ctx, form, ctx.User); err != nil {
|
||||
ctx.Flash.Error(err.Error())
|
||||
} else {
|
||||
ctx.Flash.Success(ctx.Tr("settings.update_avatar_success"))
|
||||
}
|
||||
|
||||
ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
||||
}
|
||||
|
||||
func SettingsEmails(ctx *middleware.Context) {
|
||||
|
|
|
@ -37,6 +37,20 @@
|
|||
<button class="ui green button">{{$.i18n.Tr "org.settings.update_settings"}}</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="ui divider"></div>
|
||||
|
||||
<form class="ui form" action="{{.Link}}/avatar" method="post" enctype="multipart/form-data">
|
||||
{{.CsrfTokenHtml}}
|
||||
<div class="inline field">
|
||||
<label for="avatar">{{.i18n.Tr "settings.choose_new_avatar"}}</label>
|
||||
<input name="avatar" type="file" >
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<button class="ui green button">{{$.i18n.Tr "settings.update_avatar"}}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user