Commit 9028999c933a3db790ef4645474d7b04888a308f

Authored by Dmitriy Zaporozhets
1 parent 0df1cf7f

Use new OAuth classes

app/controllers/omniauth_callbacks_controller.rb
... ... @@ -18,33 +18,39 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
18 18 def ldap
19 19 # We only find ourselves here
20 20 # if the authentication to LDAP was successful.
21   - @user = Gitlab::LDAP::User.find_or_create(request.env["omniauth.auth"])
  21 + @user = Gitlab::LDAP::User.find_or_create(oauth)
22 22 @user.remember_me = true if @user.persisted?
23   -
24 23 sign_in_and_redirect(@user)
25 24 end
26 25  
27 26 private
28 27  
29 28 def handle_omniauth
30   - oauth = request.env['omniauth.auth']
31   - provider, uid = oauth['provider'], oauth['uid']
32   -
33 29 if current_user
34 30 # Change a logged-in user's authentication method:
35   - current_user.extern_uid = uid
36   - current_user.provider = provider
  31 + current_user.extern_uid = oauth['uid']
  32 + current_user.provider = oauth['provider']
37 33 current_user.save
38 34 redirect_to profile_path
39 35 else
40   - @user = User.find_or_new_for_omniauth(oauth)
  36 + @user = Gitlab::OAuth::User.find(oauth)
  37 +
  38 + # Create user if does not exist
  39 + # and allow_single_sign_on is true
  40 + if Gitlab.config.omniauth['allow_single_sign_on']
  41 + @user ||= Gitlab::OAuth::User.create(oauth)
  42 + end
41 43  
42 44 if @user
43   - sign_in_and_redirect @user
  45 + sign_in_and_redirect(@user)
44 46 else
45 47 flash[:notice] = "There's no such user!"
46 48 redirect_to new_user_session_path
47 49 end
48 50 end
49 51 end
  52 +
  53 + def oauth
  54 + @oauth ||= request.env['omniauth.auth']
  55 + end
50 56 end
... ...