Skip to content

Commit f300d86

Browse files
committed
Refactor code
1 parent 70d55ac commit f300d86

File tree

3 files changed

+30
-26
lines changed

3 files changed

+30
-26
lines changed

authenticator.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ func NewBasicAuthenticatorWithTwoFactors(status Status, check func(context.Conte
4444
maxPasswordFailed = options[1]
4545
}
4646
service := &Authenticator{
47-
Status: status,
48-
PayloadConfig: payloadConfig,
49-
Check: check,
50-
Repository: userInfoService,
51-
Privileges: loadPrivileges,
52-
GenerateToken: generateToken,
53-
TokenConfig: tokenConfig,
54-
CodeExpires: codeExpires,
55-
CodeRepository: codeService,
56-
SendCode: sendCode,
57-
GenerateCode: generate,
58-
LockedMinutes: lockedMinutes,
47+
Status: status,
48+
PayloadConfig: payloadConfig,
49+
Check: check,
50+
Repository: userInfoService,
51+
Privileges: loadPrivileges,
52+
GenerateToken: generateToken,
53+
TokenConfig: tokenConfig,
54+
CodeExpires: codeExpires,
55+
CodeRepository: codeService,
56+
SendCode: sendCode,
57+
GenerateCode: generate,
58+
LockedMinutes: lockedMinutes,
5959
MaxPasswordFailed: maxPasswordFailed,
6060
}
6161
return service
@@ -348,7 +348,7 @@ func UserAccountToPayload(ctx context.Context, u *UserAccount, s PayloadConfig)
348348
payload[s.Contact] = u.Contact
349349
u.Contact = nil
350350
}
351-
if s.UserType != "" && u.Type != nil{
351+
if s.UserType != "" && u.Type != nil {
352352
payload[s.UserType] = u.Type
353353
u.Type = nil
354354
}
@@ -372,6 +372,9 @@ func ToPayload(ctx context.Context, user *UserInfo, s PayloadConfig) map[string]
372372
if len(s.Id) > 0 && len(user.Id) > 0 {
373373
payload[s.Id] = user.Id
374374
}
375+
if len(s.Lang) > 0 && user.Language != nil {
376+
payload[s.Lang] = user.Language
377+
}
375378
if len(s.Username) > 0 && len(user.Username) > 0 {
376379
payload[s.Username] = user.Username
377380
}

payload_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ type PayloadConfig struct {
44
Ip string `yaml:"ip" mapstructure:"ip" json:"ip,omitempty" gorm:"column:ip" bson:"ip,omitempty" dynamodbav:"ip,omitempty" firestore:"ip,omitempty"`
55
Id string `yaml:"id" mapstructure:"id" json:"id,omitempty" gorm:"column:id" bson:"id,omitempty" dynamodbav:"id,omitempty" firestore:"id,omitempty"`
66
Username string `yaml:"username" mapstructure:"username" json:"username,omitempty" gorm:"column:username" bson:"username,omitempty" dynamodbav:"username,omitempty" firestore:"username,omitempty"`
7+
Lang string `yaml:"lang" mapstructure:"lang" json:"lang,omitempty" gorm:"column:lang" bson:"lang,omitempty" dynamodbav:"lang,omitempty" firestore:"lang,omitempty"`
78
Contact string `yaml:"contact" mapstructure:"contact" json:"contact,omitempty" gorm:"column:contact" bson:"contact,omitempty" dynamodbav:"contact,omitempty" firestore:"contact,omitempty"`
89
Email string `yaml:"email" mapstructure:"email" json:"email,omitempty" gorm:"column:email" bson:"email,omitempty" dynamodbav:"email,omitempty" firestore:"email,omitempty"`
910
Phone string `yaml:"phone" mapstructure:"phone" json:"phone,omitempty" gorm:"column:phone" bson:"phone,omitempty" dynamodbav:"phone,omitempty" firestore:"phone,omitempty"`

user_info.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ type UserInfo struct {
88
Contact *string `yaml:"contact" mapstructure:"contact" json:"contact,omitempty" gorm:"column:contact" bson:"contact,omitempty" dynamodbav:"contact,omitempty" firestore:"contact,omitempty"`
99
Email *string `yaml:"email" mapstructure:"email" json:"email,omitempty" gorm:"column:email" bson:"email,omitempty" dynamodbav:"email,omitempty" firestore:"email,omitempty"`
1010
Phone *string `yaml:"phone" mapstructure:"phone" json:"phone,omitempty" gorm:"column:phone" bson:"phone,omitempty" dynamodbav:"phone,omitempty" firestore:"phone,omitempty"`
11-
DisplayName *string `yaml:"display_name" mapstructure:"display_name" json:"displayName,omitempty" gorm:"column:displayname" bson:"displayName,omitempty" dynamodbav:"displayName,omitempty" firestore:"displayName,omitempty"`
11+
DisplayName *string `yaml:"display_name" mapstructure:"display_name" json:"displayName,omitempty" gorm:"column:display_name" bson:"displayName,omitempty" dynamodbav:"displayName,omitempty" firestore:"displayName,omitempty"`
1212
Password string `yaml:"password" mapstructure:"password" json:"password,omitempty" gorm:"column:password" bson:"password,omitempty" dynamodbav:"password,omitempty" firestore:"password,omitempty"`
1313
Disable bool `yaml:"disable" mapstructure:"disable" json:"disable,omitempty" gorm:"column:disable" bson:"disable,omitempty" dynamodbav:"disable,omitempty" firestore:"disable,omitempty" true:"D"`
1414
Deactivated *bool `yaml:"deactivated" mapstructure:"deactivated" json:"deactivated,omitempty" gorm:"column:deactivated" bson:"deactivated,omitempty" dynamodbav:"deactivated,omitempty" firestore:"deactivated,omitempty" true:"I"`
1515
Suspended bool `yaml:"suspended" mapstructure:"suspended" json:"suspended,omitempty" gorm:"column:suspended" bson:"suspended,omitempty" dynamodbav:"suspended,omitempty" firestore:"suspended,omitempty" true:"S"`
16-
LockedUntilTime *time.Time `yaml:"locked_until_time" mapstructure:"locked_until_time" json:"lockedUntilTime,omitempty" gorm:"column:lockeduntiltime" bson:"lockedUntilTime,omitempty" dynamodbav:"lockedUntilTime,omitempty" firestore:"lockedUntilTime,omitempty"`
17-
SuccessTime *time.Time `yaml:"success_time" mapstructure:"success_time" json:"successTime,omitempty" gorm:"column:successtime" bson:"successTime,omitempty" dynamodbav:"successTime,omitempty" firestore:"successTime,omitempty"`
18-
FailTime *time.Time `yaml:"fail_time" mapstructure:"fail_time" json:"failTime,omitempty" gorm:"column:failtime" bson:"failTime,omitempty" dynamodbav:"failTime,omitempty" firestore:"failTime,omitempty"`
19-
FailCount *int `yaml:"fail_count" mapstructure:"fail_count" json:"failCount,omitempty" gorm:"column:failcount" bson:"failCount,omitempty" dynamodbav:"failCount,omitempty" firestore:"failCount,omitempty"`
16+
LockedUntilTime *time.Time `yaml:"locked_until_time" mapstructure:"locked_until_time" json:"lockedUntilTime,omitempty" gorm:"column:locked_until_time" bson:"lockedUntilTime,omitempty" dynamodbav:"lockedUntilTime,omitempty" firestore:"lockedUntilTime,omitempty"`
17+
SuccessTime *time.Time `yaml:"success_time" mapstructure:"success_time" json:"successTime,omitempty" gorm:"column:success_time" bson:"successTime,omitempty" dynamodbav:"successTime,omitempty" firestore:"successTime,omitempty"`
18+
FailTime *time.Time `yaml:"fail_time" mapstructure:"fail_time" json:"failTime,omitempty" gorm:"column:fail_time" bson:"failTime,omitempty" dynamodbav:"failTime,omitempty" firestore:"failTime,omitempty"`
19+
FailCount *int `yaml:"fail_count" mapstructure:"fail_count" json:"failCount,omitempty" gorm:"column:fail_count" bson:"failCount,omitempty" dynamodbav:"failCount,omitempty" firestore:"failCount,omitempty"`
2020
PasswordChangedTime *time.Time `yaml:"password_changed_time" mapstructure:"password_changed_time" json:"passwordChangedTime,omitempty" gorm:"column:passwordchangedtime" bson:"passwordChangedTime,omitempty" dynamodbav:"passwordChangedTime,omitempty" firestore:"passwordChangedTime,omitempty"`
21-
MaxPasswordAge *int32 `yaml:"max_password_age" mapstructure:"max_password_age" json:"maxPasswordAge,omitempty" gorm:"column:maxpasswordage" bson:"maxPasswordAge,omitempty" dynamodbav:"maxPasswordAge,omitempty" firestore:"maxPasswordAge,omitempty"`
21+
MaxPasswordAge *int32 `yaml:"max_password_age" mapstructure:"max_password_age" json:"maxPasswordAge,omitempty" gorm:"column:max_password_age" bson:"maxPasswordAge,omitempty" dynamodbav:"maxPasswordAge,omitempty" firestore:"maxPasswordAge,omitempty"`
2222
UserType *string `yaml:"user_type" mapstructure:"user_type" json:"userType,omitempty" gorm:"column:usertype" bson:"userType,omitempty" dynamodbav:"userType,omitempty" firestore:"userType,omitempty"`
2323
Roles []string `yaml:"roles" mapstructure:"roles" json:"roles,omitempty" gorm:"column:roles" bson:"roles,omitempty" dynamodbav:"roles,omitempty" firestore:"roles,omitempty"`
2424
Privileges []string `yaml:"privileges" mapstructure:"privileges" json:"privileges,omitempty" gorm:"column:privileges" bson:"privileges,omitempty" dynamodbav:"privileges,omitempty" firestore:"privileges,omitempty"`
25-
AccessDateFrom *time.Time `yaml:"access_date_from" mapstructure:"access_date_from" json:"accessDateFrom,omitempty" gorm:"column:accessdatefrom" bson:"accessDateFrom,omitempty" dynamodbav:"accessDateFrom,omitempty" firestore:"accessDateFrom,omitempty"`
26-
AccessDateTo *time.Time `yaml:"access_date_to" mapstructure:"access_date_to" json:"accessDateTo,omitempty" gorm:"column:accessdateto" bson:"accessDateTo,omitempty" dynamodbav:"accessDateTo,omitempty" firestore:"accessDateTo,omitempty"`
27-
AccessTimeFrom *time.Time `yaml:"access_time_from" mapstructure:"access_time_from" json:"accessTimeFrom,omitempty" gorm:"column:accesstimefrom" bson:"accessTimeFrom,omitempty" dynamodbav:"accessTimeFrom,omitempty" firestore:"accessTimeFrom,omitempty"`
28-
AccessTimeTo *time.Time `yaml:"access_time_to" mapstructure:"access_time_to" json:"accessTimeTo,omitempty" gorm:"column:accesstimeto" bson:"accessTimeTo,omitempty" dynamodbav:"accessTimeTo,omitempty" firestore:"accessTimeTo,omitempty"`
29-
TwoFactors bool `yaml:"two_factors" mapstructure:"two_factors" json:"twoFactors,omitempty" gorm:"column:twofactors" bson:"twoFactors,omitempty" dynamodbav:"twoFactors,omitempty" firestore:"twoFactors,omitempty" true:"A"`
25+
AccessDateFrom *time.Time `yaml:"access_date_from" mapstructure:"access_date_from" json:"accessDateFrom,omitempty" gorm:"column:access_date_from" bson:"accessDateFrom,omitempty" dynamodbav:"accessDateFrom,omitempty" firestore:"accessDateFrom,omitempty"`
26+
AccessDateTo *time.Time `yaml:"access_date_to" mapstructure:"access_date_to" json:"accessDateTo,omitempty" gorm:"column:access_date_to" bson:"accessDateTo,omitempty" dynamodbav:"accessDateTo,omitempty" firestore:"accessDateTo,omitempty"`
27+
AccessTimeFrom *time.Time `yaml:"access_time_from" mapstructure:"access_time_from" json:"accessTimeFrom,omitempty" gorm:"column:access_time_from" bson:"accessTimeFrom,omitempty" dynamodbav:"accessTimeFrom,omitempty" firestore:"accessTimeFrom,omitempty"`
28+
AccessTimeTo *time.Time `yaml:"access_time_to" mapstructure:"access_time_to" json:"accessTimeTo,omitempty" gorm:"column:access_time_to" bson:"accessTimeTo,omitempty" dynamodbav:"accessTimeTo,omitempty" firestore:"accessTimeTo,omitempty"`
29+
TwoFactors bool `yaml:"two_factors" mapstructure:"two_factors" json:"twoFactors,omitempty" gorm:"column:two_factors" bson:"twoFactors,omitempty" dynamodbav:"twoFactors,omitempty" firestore:"twoFactors,omitempty" true:"A"`
3030
Language *string `yaml:"language" mapstructure:"language" json:"language,omitempty" gorm:"column:language" bson:"language,omitempty" dynamodbav:"language,omitempty" firestore:"language,omitempty"`
3131
Gender *string `yaml:"gender" mapstructure:"gender" json:"gender,omitempty" gorm:"column:gender" bson:"gender,omitempty" dynamodbav:"gender,omitempty" firestore:"gender,omitempty"`
3232
DateFormat *string `yaml:"date_format" mapstructure:"date_format" json:"dateFormat,omitempty" gorm:"column:dateformat" bson:"dateFormat,omitempty" dynamodbav:"dateFormat,omitempty" firestore:"dateFormat,omitempty"`
33-
TimeFormat *string `yaml:"time_format" mapstructure:"time_format" json:"timeFormat,omitempty" gorm:"column:timeformat" bson:"timeFormat,omitempty" dynamodbav:"timeFormat,omitempty" firestore:"timeFormat,omitempty"`
34-
ImageURL *string `yaml:"image_url" mapstructure:"image_url" json:"imageURL,omitempty" gorm:"column:imageurl" bson:"imageURL,omitempty" dynamodbav:"imageURL,omitempty" firestore:"imageURL,omitempty"`
33+
TimeFormat *string `yaml:"time_format" mapstructure:"time_format" json:"timeFormat,omitempty" gorm:"column:time_format" bson:"timeFormat,omitempty" dynamodbav:"timeFormat,omitempty" firestore:"timeFormat,omitempty"`
34+
ImageURL *string `yaml:"image_url" mapstructure:"image_url" json:"imageURL,omitempty" gorm:"column:image_url" bson:"imageURL,omitempty" dynamodbav:"imageURL,omitempty" firestore:"imageURL,omitempty"`
3535
Status *string `yaml:"status" mapstructure:"status" json:"status,omitempty" gorm:"column:status" bson:"status,omitempty" dynamodbav:"status,omitempty" firestore:"status,omitempty"`
3636
}

0 commit comments

Comments
 (0)