mirror of https://github.com/go-gitea/gitea.git
parent
85f34ba538
commit
c38754d432
|
@ -406,6 +406,7 @@ func runWeb(ctx *cli.Context) {
|
||||||
m.Group("/settings", func() {
|
m.Group("/settings", func() {
|
||||||
m.Combo("").Get(org.Settings).
|
m.Combo("").Get(org.Settings).
|
||||||
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
Post(bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
|
||||||
|
m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), org.SettingsAvatar)
|
||||||
|
|
||||||
m.Group("/hooks", func() {
|
m.Group("/hooks", func() {
|
||||||
m.Get("", org.Webhooks)
|
m.Get("", org.Webhooks)
|
||||||
|
|
|
@ -656,6 +656,7 @@ settings.location = Location
|
||||||
settings.update_settings = Update Settings
|
settings.update_settings = Update Settings
|
||||||
settings.update_setting_success = Organization settings has been updated successfully.
|
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.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 = Delete Organization
|
||||||
settings.delete_account = Delete This Organization
|
settings.delete_account = Delete This Organization
|
||||||
settings.delete_prompt = The organization will be permanently removed, and this <strong>CANNOT</strong> be undone!
|
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/log"
|
||||||
"github.com/gogits/gogs/modules/middleware"
|
"github.com/gogits/gogs/modules/middleware"
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
|
"github.com/gogits/gogs/routers/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -73,6 +74,17 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateOrgSettingForm) {
|
||||||
ctx.Redirect(org.HomeLink() + "/settings")
|
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) {
|
func SettingsDelete(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = ctx.Tr("org.settings")
|
ctx.Data["Title"] = ctx.Tr("org.settings")
|
||||||
ctx.Data["PageIsSettingsDelete"] = true
|
ctx.Data["PageIsSettingsDelete"] = true
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -87,45 +89,47 @@ func SettingsPost(ctx *middleware.Context, form auth.UpdateProfileForm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: limit size.
|
// FIXME: limit size.
|
||||||
func SettingsAvatar(ctx *middleware.Context, form auth.UploadAvatarForm) {
|
func UpdateAvatarSetting(ctx *middleware.Context, form auth.UploadAvatarForm, ctxUser *models.User) error {
|
||||||
defer ctx.Redirect(setting.AppSubUrl + "/user/settings")
|
ctxUser.UseCustomAvatar = form.Enable
|
||||||
|
|
||||||
ctx.User.UseCustomAvatar = form.Enable
|
|
||||||
|
|
||||||
if form.Avatar != nil {
|
if form.Avatar != nil {
|
||||||
fr, err := form.Avatar.Open()
|
fr, err := form.Avatar.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Flash.Error(err.Error())
|
return fmt.Errorf("Avatar.Open: %v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(fr)
|
data, err := ioutil.ReadAll(fr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Flash.Error(err.Error())
|
return fmt.Errorf("ReadAll: %v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if _, ok := base.IsImageFile(data); !ok {
|
if _, ok := base.IsImageFile(data); !ok {
|
||||||
ctx.Flash.Error(ctx.Tr("settings.uploaded_avatar_not_a_image"))
|
return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image"))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
if err = ctx.User.UploadAvatar(data); err != nil {
|
if err = ctxUser.UploadAvatar(data); err != nil {
|
||||||
ctx.Flash.Error(err.Error())
|
return fmt.Errorf("UploadAvatar: %v", err)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// In case no avatar at all.
|
// In case no avatar at all.
|
||||||
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) {
|
if form.Enable && !com.IsFile(ctx.User.CustomAvatarPath()) {
|
||||||
ctx.Flash.Error(ctx.Tr("settings.no_custom_avatar_available"))
|
return errors.New(ctx.Tr("settings.no_custom_avatar_available"))
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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())
|
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) {
|
func SettingsEmails(ctx *middleware.Context) {
|
||||||
|
|
|
@ -37,6 +37,20 @@
|
||||||
<button class="ui green button">{{$.i18n.Tr "org.settings.update_settings"}}</button>
|
<button class="ui green button">{{$.i18n.Tr "org.settings.update_settings"}}</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue