mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
feat: use lowercase username when isUsernameLowered is enabled (#2952)
* feat: auto trim username during login and lowercase when isUsernameLowered enabled in conf * fix: fix linter error * fix: fix linter error * fix: fix linter error
This commit is contained in:
@ -20,6 +20,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/utils/pagination"
|
"github.com/beego/beego/utils/pagination"
|
||||||
|
"github.com/casdoor/casdoor/conf"
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
@ -293,6 +294,11 @@ func (c *ApiController) UpdateUser() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isUsernameLowered := conf.GetConfigBool("isUsernameLowered")
|
||||||
|
if isUsernameLowered {
|
||||||
|
user.Name = strings.ToLower(user.Name)
|
||||||
|
}
|
||||||
|
|
||||||
isAdmin := c.IsAdmin()
|
isAdmin := c.IsAdmin()
|
||||||
if pass, err := object.CheckPermissionForUpdateUser(oldUser, &user, isAdmin, c.GetAcceptLanguage()); !pass {
|
if pass, err := object.CheckPermissionForUpdateUser(oldUser, &user, isAdmin, c.GetAcceptLanguage()); !pass {
|
||||||
c.ResponseError(err)
|
c.ResponseError(err)
|
||||||
|
@ -877,6 +877,7 @@ func AddUsers(users []*User) (bool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.Name = strings.TrimSpace(user.Name)
|
||||||
if isUsernameLowered {
|
if isUsernameLowered {
|
||||||
user.Name = strings.ToLower(user.Name)
|
user.Name = strings.ToLower(user.Name)
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,11 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/casdoor/casdoor/conf"
|
||||||
"github.com/casdoor/casdoor/i18n"
|
"github.com/casdoor/casdoor/i18n"
|
||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
|
||||||
|
|
||||||
"github.com/casdoor/casdoor/idp"
|
"github.com/casdoor/casdoor/idp"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/xorm-io/core"
|
"github.com/xorm-io/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,6 +56,13 @@ func HasUserByField(organizationName string, field string, value string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetUserByFields(organization string, field string) (*User, error) {
|
func GetUserByFields(organization string, field string) (*User, error) {
|
||||||
|
isUsernameLowered := conf.GetConfigBool("isUsernameLowered")
|
||||||
|
if isUsernameLowered {
|
||||||
|
field = strings.ToLower(field)
|
||||||
|
}
|
||||||
|
|
||||||
|
field = strings.TrimSpace(field)
|
||||||
|
|
||||||
// check username
|
// check username
|
||||||
user, err := GetUserByField(organization, "name", field)
|
user, err := GetUserByField(organization, "name", field)
|
||||||
if err != nil || user != nil {
|
if err != nil || user != nil {
|
||||||
|
Reference in New Issue
Block a user