0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-12-22 11:44:20 +01:00

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 <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2023-12-19 10:32:45 +08:00 committed by GitHub
parent 11f0519ad8
commit 14ffdf6173
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 16 deletions

View file

@ -15,9 +15,8 @@ type CreateUserOption struct {
FullName string `json:"full_name" binding:"MaxSize(100)"` FullName string `json:"full_name" binding:"MaxSize(100)"`
// required: true // required: true
// swagger:strfmt email // swagger:strfmt email
Email string `json:"email" binding:"Required;Email;MaxSize(254)"` Email string `json:"email" binding:"Required;Email;MaxSize(254)"`
// required: true Password string `json:"password" binding:"MaxSize(255)"`
Password string `json:"password" binding:"Required;MaxSize(255)"`
MustChangePassword *bool `json:"must_change_password"` MustChangePassword *bool `json:"must_change_password"`
SendNotify bool `json:"send_notify"` SendNotify bool `json:"send_notify"`
Restricted *bool `json:"restricted"` Restricted *bool `json:"restricted"`

View file

@ -93,18 +93,28 @@ func CreateUser(ctx *context.APIContext) {
if ctx.Written() { if ctx.Written() {
return return
} }
if !password.IsComplexEnough(form.Password) {
err := errors.New("PasswordComplexity") if u.LoginType == auth.Plain {
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err) if len(form.Password) < setting.MinPasswordLength {
return err := errors.New("PasswordIsRequired")
} ctx.Error(http.StatusBadRequest, "PasswordIsRequired", err)
pwned, err := password.IsPwned(ctx, form.Password) return
if pwned { }
if err != nil {
log.Error(err.Error()) if !password.IsComplexEnough(form.Password) {
err := errors.New("PasswordComplexity")
ctx.Error(http.StatusBadRequest, "PasswordComplexity", err)
return
}
pwned, err := password.IsPwned(ctx, form.Password)
if pwned {
if err != nil {
log.Error(err.Error())
}
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
return
} }
ctx.Error(http.StatusBadRequest, "PasswordPwned", errors.New("PasswordPwned"))
return
} }
overwriteDefault := &user_model.CreateUserOverwriteOptions{ overwriteDefault := &user_model.CreateUserOverwriteOptions{

View file

@ -18406,8 +18406,7 @@
"type": "object", "type": "object",
"required": [ "required": [
"username", "username",
"email", "email"
"password"
], ],
"properties": { "properties": {
"created_at": { "created_at": {