mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-21 02:04:26 +08:00
user settings supports language and date&time format
This commit is contained in:
+57
-15
@@ -57,6 +57,7 @@ func (a *UsersApi) UserRegisterHandler(c *core.Context) (interface{}, *errs.Erro
|
||||
Email: userRegisterReq.Email,
|
||||
Nickname: userRegisterReq.Nickname,
|
||||
Password: userRegisterReq.Password,
|
||||
Language: userRegisterReq.Language,
|
||||
DefaultCurrency: userRegisterReq.DefaultCurrency,
|
||||
FirstDayOfWeek: userRegisterReq.FirstDayOfWeek,
|
||||
TransactionEditScope: models.TRANSACTION_EDIT_SCOPE_ALL,
|
||||
@@ -161,12 +162,6 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
anythingUpdate = true
|
||||
}
|
||||
|
||||
if userUpdateReq.DefaultCurrency != "" && userUpdateReq.DefaultCurrency != user.DefaultCurrency {
|
||||
user.DefaultCurrency = userUpdateReq.DefaultCurrency
|
||||
userNew.DefaultCurrency = userUpdateReq.DefaultCurrency
|
||||
anythingUpdate = true
|
||||
}
|
||||
|
||||
if userUpdateReq.DefaultAccountId > 0 && userUpdateReq.DefaultAccountId != user.DefaultAccountId {
|
||||
accounts, err := a.accounts.GetAccountsByAccountIds(uid, []int64{userUpdateReq.DefaultAccountId})
|
||||
|
||||
@@ -179,14 +174,6 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
anythingUpdate = true
|
||||
}
|
||||
|
||||
if userUpdateReq.FirstDayOfWeek != nil && *userUpdateReq.FirstDayOfWeek != user.FirstDayOfWeek {
|
||||
user.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
|
||||
userNew.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.FirstDayOfWeek = models.WEEKDAY_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.TransactionEditScope != nil && *userUpdateReq.TransactionEditScope != user.TransactionEditScope {
|
||||
user.TransactionEditScope = *userUpdateReq.TransactionEditScope
|
||||
userNew.TransactionEditScope = *userUpdateReq.TransactionEditScope
|
||||
@@ -195,11 +182,66 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs
|
||||
userNew.TransactionEditScope = models.TRANSACTION_EDIT_SCOPE_INVALID
|
||||
}
|
||||
|
||||
modifyUserLanguage := false
|
||||
|
||||
if userUpdateReq.Language != user.Language {
|
||||
user.Language = userUpdateReq.Language
|
||||
userNew.Language = userUpdateReq.Language
|
||||
modifyUserLanguage = true
|
||||
anythingUpdate = true
|
||||
}
|
||||
|
||||
if userUpdateReq.DefaultCurrency != "" && userUpdateReq.DefaultCurrency != user.DefaultCurrency {
|
||||
user.DefaultCurrency = userUpdateReq.DefaultCurrency
|
||||
userNew.DefaultCurrency = userUpdateReq.DefaultCurrency
|
||||
anythingUpdate = true
|
||||
}
|
||||
|
||||
if userUpdateReq.FirstDayOfWeek != nil && *userUpdateReq.FirstDayOfWeek != user.FirstDayOfWeek {
|
||||
user.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
|
||||
userNew.FirstDayOfWeek = *userUpdateReq.FirstDayOfWeek
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.FirstDayOfWeek = models.WEEKDAY_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.LongDateFormat != nil && *userUpdateReq.LongDateFormat != user.LongDateFormat {
|
||||
user.LongDateFormat = *userUpdateReq.LongDateFormat
|
||||
userNew.LongDateFormat = *userUpdateReq.LongDateFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.LongDateFormat = models.LONG_DATE_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.ShortDateFormat != nil && *userUpdateReq.ShortDateFormat != user.ShortDateFormat {
|
||||
user.ShortDateFormat = *userUpdateReq.ShortDateFormat
|
||||
userNew.ShortDateFormat = *userUpdateReq.ShortDateFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.ShortDateFormat = models.SHORT_DATE_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.LongTimeFormat != nil && *userUpdateReq.LongTimeFormat != user.LongTimeFormat {
|
||||
user.LongTimeFormat = *userUpdateReq.LongTimeFormat
|
||||
userNew.LongTimeFormat = *userUpdateReq.LongTimeFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.LongTimeFormat = models.LONG_TIME_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if userUpdateReq.ShortTimeFormat != nil && *userUpdateReq.ShortTimeFormat != user.ShortTimeFormat {
|
||||
user.ShortTimeFormat = *userUpdateReq.ShortTimeFormat
|
||||
userNew.ShortTimeFormat = *userUpdateReq.ShortTimeFormat
|
||||
anythingUpdate = true
|
||||
} else {
|
||||
userNew.ShortTimeFormat = models.SHORT_TIME_FORMAT_INVALID
|
||||
}
|
||||
|
||||
if !anythingUpdate {
|
||||
return nil, errs.ErrNothingWillBeUpdated
|
||||
}
|
||||
|
||||
keyProfileUpdated, err := a.users.UpdateUser(userNew)
|
||||
keyProfileUpdated, err := a.users.UpdateUser(userNew, modifyUserLanguage)
|
||||
|
||||
if err != nil {
|
||||
log.ErrorfWithRequestId(c, "[users.UserUpdateProfileHandler] failed to update user \"uid:%d\", because %s", user.Uid, err.Error())
|
||||
|
||||
@@ -142,7 +142,7 @@ func (l *UserDataCli) ModifyUserPassword(c *cli.Context, username string, passwo
|
||||
Password: password,
|
||||
}
|
||||
|
||||
_, err = l.users.UpdateUser(userNew)
|
||||
_, err = l.users.UpdateUser(userNew, false)
|
||||
|
||||
if err != nil {
|
||||
log.BootErrorf("[user_data.ModifyUserPassword] failed to update user \"%s\" password, because %s", user.Username, err.Error())
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
package models
|
||||
|
||||
import "fmt"
|
||||
|
||||
// WeekDay represents week day
|
||||
type WeekDay byte
|
||||
|
||||
// Week days
|
||||
const (
|
||||
WEEKDAY_SUNDAY WeekDay = 0
|
||||
WEEKDAY_MONDAY WeekDay = 1
|
||||
WEEKDAY_TUESDAY WeekDay = 2
|
||||
WEEKDAY_WEDNESDAY WeekDay = 3
|
||||
WEEKDAY_THURSDAY WeekDay = 4
|
||||
WEEKDAY_FRIDAY WeekDay = 5
|
||||
WEEKDAY_SATURDAY WeekDay = 6
|
||||
WEEKDAY_INVALID WeekDay = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the week day enum
|
||||
func (d WeekDay) String() string {
|
||||
switch d {
|
||||
case WEEKDAY_SUNDAY:
|
||||
return "Sunday"
|
||||
case WEEKDAY_MONDAY:
|
||||
return "Monday"
|
||||
case WEEKDAY_TUESDAY:
|
||||
return "Tuesday"
|
||||
case WEEKDAY_WEDNESDAY:
|
||||
return "Wednesday"
|
||||
case WEEKDAY_THURSDAY:
|
||||
return "Thursday"
|
||||
case WEEKDAY_FRIDAY:
|
||||
return "Friday"
|
||||
case WEEKDAY_SATURDAY:
|
||||
return "Saturday"
|
||||
case WEEKDAY_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(d))
|
||||
}
|
||||
}
|
||||
|
||||
// LongDateFormat represents long date format
|
||||
type LongDateFormat byte
|
||||
|
||||
// Long Date Format
|
||||
const (
|
||||
LONG_DATE_FORMAT_DEFAULT LongDateFormat = 0
|
||||
LONG_DATE_FORMAT_YYYY_M_D LongDateFormat = 1
|
||||
LONG_DATE_FORMAT_M_D_YYYY LongDateFormat = 2
|
||||
LONG_DATE_FORMAT_D_M_YYYY LongDateFormat = 3
|
||||
LONG_DATE_FORMAT_INVALID LongDateFormat = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the long date format enum
|
||||
func (f LongDateFormat) String() string {
|
||||
switch f {
|
||||
case LONG_DATE_FORMAT_DEFAULT:
|
||||
return "Default"
|
||||
case LONG_DATE_FORMAT_YYYY_M_D:
|
||||
return "YYYY_MM_D"
|
||||
case LONG_DATE_FORMAT_M_D_YYYY:
|
||||
return "M_D_YYYY"
|
||||
case LONG_DATE_FORMAT_D_M_YYYY:
|
||||
return "D_M_YYYY"
|
||||
case LONG_DATE_FORMAT_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(f))
|
||||
}
|
||||
}
|
||||
|
||||
// ShortDateFormat represents short date format
|
||||
type ShortDateFormat byte
|
||||
|
||||
// Short Date Format
|
||||
const (
|
||||
SHORT_DATE_FORMAT_DEFAULT ShortDateFormat = 0
|
||||
SHORT_DATE_FORMAT_YYYY_M_D ShortDateFormat = 1
|
||||
SHORT_DATE_FORMAT_M_D_YYYY ShortDateFormat = 2
|
||||
SHORT_DATE_FORMAT_D_M_YYYY ShortDateFormat = 3
|
||||
SHORT_DATE_FORMAT_INVALID ShortDateFormat = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the short date format enum
|
||||
func (f ShortDateFormat) String() string {
|
||||
switch f {
|
||||
case SHORT_DATE_FORMAT_DEFAULT:
|
||||
return "Default"
|
||||
case SHORT_DATE_FORMAT_YYYY_M_D:
|
||||
return "YYYY_MM_D"
|
||||
case SHORT_DATE_FORMAT_M_D_YYYY:
|
||||
return "M_D_YYYY"
|
||||
case SHORT_DATE_FORMAT_D_M_YYYY:
|
||||
return "D_M_YYYY"
|
||||
case SHORT_DATE_FORMAT_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(f))
|
||||
}
|
||||
}
|
||||
|
||||
// LongTimeFormat represents long time format
|
||||
type LongTimeFormat byte
|
||||
|
||||
// Long Time Format
|
||||
const (
|
||||
LONG_TIME_FORMAT_DEFAULT LongTimeFormat = 0
|
||||
LONG_TIME_FORMAT_HH_MM_SS LongTimeFormat = 1
|
||||
LONG_TIME_FORMAT_A_HH_MM_SS LongTimeFormat = 2
|
||||
LONG_TIME_FORMAT_HH_MM_SS_A LongTimeFormat = 3
|
||||
LONG_TIME_FORMAT_INVALID LongTimeFormat = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the long time format enum
|
||||
func (f LongTimeFormat) String() string {
|
||||
switch f {
|
||||
case LONG_TIME_FORMAT_DEFAULT:
|
||||
return "Default"
|
||||
case LONG_TIME_FORMAT_HH_MM_SS:
|
||||
return "HH_MM_SS"
|
||||
case LONG_TIME_FORMAT_A_HH_MM_SS:
|
||||
return "A_HH_MM_SS"
|
||||
case LONG_TIME_FORMAT_HH_MM_SS_A:
|
||||
return "HH_MM_SS_A"
|
||||
case LONG_TIME_FORMAT_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(f))
|
||||
}
|
||||
}
|
||||
|
||||
// ShortTimeFormat represents short time format
|
||||
type ShortTimeFormat byte
|
||||
|
||||
// Short Time Format
|
||||
const (
|
||||
SHORT_TIME_FORMAT_DEFAULT ShortTimeFormat = 0
|
||||
SHORT_TIME_FORMAT_HH_MM ShortTimeFormat = 1
|
||||
SHORT_TIME_FORMAT_A_HH_MM ShortTimeFormat = 2
|
||||
SHORT_TIME_FORMAT_HH_MM_A ShortTimeFormat = 3
|
||||
SHORT_TIME_FORMAT_INVALID ShortTimeFormat = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the short time format enum
|
||||
func (f ShortTimeFormat) String() string {
|
||||
switch f {
|
||||
case SHORT_TIME_FORMAT_DEFAULT:
|
||||
return "Default"
|
||||
case SHORT_TIME_FORMAT_HH_MM:
|
||||
return "HH_MM"
|
||||
case SHORT_TIME_FORMAT_A_HH_MM:
|
||||
return "A_HH_MM"
|
||||
case SHORT_TIME_FORMAT_HH_MM_A:
|
||||
return "HH_MM_A"
|
||||
case SHORT_TIME_FORMAT_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(f))
|
||||
}
|
||||
}
|
||||
+43
-51
@@ -7,45 +7,6 @@ import (
|
||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||
)
|
||||
|
||||
// WeekDay represents week day
|
||||
type WeekDay byte
|
||||
|
||||
// Week days
|
||||
const (
|
||||
WEEKDAY_SUNDAY WeekDay = 0
|
||||
WEEKDAY_MONDAY WeekDay = 1
|
||||
WEEKDAY_TUESDAY WeekDay = 2
|
||||
WEEKDAY_WEDNESDAY WeekDay = 3
|
||||
WEEKDAY_THURSDAY WeekDay = 4
|
||||
WEEKDAY_FRIDAY WeekDay = 5
|
||||
WEEKDAY_SATURDAY WeekDay = 6
|
||||
WEEKDAY_INVALID WeekDay = 255
|
||||
)
|
||||
|
||||
// String returns a textual representation of the week day enum
|
||||
func (d WeekDay) String() string {
|
||||
switch d {
|
||||
case WEEKDAY_SUNDAY:
|
||||
return "Sunday"
|
||||
case WEEKDAY_MONDAY:
|
||||
return "Monday"
|
||||
case WEEKDAY_TUESDAY:
|
||||
return "Tuesday"
|
||||
case WEEKDAY_WEDNESDAY:
|
||||
return "Wednesday"
|
||||
case WEEKDAY_THURSDAY:
|
||||
return "Thursday"
|
||||
case WEEKDAY_FRIDAY:
|
||||
return "Friday"
|
||||
case WEEKDAY_SATURDAY:
|
||||
return "Saturday"
|
||||
case WEEKDAY_INVALID:
|
||||
return "Invalid"
|
||||
default:
|
||||
return fmt.Sprintf("Invalid(%d)", int(d))
|
||||
}
|
||||
}
|
||||
|
||||
// TransactionEditScope represents the scope which transaction can be edited
|
||||
type TransactionEditScope byte
|
||||
|
||||
@@ -93,10 +54,15 @@ type User struct {
|
||||
Nickname string `xorm:"VARCHAR(64) NOT NULL"`
|
||||
Password string `xorm:"VARCHAR(64) NOT NULL"`
|
||||
Salt string `xorm:"VARCHAR(10) NOT NULL"`
|
||||
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
|
||||
DefaultAccountId int64
|
||||
FirstDayOfWeek WeekDay `xorm:"TINYINT NOT NULL"`
|
||||
TransactionEditScope TransactionEditScope `xorm:"TINYINT NOT NULL"`
|
||||
Language string `xorm:"VARCHAR(10)"`
|
||||
DefaultCurrency string `xorm:"VARCHAR(3) NOT NULL"`
|
||||
FirstDayOfWeek WeekDay `xorm:"TINYINT NOT NULL"`
|
||||
LongDateFormat LongDateFormat `xorm:"TINYINT"`
|
||||
ShortDateFormat ShortDateFormat `xorm:"TINYINT"`
|
||||
LongTimeFormat LongTimeFormat `xorm:"TINYINT"`
|
||||
ShortTimeFormat ShortTimeFormat `xorm:"TINYINT"`
|
||||
Deleted bool `xorm:"NOT NULL"`
|
||||
EmailVerified bool `xorm:"NOT NULL"`
|
||||
CreatedUnixTime int64
|
||||
@@ -110,10 +76,15 @@ type UserBasicInfo struct {
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
DefaultAccountId int64 `json:"defaultAccountId,string"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
TransactionEditScope TransactionEditScope `json:"transactionEditScope"`
|
||||
Language string `json:"language"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
LongDateFormat LongDateFormat `json:"longDateFormat"`
|
||||
ShortDateFormat ShortDateFormat `json:"shortDateFormat"`
|
||||
LongTimeFormat LongTimeFormat `json:"longTimeFormat"`
|
||||
ShortTimeFormat ShortTimeFormat `json:"shortTimeFormat"`
|
||||
}
|
||||
|
||||
// UserLoginRequest represents all parameters of user login request
|
||||
@@ -128,6 +99,7 @@ type UserRegisterRequest struct {
|
||||
Email string `json:"email" binding:"required,notBlank,max=100,validEmail"`
|
||||
Nickname string `json:"nickname" binding:"required,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"required,min=6,max=128"`
|
||||
Language string `json:"language" binding:"required,min=2,max=16"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"required,len=3,validCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek" binding:"min=0,max=6"`
|
||||
}
|
||||
@@ -138,10 +110,15 @@ type UserProfileUpdateRequest struct {
|
||||
Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"`
|
||||
Password string `json:"password" binding:"omitempty,min=6,max=128"`
|
||||
OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"omitempty,len=3,validCurrency"`
|
||||
DefaultAccountId int64 `json:"defaultAccountId,string" binding:"omitempty,min=1"`
|
||||
FirstDayOfWeek *WeekDay `json:"firstDayOfWeek" binding:"omitempty,min=0,max=6"`
|
||||
TransactionEditScope *TransactionEditScope `json:"transactionEditScope" binding:"omitempty,min=0,max=7"`
|
||||
Language string `json:"language" binding:"omitempty,min=2,max=16"`
|
||||
DefaultCurrency string `json:"defaultCurrency" binding:"omitempty,len=3,validCurrency"`
|
||||
FirstDayOfWeek *WeekDay `json:"firstDayOfWeek" binding:"omitempty,min=0,max=6"`
|
||||
LongDateFormat *LongDateFormat `json:"longDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortDateFormat *ShortDateFormat `json:"shortDateFormat" binding:"omitempty,min=0,max=3"`
|
||||
LongTimeFormat *LongTimeFormat `json:"longTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
ShortTimeFormat *ShortTimeFormat `json:"shortTimeFormat" binding:"omitempty,min=0,max=3"`
|
||||
}
|
||||
|
||||
// UserProfileUpdateResponse represents the data returns to frontend after updating profile
|
||||
@@ -155,10 +132,15 @@ type UserProfileResponse struct {
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Nickname string `json:"nickname"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
DefaultAccountId int64 `json:"defaultAccountId,string"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
TransactionEditScope TransactionEditScope `json:"transactionEditScope"`
|
||||
Language string `json:"language"`
|
||||
DefaultCurrency string `json:"defaultCurrency"`
|
||||
FirstDayOfWeek WeekDay `json:"firstDayOfWeek"`
|
||||
LongDateFormat LongDateFormat `json:"longDateFormat"`
|
||||
ShortDateFormat ShortDateFormat `json:"shortDateFormat"`
|
||||
LongTimeFormat LongTimeFormat `json:"longTimeFormat"`
|
||||
ShortTimeFormat ShortTimeFormat `json:"shortTimeFormat"`
|
||||
LastLoginAt int64 `json:"lastLoginAt"`
|
||||
}
|
||||
|
||||
@@ -210,10 +192,15 @@ func (u *User) ToUserBasicInfo() *UserBasicInfo {
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
Nickname: u.Nickname,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
DefaultAccountId: u.DefaultAccountId,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
TransactionEditScope: u.TransactionEditScope,
|
||||
Language: u.Language,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
LongDateFormat: u.LongDateFormat,
|
||||
ShortDateFormat: u.ShortDateFormat,
|
||||
LongTimeFormat: u.LongTimeFormat,
|
||||
ShortTimeFormat: u.ShortTimeFormat,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,10 +210,15 @@ func (u *User) ToUserProfileResponse() *UserProfileResponse {
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
Nickname: u.Nickname,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
DefaultAccountId: u.DefaultAccountId,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
TransactionEditScope: u.TransactionEditScope,
|
||||
Language: u.Language,
|
||||
DefaultCurrency: u.DefaultCurrency,
|
||||
FirstDayOfWeek: u.FirstDayOfWeek,
|
||||
LongDateFormat: u.LongDateFormat,
|
||||
ShortDateFormat: u.ShortDateFormat,
|
||||
LongTimeFormat: u.LongTimeFormat,
|
||||
ShortTimeFormat: u.ShortTimeFormat,
|
||||
LastLoginAt: u.LastLoginUnixTime,
|
||||
}
|
||||
}
|
||||
|
||||
+27
-7
@@ -150,7 +150,7 @@ func (s *UserService) CreateUser(user *models.User) error {
|
||||
}
|
||||
|
||||
// UpdateUser saves an existed user model to database
|
||||
func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err error) {
|
||||
func (s *UserService) UpdateUser(user *models.User, modifyUserLanguage bool) (keyProfileUpdated bool, err error) {
|
||||
if user.Uid <= 0 {
|
||||
return false, errs.ErrUserIdInvalid
|
||||
}
|
||||
@@ -186,20 +186,40 @@ func (s *UserService) UpdateUser(user *models.User) (keyProfileUpdated bool, err
|
||||
updateCols = append(updateCols, "nickname")
|
||||
}
|
||||
|
||||
if user.DefaultCurrency != "" {
|
||||
updateCols = append(updateCols, "default_currency")
|
||||
}
|
||||
|
||||
if user.DefaultAccountId > 0 {
|
||||
updateCols = append(updateCols, "default_account_id")
|
||||
}
|
||||
|
||||
if models.TRANSACTION_EDIT_SCOPE_NONE <= user.TransactionEditScope && user.TransactionEditScope <= models.TRANSACTION_EDIT_SCOPE_THIS_YEAR_OR_LATER {
|
||||
updateCols = append(updateCols, "transaction_edit_scope")
|
||||
}
|
||||
|
||||
if modifyUserLanguage || user.Language != "" {
|
||||
updateCols = append(updateCols, "language")
|
||||
}
|
||||
|
||||
if user.DefaultCurrency != "" {
|
||||
updateCols = append(updateCols, "default_currency")
|
||||
}
|
||||
|
||||
if models.WEEKDAY_SUNDAY <= user.FirstDayOfWeek && user.FirstDayOfWeek <= models.WEEKDAY_SATURDAY {
|
||||
updateCols = append(updateCols, "first_day_of_week")
|
||||
}
|
||||
|
||||
if models.TRANSACTION_EDIT_SCOPE_NONE <= user.TransactionEditScope && user.TransactionEditScope <= models.TRANSACTION_EDIT_SCOPE_THIS_YEAR_OR_LATER {
|
||||
updateCols = append(updateCols, "transaction_edit_scope")
|
||||
if models.LONG_DATE_FORMAT_DEFAULT <= user.LongDateFormat && user.LongDateFormat <= models.LONG_DATE_FORMAT_D_M_YYYY {
|
||||
updateCols = append(updateCols, "long_date_format")
|
||||
}
|
||||
|
||||
if models.SHORT_DATE_FORMAT_DEFAULT <= user.ShortDateFormat && user.ShortDateFormat <= models.SHORT_DATE_FORMAT_D_M_YYYY {
|
||||
updateCols = append(updateCols, "short_date_format")
|
||||
}
|
||||
|
||||
if models.LONG_TIME_FORMAT_DEFAULT <= user.LongTimeFormat && user.LongTimeFormat <= models.LONG_TIME_FORMAT_HH_MM_SS_A {
|
||||
updateCols = append(updateCols, "long_time_format")
|
||||
}
|
||||
|
||||
if models.SHORT_TIME_FORMAT_DEFAULT <= user.ShortTimeFormat && user.ShortTimeFormat <= models.SHORT_TIME_FORMAT_HH_MM_A {
|
||||
updateCols = append(updateCols, "short_time_format")
|
||||
}
|
||||
|
||||
user.UpdatedUnixTime = now
|
||||
|
||||
Reference in New Issue
Block a user