Skip to content

Commit 1c2c031

Browse files
authored
fix:issue #644 (#645)
* fix:issue #644 * fix:移除重复定义的函数 * refactor:checkMobile=>checkMobilePhone * refactor:调整checkEmail逻辑 * fix:调整错误信息 * refactor:调整错误信息描述
1 parent c3cb151 commit 1c2c031

File tree

9 files changed

+43
-31
lines changed

9 files changed

+43
-31
lines changed

auth/defaultauth/user.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func checkCreateUser(req *api.User) *api.Response {
559559
return api.NewUserResponse(api.InvalidUserOwners, req)
560560
}
561561

562-
if err := checkMobile(req.Mobile); err != nil {
562+
if err := checkMobilePhone(req.Mobile); err != nil {
563563
return api.NewUserResponse(api.InvalidUserMobile, req)
564564
}
565565

@@ -587,6 +587,14 @@ func checkUpdateUser(req *api.User) *api.Response {
587587
return api.NewUserResponse(api.BadRequest, req)
588588
}
589589

590+
if err := checkMobilePhone(req.Mobile); err != nil {
591+
return api.NewUserResponse(api.InvalidUserMobile, req)
592+
}
593+
594+
if err := checkEmail(req.Email); err != nil {
595+
return api.NewUserResponse(api.InvalidUserEmail, req)
596+
}
597+
590598
return nil
591599
}
592600

