BikeBikeBike/app/controllers/oauths_controller.rb
Graham Kaplan 230295790b Add Facebook login with Sorcery
The facebook key and secret defined in the sorcery config file are for
testing only and need to be changed and not committed to source when
app is ready to go live
2014-04-05 19:18:57 -07:00

32 lines
813 B
Ruby

class OauthsController < ApplicationController
skip_before_filter :require_login
# sends the user on a trip to the provider,
# and after authorizing there back to the callback url.
def oauth
login_at(auth_params[:provider])
end
def callback
provider = auth_params[:provider]
if @user = login_from(provider)
redirect_to root_path, :notice => "Logged in with #{provider.titleize}!"
else
begin
@user = create_from(auth_params[:provider])
reset_session
auto_login(@user)
redirect_to root_path, :notice => "Signed up with #{provider.titleize}!"
rescue
redirect_to root_path, :alert => "Failed to login with #{provider.titleize}!"
end
end
end
private
def auth_params
params.permit(:code, :provider)
end
end