diff options
author | zeripath <art27@cantab.net> | 2020-01-19 23:49:55 +0000 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-19 18:49:55 -0500 |
commit | dcf7e858cb5d97389c4784227bfb93b9076938e6 (patch) | |
tree | cbc0f16091a1c35e983d82cec71019613ead716b /models/login_source.go | |
parent | bec99507a4c2be6009c9539d7c3b7eb06a559cd8 (diff) | |
download | gitea-dcf7e858cb5d97389c4784227bfb93b9076938e6.tar.gz gitea-dcf7e858cb5d97389c4784227bfb93b9076938e6.zip |
Check user != nil before checking values (#9881)
* Check user != nil before checking values
* Handle autoAdmin
Diffstat (limited to 'models/login_source.go')
-rw-r--r-- | models/login_source.go | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/models/login_source.go b/models/login_source.go index 0a8a92336e..0c4d444fec 100644 --- a/models/login_source.go +++ b/models/login_source.go @@ -473,13 +473,21 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR // Update User admin flag if exist if isExist, err := IsUserExist(0, sr.Username); err != nil { return nil, err - } else if isExist && - !user.ProhibitLogin && len(source.LDAP().AdminFilter) > 0 && user.IsAdmin != sr.IsAdmin { - // Change existing admin flag only if AdminFilter option is set - user.IsAdmin = sr.IsAdmin - err = UpdateUserCols(user, "is_admin") - if err != nil { - return nil, err + } else if isExist { + if user == nil { + user, err = GetUserByName(sr.Username) + if err != nil { + return nil, err + } + } + if user != nil && + !user.ProhibitLogin && len(source.LDAP().AdminFilter) > 0 && user.IsAdmin != sr.IsAdmin { + // Change existing admin flag only if AdminFilter option is set + user.IsAdmin = sr.IsAdmin + err = UpdateUserCols(user, "is_admin") + if err != nil { + return nil, err + } } } |