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
This commit is contained in:
Graham Kaplan
2014-04-05 19:18:57 -07:00
parent a6da30dc08
commit 230295790b
17 changed files with 112 additions and 12 deletions
+32
View File
@@ -0,0 +1,32 @@
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