mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 08:44:25 +08:00
code refactor
This commit is contained in:
@@ -60,7 +60,7 @@ func (s *AccountService) GetMaxDisplayOrder(uid int64, category models.AccountCa
|
||||
}
|
||||
|
||||
account := &models.Account{}
|
||||
has, err := s.UserDataDB(uid).Cols("uid", "deleted", "parent_account_id", "display_order").Where("uid=? AND deleted=? AND parent_account_id=? AND category=?", uid, false, models.ACCOUNT_PARENT_ID_LEVEL_ONE, category).OrderBy("display_order desc").Limit(1).Get(account)
|
||||
has, err := s.UserDataDB(uid).Cols("uid", "deleted", "parent_account_id", "display_order").Where("uid=? AND deleted=? AND parent_account_id=? AND category=?", uid, false, models.LevelOneAccountParentId, category).OrderBy("display_order desc").Limit(1).Get(account)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -314,8 +314,8 @@ func (s *TokenService) getUserAgent(ctx *core.Context) string {
|
||||
userAgent = ctx.Request.UserAgent()
|
||||
}
|
||||
|
||||
if len(userAgent) > models.TOKEN_USER_AGENT_MAX_LENGTH {
|
||||
userAgent = utils.SubString(userAgent, 0, models.TOKEN_USER_AGENT_MAX_LENGTH)
|
||||
if len(userAgent) > models.TokenMaxUserAgentLength {
|
||||
userAgent = utils.SubString(userAgent, 0, models.TokenMaxUserAgentLength)
|
||||
}
|
||||
|
||||
return userAgent
|
||||
|
||||
@@ -80,7 +80,7 @@ func (s *TransactionCategoryService) GetMaxDisplayOrder(uid int64, categoryType
|
||||
}
|
||||
|
||||
category := &models.TransactionCategory{}
|
||||
has, err := s.UserDataDB(uid).Cols("uid", "deleted", "parent_category_id", "display_order").Where("uid=? AND deleted=? AND type=? AND parent_category_id=?", uid, false, categoryType, models.TRANSACTION_PARENT_ID_LEVEL_ONE).OrderBy("display_order desc").Limit(1).Get(category)
|
||||
has, err := s.UserDataDB(uid).Cols("uid", "deleted", "parent_category_id", "display_order").Where("uid=? AND deleted=? AND type=? AND parent_category_id=?", uid, false, categoryType, models.LevelOneTransactionParentId).OrderBy("display_order desc").Limit(1).Get(category)
|
||||
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -16,10 +16,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
TWOFACTOR_PERIOD uint = 30 // seconds
|
||||
TWOFACTOR_SECRET_SIZE uint = 20 // bytes
|
||||
TWOFACTOR_RECOVERY_CODE_COUNT int = 10
|
||||
TWOFACTOR_RECOVERY_CODE_LENGTH int = 10 // bytes
|
||||
twoFactorPeriod uint = 30 // seconds
|
||||
twoFactorSecretSize uint = 20 // bytes
|
||||
twoFactorRecoveryCodeCount int = 10
|
||||
twoFactorRecoveryCodeLength int = 10 // bytes
|
||||
)
|
||||
|
||||
type TwoFactorAuthorizationService struct {
|
||||
@@ -73,8 +73,8 @@ func (s *TwoFactorAuthorizationService) GenerateTwoFactorSecret(user *models.Use
|
||||
key, err := totp.Generate(totp.GenerateOpts{
|
||||
Issuer: s.CurrentConfig().AppName,
|
||||
AccountName: user.Username,
|
||||
Period: TWOFACTOR_PERIOD,
|
||||
SecretSize: TWOFACTOR_SECRET_SIZE,
|
||||
Period: twoFactorPeriod,
|
||||
SecretSize: twoFactorSecretSize,
|
||||
})
|
||||
|
||||
return key, err
|
||||
@@ -147,10 +147,10 @@ func (s *TwoFactorAuthorizationService) GetAndUseUserTwoFactorRecoveryCode(uid i
|
||||
}
|
||||
|
||||
func (s *TwoFactorAuthorizationService) GenerateTwoFactorRecoveryCodes() ([]string, error) {
|
||||
recoveryCodes := make([]string, TWOFACTOR_RECOVERY_CODE_COUNT)
|
||||
recoveryCodes := make([]string, twoFactorRecoveryCodeCount)
|
||||
|
||||
for i := 0; i < TWOFACTOR_RECOVERY_CODE_COUNT; i++ {
|
||||
recoveryCode, err := utils.GetRandomNumberOrLetter(TWOFACTOR_RECOVERY_CODE_LENGTH)
|
||||
for i := 0; i < twoFactorRecoveryCodeCount; i++ {
|
||||
recoveryCode, err := utils.GetRandomNumberOrLetter(twoFactorRecoveryCodeLength)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user