Skip to content

Instantly share code, notes, and snippets.

@dbarrionuevo
Created November 18, 2013 15:39
Show Gist options
  • Save dbarrionuevo/7529875 to your computer and use it in GitHub Desktop.
Save dbarrionuevo/7529875 to your computer and use it in GitHub Desktop.
# app/controllers/sessions_controller.rb
class SessionsController < ApplicationController
def login
if current_user
redirect_to root_path
return
end
@redirect_path = { path: "/auth/facebook", message: { notice: "Logged in successfully" } }
parse_to_path if params[:to]
redirect_to @redirect_path[:path], @redirect_path[:message]
end
protected
def invalid_to_path
@redirect_path = { path: new_story_path, message: { alert: "Invalid URL" } }
end
def parse_to_path
begin
uri = URI.parse(params[:to])
unless ENV['HOST'].include? uri.host
invalid_to_path
else
session[:from] = uri.to_s
end
rescue URI::InvalidURIError
invalid_to_path
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment