I'm using Devise and trying to redirect to another site upon form submit but I want the user be logged-out(end session) so that if a browser's back button is pressed, the same form cannot be reloaded or resubmitted. The user must instead be redirected to root_url.
In the controller, I've the devise function below but it's not logging out instantly maybe due to timeout parameter.
before_action :authenticate_user!
Now my doubts are:
- Is there a devise helper/callback function to activate session#destroy. Any code snippet?
Ideally the session must be destroyed after 'successful' redirection, but then we have lost the controller action as soon as redirection from app to another site occurs.. So which comes first(redirection or session#end) and how ?
And if redirection is unsuccessful, then it must redirect back to app and not destroy session. Right now, I can only check uri by parsing but not checking if the site address is right or in other words, the site exists or loads up properly. How to accomplish this?
To load the new site, I've put a sleep(5) just after redirect_to.
apply_mode = 'http://www.google.com'
if @profile.uri?(apply_mode)
redirect_to apply_mode, confirm: 'You are being redirected to an external site.'
sleep(5)
else # Application mode is not url
redirect_to root_path
end
profile.rb
def uri?(string)
uri = URI.parse(string)
%w( http https ).include?(uri.scheme)
rescue URI::BadURIError
false
rescue URI::InvalidURIError
false
end