summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2014-11-25 18:15:30 +0200
committerValery Sizov <vsv2711@gmail.com>2014-12-04 13:01:50 +0200
commit1a80d13a3990937580c97e2b0ba8fb98f69bc055 (patch)
treed073b436e6585b0d025163f10e5762578fcbc169 /lib
parent236741008ed82b77e3e4357e07060f7764d1d21a (diff)
downloadgitlab-ce-1a80d13a3990937580c97e2b0ba8fb98f69bc055.tar.gz
Multi-provider auth. LDAP is not reworked
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/ldap/user.rb5
-rw-r--r--lib/gitlab/oauth/user.rb21
2 files changed, 10 insertions, 16 deletions
diff --git a/lib/gitlab/ldap/user.rb b/lib/gitlab/ldap/user.rb
index 3176e9790a7..827a33b5217 100644
--- a/lib/gitlab/ldap/user.rb
+++ b/lib/gitlab/ldap/user.rb
@@ -12,9 +12,10 @@ module Gitlab
class << self
def find_by_uid_and_provider(uid, provider)
# LDAP distinguished name is case-insensitive
- ::User.
+ identity = ::Identity.
where(provider: [provider, :ldap]).
where('lower(extern_uid) = ?', uid.downcase).last
+ identity && identity.user
end
end
@@ -34,7 +35,7 @@ module Gitlab
end
def find_by_email
- model.find_by(email: auth_hash.email)
+ User.find_by(email: auth_hash.email)
end
def update_user_attributes
diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb
index 47f62153a50..7c1970eb8e5 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -27,11 +27,9 @@ module Gitlab
def save
unauthorized_to_create unless gl_user
+ gl_user.save!
if needs_blocking?
- gl_user.save!
gl_user.block
- else
- gl_user.save!
end
log.info "(OAuth) saving user #{auth_hash.email} from login with extern_uid => #{auth_hash.uid}"
@@ -70,24 +68,23 @@ module Gitlab
end
def find_by_uid_and_provider
- model.where(provider: auth_hash.provider, extern_uid: auth_hash.uid).last
+ identity = Identity.find_by(provider: auth_hash.provider, extern_uid: auth_hash.uid)
+ identity && identity.user
end
def build_new_user
- model.new(user_attributes).tap do |user|
- user.skip_confirmation!
- end
+ user = User.new(user_attributes)
+ user.skip_confirmation!
+ user.identities.new(extern_uid: auth_hash.uid, provider: auth_hash.provider)
end
def user_attributes
{
- extern_uid: auth_hash.uid,
- provider: auth_hash.provider,
name: auth_hash.name,
username: auth_hash.username,
email: auth_hash.email,
password: auth_hash.password,
- password_confirmation: auth_hash.password,
+ password_confirmation: auth_hash.password
}
end
@@ -95,10 +92,6 @@ module Gitlab
Gitlab::AppLogger
end
- def model
- ::User
- end
-
def raise_unauthorized_to_create
raise StandardError.new("Unauthorized to create user, signup disabled for #{auth_hash.provider}")
end