forked from External/greenlight
omniauth strategy
This commit is contained in:
@ -1,3 +1,8 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
def current_user
|
||||
@current_user ||= User.find_by(id: session[:user_id])
|
||||
end
|
||||
helper_method :current_user
|
||||
end
|
||||
|
17
app/controllers/sessions_controller.rb
Normal file
17
app/controllers/sessions_controller.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class SessionsController < ApplicationController
|
||||
def create
|
||||
@user = User.from_omniauth(request.env['omniauth.auth'])
|
||||
session[:user_id] = @user.id
|
||||
rescue => e
|
||||
logger.error "Error authenticating via omniauth: #{e}"
|
||||
ensure
|
||||
redirect_to root_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
if current_user
|
||||
session.delete(:user_id)
|
||||
end
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user