Skip to content

Commit 64c7271

Browse files
committed
feat(users): check duplicate email
1 parent 00e40ad commit 64c7271

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

internal/service/user_admin/user_backyard.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,24 @@ func (us *UserAdminService) formatBulkAddUsers(ctx context.Context, req *schema.
190190
lang := handler.GetLangByCtx(ctx)
191191
val := validator.GetValidatorByLang(lang)
192192
errorData := &schema.AddUsersErrorData{Line: -1}
193+
existEmails := make(map[string]bool)
194+
existDisplayNames := make(map[string]bool)
193195
for line, user := range req.Users {
196+
if existEmails[user.Email] {
197+
errorData.Field = "email"
198+
errorData.Line = line + 1
199+
errorData.Content = user.Email
200+
errorData.ExtraMessage = translator.Tr(lang, reason.EmailDuplicate)
201+
break
202+
}
203+
if existDisplayNames[user.DisplayName] {
204+
errorData.Field = "displayName"
205+
errorData.Line = line + 1
206+
errorData.Content = user.DisplayName
207+
errorData.ExtraMessage = translator.Tr(lang, reason.UsernameDuplicate)
208+
break
209+
}
210+
194211
if fields, e := val.Check(user); e != nil {
195212
errorData.SetErrField(fields)
196213
errorData.Line = line + 1
@@ -227,6 +244,8 @@ func (us *UserAdminService) formatBulkAddUsers(ctx context.Context, req *schema.
227244
userInfo.Status = entity.UserStatusAvailable
228245
userInfo.Rank = 1
229246
users = append(users, userInfo)
247+
existEmails[user.Email] = true
248+
existDisplayNames[user.DisplayName] = true
230249
}
231250

232251
if errorData.Line != -1 {

0 commit comments

Comments
 (0)