diff options
author | Jan-Willem van der Meer <mail@jewilmeer.nl> | 2014-09-04 14:55:10 +0400 |
---|---|---|
committer | Jan-Willem van der Meer <mail@jewilmeer.nl> | 2014-09-04 14:55:10 +0400 |
commit | 5b86dab03bbd19d9a3e6090d4672d8f1493e6fe5 (patch) | |
tree | 24ca8e51fbc42b1308f532d2668b6cdc1dd5dd1b /lib/gitlab/ldap/user.rb | |
parent | 1bd15fa717e053824e3abbf72e4010f19677fb79 (diff) |
Move auth hash to a seperate class
Diffstat (limited to 'lib/gitlab/ldap/user.rb')
-rw-r--r-- | lib/gitlab/ldap/user.rb | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb index 99f23080a84..6d1bec5f54a 100644 --- a/lib/gitlab/ldap/user.rb +++ b/lib/gitlab/ldap/user.rb @@ -10,23 +10,27 @@ module Gitlab module LDAP class User < Gitlab::OAuth::User class << self - def find_or_create(auth) - self.auth = auth - find(auth) || create(auth) + def find_or_create(auth_hash) + self.auth_hash = auth_hash + find(auth_hash) || find_and_connect_by_email(auth_hash) || create(auth_hash) end - # overloaded from Gitlab::Oauth::User - # TODO: it's messy, needs cleanup, less complexity - def create(auth) - ldap_user = new(auth) - # first try to find the user based on the returned email address - user = ldap_user.find_gitlab_user_by_email + def find_and_connect_by_email(auth_hash) + self.auth_hash = auth_hash + user = model.find_by(email: self.auth_hash.email) if user - user.update_attributes(extern_uid: ldap_user.uid, provider: ldap_user.provider) - Gitlab::AppLogger.info("(LDAP) Updating legacy LDAP user #{ldap_user.email} with extern_uid => #{ldap_user.uid}") + user.update_attributes(extern_uid: auth_hash.uid, provider: auth_hash.provider) + Gitlab::AppLogger.info("(LDAP) Updating legacy LDAP user #{self.auth_hash.email} with extern_uid => #{auth_hash.uid}") return user end + end + + # overloaded from Gitlab::Oauth::User + # TODO: it's messy, needs cleanup, less complexity + def create(auth_hash) + ldap_user = new(auth_hash) + # first try to find the user based on the returned email address # if the user isn't found by an exact email match, use oauth methods ldap_user.save_and_trigger_callbacks @@ -58,7 +62,7 @@ module Gitlab protected def find_by_uid_and_provider - find_by_uid(uid) + find_by_uid(auth_hash.uid) end def find_by_uid(uid) @@ -79,10 +83,6 @@ module Gitlab end end - def find_gitlab_user_by_email - self.class.model.find_by(email: email) - end - def needs_blocking? false end |