summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2014-10-17 12:35:46 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2014-10-17 12:35:46 +0000
commit5a4a1a2fa44630d00f7029ae0bb11d614147af23 (patch)
tree14afc9c80b300dee807aec4eb7dfca39fdc1d546 /lib
parent966f68b33e1f15f08e383ec68346ed1bd690b59b (diff)
parentf8cdd62e2269b6c8243b6d1bc9bf73dc7dd1b535 (diff)
downloadgitlab-ce-5a4a1a2fa44630d00f7029ae0bb11d614147af23.tar.gz
Merge branch 'fix-oauth-block' into 'master'
Fix user being blocked after oauth sign-in See merge request !1190
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/oauth/user.rb32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/gitlab/oauth/user.rb b/lib/gitlab/oauth/user.rb
index 18ec63a62a2..47f62153a50 100644
--- a/lib/gitlab/oauth/user.rb
+++ b/lib/gitlab/oauth/user.rb
@@ -17,7 +17,7 @@ module Gitlab
end
def new?
- !gl_user.persisted?
+ !persisted?
end
def valid?
@@ -27,10 +27,14 @@ module Gitlab
def save
unauthorized_to_create unless gl_user
- gl_user.save!
- log.info "(OAuth) saving user #{auth_hash.email} from login with extern_uid => #{auth_hash.uid}"
- gl_user.block if needs_blocking?
+ 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}"
gl_user
rescue ActiveRecord::RecordInvalid => e
log.info "(OAuth) Error saving user: #{gl_user.errors.full_messages}"
@@ -40,13 +44,27 @@ module Gitlab
def gl_user
@user ||= find_by_uid_and_provider
- if Gitlab.config.omniauth.allow_single_sign_on
+ if signup_enabled?
@user ||= build_new_user
end
+
@user
end
protected
+
+ def needs_blocking?
+ new? && block_after_signup?
+ end
+
+ def signup_enabled?
+ Gitlab.config.omniauth.allow_single_sign_on
+ end
+
+ def block_after_signup?
+ Gitlab.config.omniauth.block_auto_created_users
+ end
+
def auth_hash=(auth_hash)
@auth_hash = AuthHash.new(auth_hash)
end
@@ -77,10 +95,6 @@ module Gitlab
Gitlab::AppLogger
end
- def needs_blocking?
- Gitlab.config.omniauth['block_auto_created_users']
- end
-
def model
::User
end