auth/defaultauth/utils.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package defaultauth
2020
import (
2121
"context"
2222
"errors"
23+
"fmt"
2324
"regexp"
2425
"unicode/utf8"
2526

@@ -59,7 +60,6 @@ var storeCodeAPICodeMap = map[store.StatusCode]uint32{
5960

6061
var (
6162
regNameStr = regexp.MustCompile("^[\u4E00-\u9FA5A-Za-z0-9_\\-]+$")
62-
regEmail = regexp.MustCompile(`^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$`)
6363
)
6464

6565
// StoreCode2APICode store code to api code
@@ -130,8 +130,8 @@ func checkOwner(owner *wrappers.StringValue) error {
130130
return nil
131131
}
132132

133-
// checkMobile 检查用户的 mobile 信息
134-
func checkMobile(mobile *wrappers.StringValue) error {
133+
// checkMobilePhone 检查用户的 mobile phone 信息
134+
func checkMobilePhone(mobile *wrappers.StringValue) error {
135135
if mobile == nil {
136136
return nil
137137
}
@@ -140,8 +140,9 @@ func checkMobile(mobile *wrappers.StringValue) error {
140140
return nil
141141
}
142142

143-
if utf8.RuneCountInString(mobile.GetValue()) != 11 {
144-
return errors.New("invalid mobile")
143+
if utf8.RuneCountInString(mobile.GetValue()) > utils.MobilePhoneLength {
144+
return fmt.Errorf("invalid mobile, current is %s, length must be less than %d",
145+
mobile.GetValue(), utils.MobilePhoneLength)
145146
}
146147

147148
return nil
@@ -157,8 +158,9 @@ func checkEmail(email *wrappers.StringValue) error {
157158
return nil
158159
}
159160

160-
if ok := regEmail.MatchString(email.GetValue()); !ok {
161-
return errors.New("invalid email")
161+
if utf8.RuneCountInString(email.GetValue()) > utils.MaxEmailLength {
162+
return fmt.Errorf("invalid email, current is %s, length must be less than %d",
163+
email.GetValue(), utils.MaxEmailLength)
162164
}
163165

164166
return nil

common/utils/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ const (
9191
MaxPlatformNameLength = 128
9292
MaxPlatformDomainLength = 1024
9393
MaxPlatformQPS = 65535
94+
95+
MaxEmailLength = 64
96+
MobilePhoneLength = 11
9497
)
9598

9699
var resourceNameRE = regexp.MustCompile("^[0-9A-Za-z-./:_]+$")

polaris-server.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,6 @@ bootstrap:
7878
enable_register: true
7979
isolated: false
8080
services:
81-
- name: polaris.discover
82-
protocols:
83-
- service-grpc
84-
- name: polaris.healthcheck
85-
protocols:
86-
- service-grpc
8781
- name: polaris.checker
8882
protocols:
8983
- service-grpc

service/instance.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -610,21 +610,6 @@ func (s *Server) updateInstanceAttribute(req *api.Instance, instance *model.Inst
610610
return needUpdate
611611
}
612612

613-
func instanceLocationNeedUpdate(req *api.Location, old *api.Location) bool {
614-
615-
if req.GetRegion().GetValue() != old.GetRegion().GetValue() {
616-
return true
617-
}
618-
if req.GetZone().GetValue() != old.GetZone().GetValue() {
619-
return true
620-
}
621-
if req.GetCampus().GetValue() != old.GetCampus().GetValue() {
622-
return true
623-
}
624-
625-
return false
626-
}
627-
628613
// 健康检查的更新
629614
func updateHealthCheck(req *api.Instance, instance *model.Instance) bool {
630615
needUpdate := false

store/boltdb/default.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ const (
111111
var (
112112
namespacesToInit = []string{"default", namespacePolaris}
113113
servicesToInit = map[string]string{
114-
"polaris.discover": "1866010b40be6542db1a2cc846c7f51f",
115-
"polaris.healthcheck": "846c1866010b40b7f51fe6542db1a2cc",
116114
"polaris.checker": "fbca9bfa04ae4ead86e1ecf5811e32a9",
117115
"polaris.monitor": "bbfdda174ea64e11ac862adf14593c03",
118116
"polaris.config": "e6542db1a2cc846c1866010b40b7f51f",

store/boltdb/group.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ func doGroupPage(ret map[string]interface{}, offset uint32, limit uint32) []*mod
460460

461461
// GetGroupsForCache 查询用户分组数据,主要用于Cache更新
462462
func (gs *groupStore) GetGroupsForCache(mtime time.Time, firstUpdate bool) ([]*model.UserGroupDetail, error) {
463+
if firstUpdate {
464+
mtime = time.Time{}
465+
}
466+
463467
ret, err := gs.handler.LoadValuesByFilter(tblGroup, []string{GroupFieldModifyTime}, &groupForStore{},
464468
func(m map[string]interface{}) bool {
465469
mt := m[GroupFieldModifyTime].(time.Time)

store/boltdb/strategy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (ss *strategyStore) updateStrategy(tx *bolt.Tx, modify *model.ModifyStrateg
165165
computeResources(false, modify.AddResources, saveVal)
166166
computeResources(true, modify.RemoveResources, saveVal)
167167

168+
saveVal.ModifyTime = time.Now()
168169
if err := saveValue(tx, tblStrategy, saveVal.ID, saveVal); err != nil {
169170
logger.StoreScope().Error("[Store][Strategy] update auth_strategy", zap.Error(err),
170171
zap.String("id", saveVal.ID))
@@ -279,6 +280,7 @@ func (ss *strategyStore) operateStrategyResources(remove bool, resources []model
279280
}
280281

281282
computeResources(remove, ress, rule)
283+
rule.ModifyTime = time.Now()
282284
if err := saveValue(tx, tblStrategy, rule.ID, rule); err != nil {
283285
logger.StoreScope().Error("[Store][Strategy] operate strategy resource", zap.Error(err),
284286
zap.Bool("remove", remove), zap.String("id", id))
@@ -669,6 +671,10 @@ func comparePrincipalExist(principalType, principalId string, m map[string]inter
669671
func (ss *strategyStore) GetStrategyDetailsForCache(mtime time.Time,
670672
firstUpdate bool) ([]*model.StrategyDetail, error) {
671673

674+
if firstUpdate {
675+
mtime = time.Time{}
676+
}
677+
672678
ret, err := ss.handler.LoadValuesByFilter(tblStrategy, []string{StrategyFieldModifyTime}, &strategyForStore{},
673679
func(m map[string]interface{}) bool {
674680
mt := m[StrategyFieldModifyTime].(time.Time)

store/boltdb/user.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ func (us *userStore) UpdateUser(user *model.User) error {
142142
properties[UserFieldToken] = user.Token
143143
properties[UserFieldTokenEnable] = user.TokenEnable
144144
properties[UserFieldPassword] = user.Password
145+
properties[UserFieldEmail] = user.Email
146+
properties[UserFieldMobile] = user.Mobile
145147
properties[UserFieldModifyTime] = time.Now()
146148

147149
err := us.handler.UpdateValue(tblUser, user.ID, properties)
@@ -396,6 +398,12 @@ func (us *userStore) getUsers(filters map[string]string, offset uint32, limit ui
396398
}
397399
}
398400

401+
if queryId, ok := filters["id"]; ok {
402+
if queryId != saveId {
403+
return false
404+
}
405+
}
406+
399407
return true
400408
})
401409

@@ -490,6 +498,10 @@ func (us *userStore) getGroupUsers(filters map[string]string, offset uint32, lim
490498

491499
// GetUsersForCache
492500
func (us *userStore) GetUsersForCache(mtime time.Time, firstUpdate bool) ([]*model.User, error) {
501+
if firstUpdate {
502+
mtime = time.Time{}
503+
}
504+
493505
ret, err := us.handler.LoadValuesByFilter(tblUser, []string{UserFieldModifyTime}, &userForStore{},
494506
func(m map[string]interface{}) bool {
495507
mt := m[UserFieldModifyTime].(time.Time)

0 commit comments

Comments
 (0)