Merge branch 'master' of https://github.com/funglaub/gitlabhq into funglaub-master
Conflicts: Gemfile.lock app/helpers/application_helper.rb app/views/devise/sessions/new.html.erb db/schema.rb
This commit is contained in:
commit
621affecb5
18 changed files with 189 additions and 35 deletions
|
@ -9,7 +9,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
error ||= env["omniauth.error.type"].to_s
|
||||
error.to_s.humanize if error
|
||||
end
|
||||
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
@user = User.find_for_ldap_auth(request.env["omniauth.auth"], current_user)
|
||||
|
@ -19,4 +19,33 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
|||
sign_in_and_redirect @user
|
||||
end
|
||||
|
||||
Settings.omniauth_providers.each do |provider|
|
||||
define_method provider['name'] do
|
||||
handle_omniauth
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def handle_omniauth
|
||||
oauth = request.env['omniauth.auth']
|
||||
provider, uid = oauth['provider'], oauth['uid']
|
||||
|
||||
if current_user
|
||||
# Change a logged-in user's authentication method:
|
||||
current_user.extern_uid = uid
|
||||
current_user.provider = provider
|
||||
current_user.save
|
||||
redirect_to profile_path
|
||||
else
|
||||
@user = User.find_or_new_for_omniauth(oauth)
|
||||
|
||||
if @user
|
||||
sign_in_and_redirect @user
|
||||
else
|
||||
flash[:notice] = "There's no such user!"
|
||||
redirect_to new_user_session_path
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue