Module: Users::Lib::LoginSystem

Defined in:
lib/users/lib/login_system.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/users/lib/login_system.rb', line 5

def self.included(base)
  base.class_eval do
    protected
      alias_method :authorize_radiant, :authorize
      alias_method :current_user_radiant, :current_user
      
      def authorize
        if user_has_backend_access?
          authorize_radiant
        else
          path = Radiant::Config["scoped.#{current_user.access}.welcome"]
          path = "/#{path}".gsub('//','/')
          
          respond_to do |format|
            format.any(:html, :xml, :json) { redirect_to(path) }
          end
        end
      end

      def user_has_backend_access?
        current_user.access.blank?
      end
      
      def current_user
        @current_user ||= (current_user_radiant || )
      end

      def 
        result = nil
        if params[:api_key].present?
          result = User.find_by_api_key(params[:api_key])
        else
          authenticate_with_http_basic do |api_key,_|
            result = User.find_by_api_key(api_key)
          end
        end
        result
      end 
  end
end