Made it easier to edit avatars

This commit is contained in:
2019-09-06 09:15:49 +09:00
parent 49547cc3b8
commit ca21bd5df0
7 changed files with 54 additions and 27 deletions

View File

@ -56,7 +56,7 @@ type User struct {
UserAgent string `json:"agent" private:"true"`
Balance int `json:"balance" private:"true"`
Image Image `json:"image"`
Avatar UserAvatar `json:"avatar"`
Avatar UserAvatar `json:"avatar" editable:"true"`
Cover UserCover `json:"cover"`
Accounts UserAccounts `json:"accounts" private:"true"`
Browser UserBrowser `json:"browser" private:"true"`

View File

@ -96,10 +96,10 @@ func (user *User) Edit(ctx aero.Context, key string, value reflect.Value, newVal
user.BirthDay = newBirthDay
return true, nil
case "ProExpires":
user := GetUserFromContext(ctx)
case "ProExpires", "Avatar.Extension", "Avatar.LastModified":
editor := GetUserFromContext(ctx)
if user == nil || user.Role != "admin" {
if editor == nil || editor.Role != "admin" {
return true, errors.New("Not authorized to edit")
}

View File

@ -60,9 +60,8 @@ var avatarOutputs = []imageserver.Output{
// UserAvatar ...
type UserAvatar struct {
Extension string `json:"extension"`
Source string `json:"source"`
LastModified int64 `json:"lastModified"`
Extension string `json:"extension" editable:"true"`
LastModified int64 `json:"lastModified" editable:"true"`
}
// SetImageBytes accepts a byte buffer that represents an image file and updates the avatar.