0

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:

  1. Is there a devise helper/callback function to activate session#destroy. Any code snippet?
  2. 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 ?

  3. 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

Means
  • 322
  • 2
  • 4
  • 16
  • Refer here for url existence http://stackoverflow.com/a/18582395/6548745 – Md. Farhan Memon May 03 '17 at 17:49
  • I haven't been able to check it as I am stuck with another issue. Thanks, I did pick a code snippet from your link but I'm still wondering about terminating a session before/after redirecting to another site. Any idea? – Means May 04 '17 at 16:43

0 Answers0