Skip to content

Commit 14ffdf6

Browse files
authored
chore(api): support ignore password if login source type is LDAP for creating user API (#28491)
- Modify the `Password` field in `CreateUserOption` struct to remove the `Required` tag - Update the `v1_json.tmpl` template to include the `email` field and remove the `password` field --------- Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 11f0519 commit 14ffdf6

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

modules/structs/admin_user.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ type CreateUserOption struct {
1515
FullName string `json:"full_name" binding:"MaxSize(100)"`
1616
// required: true
1717
// swagger:strfmt email
18-
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
19-
// required: true
20-
Password string `json:"password" binding:"Required;MaxSize(255)"`
18+
Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
19+
Password string `json:"password" binding:"MaxSize(255)"`
2120
MustChangePassword *bool `json:"must_change_password"`
2221
SendNotify bool `json:"send_notify"`
2322
Restricted *bool `json:"restricted"`

routers/api/v1/admin/user.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,28 @@ func CreateUser(ctx *context.APIContext) {
9393
if ctx.Written() {
9494
return
9595
}
96-
if !password.IsComplexEnough(form.Password) {
97-
err := errors.New("PasswordComplexity")
98-
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
99-
return
100-
}
101-
pwned, err := password.IsPwned(ctx, form.Password)
102-
if pwned {
103-
if err != nil {
104-
log.Error(err.Error())
96+
97+
if u.LoginType == auth.Plain {
98+
if len(form.Password) < setting.MinPasswordLength {
99+
err := errors.New("PasswordIsRequired")
100+
ctx.Error(http.StatusBadRequest, "PasswordIsRequired", err)
101+
return
102+
}
103+
104+
if !password.IsComplexEnough(form.Password) {
105+
err := errors.New("PasswordComplexity")
106+
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
107+
return
108+
}
109+
110+
pwned, err := password.IsPwned(ctx, form.Password)
111+
if pwned {
112+
if err != nil {
113+
log.Error(err.Error())
114+
}
115+
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
116+
return
105117
}
106-
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
107-
return
108118
}
109119

110120
overwriteDefault := &user_model.CreateUserOverwriteOptions{

templates/swagger/v1_json.tmpl

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)