Skip to content

Instantly share code, notes, and snippets.

@Bregor
Created December 25, 2011 07:09
Show Gist options
  • Save Bregor/f0b0c2946e4bc94c4a3f to your computer and use it in GitHub Desktop.
Save Bregor/f0b0c2946e4bc94c4a3f to your computer and use it in GitHub Desktop.
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def ldap
@user = User.find_for_ldap_auth(request.env['omniauth.auth'])
if @user.persisted?
flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', :kind => 'ldap'
@user.remember_me = true
sign_in_and_redirect @user, :event => :authentication
else
flash[:notice] = I18n.t 'devise.omniauth_callbacks.failure', :kind => 'Ldap', :reason => 'User not found'
redirect_to new_user_session_path
end
end
def passthru
render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
end
end
devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks", :sessions => "sessions"} do
get '/users/auth/:provider' => 'omniauth_callbacks#passthru'
end
class SessionsController < Devise::SessionsController
prepend_view_path "app/views/devise"
before_filter :unconfigure_phone, :only => [:destroy]
after_filter :configure_phone, :only => [:create]
private
def configure_phone(reset = false)
device = Device.find_by_hostname(request.env['HTTP_X_FORWARDED_FOR'])
unless device.nil?
AstCC.set_device(:device => device, :user => current_user, :reset => reset)
else
flash[:failure] = t('errors.messages.device_not_found')
end
end
def unconfigure_phone
configure_phone(true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment