mixing in some sorcery auth
This commit is contained in:
@ -4,10 +4,4 @@ class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
respond_to :html, :json
|
||||
|
||||
def current_user
|
||||
# temp
|
||||
Person.new(id: 9999)
|
||||
end
|
||||
helper_method :current_user
|
||||
end
|
||||
|
34
app/controllers/oauths_controller.rb
Normal file
34
app/controllers/oauths_controller.rb
Normal file
@ -0,0 +1,34 @@
|
||||
class OauthsController < ApplicationController
|
||||
skip_before_filter :require_login
|
||||
|
||||
def oauth
|
||||
login_at(params[:provider])
|
||||
end
|
||||
|
||||
def callback
|
||||
provider = params[:provider]
|
||||
@user = login_from(provider)
|
||||
|
||||
if @user
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
else
|
||||
begin
|
||||
@user = create_from(provider)
|
||||
# NOTE: this is the place to add '@user.activate!'
|
||||
# if you are using user_activation submodule
|
||||
|
||||
reset_session # protect from session fixation attack
|
||||
auto_login(@user)
|
||||
redirect_to root_path, notice: "Logged in from #{provider.titleize}!"
|
||||
rescue
|
||||
redirect_to root_path, alert: "Failed to login from #{provider.titleize}!"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def auth_params
|
||||
params.permit(:code, :provider)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user