Created
November 18, 2013 15:39
-
-
Save dbarrionuevo/7529875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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