LDAP done
This commit is contained in:
parent
d885f24f7b
commit
d6a0b8f428
6 changed files with 37 additions and 24 deletions
13
app/controllers/omniauth_callbacks_controller.rb
Normal file
13
app/controllers/omniauth_callbacks_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
omniauth = request.env["omniauth.auth"]["extra"]["raw_info"]
|
||||
@user = User.find_for_ldap_auth(omniauth)
|
||||
if @user.persisted?
|
||||
@user.remember_me = true
|
||||
end
|
||||
sign_in_and_redirect @user
|
||||
end
|
||||
|
||||
end
|
|
@ -1,22 +0,0 @@
|
|||
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
|
||||
|
||||
def ldap
|
||||
# We only find ourselves here if the authentication to LDAP was successful.
|
||||
ldap = request.env["omniauth.auth"]["extra"]["raw_info"]
|
||||
username = ldap.sAMAccountName[0].to_s
|
||||
email = ldap.proxyaddresses[0][5..-1].to_s
|
||||
|
||||
if @user = User.find_by_email(email)
|
||||
sign_in_and_redirect root_path
|
||||
else
|
||||
password = User.generate_random_password
|
||||
@user = User.create(:name => username,
|
||||
:email => email,
|
||||
:password => password,
|
||||
:password_confirmation => password
|
||||
)
|
||||
sign_in_and_redirect @user
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue