fix: use correct field name in user put api (#2026)

This commit is contained in:
Oleg Lobanov 2022-07-05 16:55:31 +02:00 committed by GitHub
parent 06d9c03e92
commit d94acdd89a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -177,7 +177,7 @@ var userPutHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request
}
for k, v := range req.Which {
v = cases.Title(language.English).String(v)
v = cases.Title(language.English, cases.NoLower).String(v)
req.Which[k] = v
if v == "Password" {

View File

@ -1,6 +1,7 @@
package bolt
import (
"fmt"
"reflect"
"github.com/asdine/storm/v3"
@ -58,7 +59,11 @@ func (st usersBackend) Update(user *users.User, fields ...string) error {
}
for _, field := range fields {
val := reflect.ValueOf(user).Elem().FieldByName(field).Interface()
userField := reflect.ValueOf(user).Elem().FieldByName(field)
if !userField.IsValid() {
return fmt.Errorf("invalid field: %s", field)
}
val := userField.Interface()
if err := st.db.UpdateField(user, field, val); err != nil {
return err
}