I would like to show my login page with error message like “The system cannot log you on at this time. Please try again later” when there is ldap error during the login process.
Currently, I have used the custom_failure.rb approach as described in
https://github.com/plataformatec/devise/wiki/How-To:-Redirect-to-a-specific-page-when-the-user-can-not-be-authenticated
and it is able to catch error like invalid username / password and I have redirected it to the login page
showing the error messages as desired without problem.
But this approach cannot catch the ldap errors.
These ldap errors are shown as a very raw html page like the following:
Errno::ETIMEDOUT in Devise::SessionsController#create
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. – connect(2)
Rails.root: C:/extratxt/2.2.0/source/ruby/messaging
Application Trace | Framework Trace | Full Trace
Request
Parameters:
{"utf8"=>"✓",
"user"=>{"username"=>"administrator",
"password"=>"[FILTERED]",
"remember_me"=>"0"},
"commit"=>"Sign in"}
Show session dump
Show env dump
Response
Headers:
None
How can I prevent this and instead show my specified page (e.g. login page with my own error message) ?
Any idea ? Thanks
One way is to override the create session action, but there are a couple steps required to get it working. First, copy the devise views (if you haven’t already done so) with
Then you need to create a sessions_controller.rb file that extends Devise::SessionsController:
Finally, in your config/routes.rb, you need to tell devise to use your customized controller: