Created
August 22, 2011 16:59
-
-
Save jimmyz/1162902 to your computer and use it in GitHub Desktop.
helper stuff
This file contains hidden or 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
class FamilySearchController < ApplicationController | |
before_filter :get_window | |
around_filter :catch_authentication | |
include FamilySearchApiHelper | |
# Internal, only for Spec purposes. | |
# get_client_test and serialize_test share behavior that will be | |
# used accross other controller actions that inherit FamilySearchController | |
def get_client_test | |
if(params[:username] && params[:password]) | |
@client = get_family_tree_api params[:username], params[:password] | |
else | |
@client = get_family_tree_api | |
end | |
end | |
def serialize_test | |
serialize_request | |
end | |
def fs_authenticate | |
@fs_user = FamilySearchUser.new params[:fs_user] | |
@client = get_family_tree_api(@fs_user.username,@fs_user.password) | |
deserialize_request | |
send @action | |
end | |
private | |
def get_window | |
@window = params[:window] if params[:window] | |
end | |
def catch_authentication | |
yield | |
rescue RubyFsStack::Unauthorized => e | |
if e.message =~ /401\.23/ # Unauthorized | |
serialize_request | |
please_authenticate | |
elsif e.message =~ /401\.1/ # Bad Credentials | |
@message = "Invalid credentials. Please try again." | |
please_authenticate | |
else | |
raise e | |
end | |
rescue Exception => e | |
if e.message == 'Unauthorized' | |
serialize_request | |
please_authenticate | |
else | |
raise e | |
end | |
end | |
def please_authenticate | |
@fs_user = FamilySearchUser.new | |
session[:ft_session] = nil | |
respond_to do |format| | |
format.js {render :partial => 'authenticate'} | |
format.html {render :action => 'authenticate'} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment