Last active
August 29, 2015 14:01
-
-
Save bsodmike/7f7d130b0c38964dfabd to your computer and use it in GitHub Desktop.
Initialise Authentication via Rails Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'initialise_authentication' | |
module Refinery | |
module AuthenticateIdentities | |
class Engine < Rails::Engine | |
extend Refinery::Engine | |
isolate_namespace Refinery::AuthenticateIdentities | |
engine_name :refinery_authenticate_identities | |
before_inclusion do | |
Refinery::Plugin.register do |plugin| | |
plugin.name = "authenticate_identities" | |
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.authenticate_identities_admin_authenticate_identities_path } | |
plugin.pathname = root | |
plugin.activity = { | |
:class_name => :'refinery/authenticate_identities/authenticate_identity', | |
:title => 'name' | |
} | |
plugin.hide_from_menu = true | |
end | |
end | |
config.before_initialize do | |
# NOTE Secure frontend access with Omniauth Identity strategy | |
::Authentication.secure_frontend | |
end | |
config.after_initialize do | |
Refinery.register_extension(Refinery::AuthenticateIdentities) | |
end | |
config.to_prepare do | |
Decorators.register! Engine.root | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts ">> Initialising Authentication: Omniauth Identity" | |
module Authentication | |
def self.secure_frontend | |
ActionController::Base.class_eval do | |
class << self | |
def you_shall_not_pass! | |
include ::Authentication::ApplicationController | |
end | |
end | |
end | |
end | |
module ApplicationController | |
def self.included _klass | |
_klass.class_eval do | |
include InstanceMethods | |
_klass.send(:before_filter, :set_current_user) | |
helper_method :set_current_user, :current_user, :user_signed_in? | |
private :set_current_user, :current_user, :user_signed_in? | |
end | |
end | |
module InstanceMethods | |
def set_current_user | |
current_user | |
end | |
def current_user | |
@current_user ||= User.find(session[:user_id]) if session[:user_id] | |
end | |
def user_signed_in? | |
@current_user.present? | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment