Bike!Bike! Website!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.3 KiB

9 years ago
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
9 years ago
session[:oauth_last_url] = request.referer
9 years ago
login_at(auth_params[:provider])
end
def callback
9 years ago
user_info = (sorcery_fetch_user_hash auth_params[:provider] || {})[:user_info]
user = User.find_by_email(user_info['email'])
# create the user if the email is not recognized
unless user
user = User.new(email: user_info['email'], firstname: user_info['name'])
user.save!
9 years ago
end
9 years ago
# log in the user
auto_login(user) if user
redirect_to (session[:oauth_last_url] || home_path)
#, :notice => "Logged in with #{provider.titleize}!"
# if @user = login_from(provider)
# else
# begin
# @user = create_from(auth_params[:provider])
# reset_session
# auto_login(@user)
# redirect_to redirect_url, :notice => "Signed up with #{provider.titleize}!"
# rescue
# redirect_to redirect_url, :alert => "Failed to login with #{provider.titleize}!"
# end
# end
9 years ago
end
private
def auth_params
params.permit(:code, :provider)
end
end