File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ package user
17
17
import (
18
18
"errors"
19
19
"github.com/openimsdk/protocol/constant"
20
+ "github.com/openimsdk/protocol/util/datautil"
20
21
)
21
22
22
23
func (x * GetAllUserIDReq ) Check () error {
@@ -140,11 +141,19 @@ func (x *GetPaginationUsersReq) Check() error {
140
141
141
142
func (x * UserRegisterReq ) Check () error {
142
143
if x .Users == nil {
143
- return errors .New ("Users are empty" )
144
+ return errors .New ("users are empty" )
145
+ }
146
+ for _ , u := range x .Users {
147
+ switch {
148
+ case u == nil :
149
+ return errors .New ("user is empty" )
150
+ case datautil .IsLegalUserID (u .UserID ):
151
+ return errors .New ("userID is legal" )
152
+ }
144
153
}
145
154
for _ , u := range x .Users {
146
155
if u .Nickname == "" {
147
- return errors .New ("User name is empty" )
156
+ return errors .New ("user name is empty" )
148
157
}
149
158
}
150
159
Original file line number Diff line number Diff line change
1
+ package datautil
2
+
3
+ import "unicode"
4
+
5
+ // IsLegalUserID check if str is legal userID(Only contain letter/number/_).
6
+ func IsLegalUserID (str string ) bool {
7
+ for _ , r := range str {
8
+ if ! IsAlphanumeric (r ) && r != '_' {
9
+ return false
10
+ }
11
+ }
12
+ return true
13
+ }
14
+
15
+ // IsAlphanumeric check if b is a letter or number
16
+ func IsAlphanumeric (b rune ) bool {
17
+ if ! unicode .IsLetter (b ) && ! unicode .IsDigit (b ) {
18
+ return false
19
+ }
20
+ return true
21
+ }
You can’t perform that action at this time.
0 commit comments