Module: Rich::Cms::Auth

Extended by:
Auth
Included in:
Auth
Defined in:
lib/rich/cms/auth.rb

Defined Under Namespace

Classes: Specs

Instance Method Summary collapse

Instance Method Details

#adminObject



55
56
57
58
59
60
61
62
63
# File 'lib/rich/cms/auth.rb', line 55

def admin
  case specs.logic
  when :authlogic
    user_session = "#{klass.name}Session".constantize.find
    user_session.try klass_symbol
  when :devise
    current_controller.try :send, specs.current_admin_method if enabled? && specs.current_admin_method
  end if enabled?
end

#admin_labelObject



65
66
67
# File 'lib/rich/cms/auth.rb', line 65

def admin_label
  (admin.try(:send, specs.identifier) if enabled?) || "Rich-CMS"
end

#enabled?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rich/cms/auth.rb', line 15

def enabled?
  !!specs.logic
end

#loginObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rich/cms/auth.rb', line 23

def 
  case specs.logic
  when :authlogic
    user_session = "#{klass.name}Session".constantize.new params[klass_symbol]
    user_session.save
  when :devise
    if Devise::VERSION.to_f < 1.1
      warden.authenticate(:scope => klass_symbol)
    else
      begin
        sessions = Devise.mappings[klass_symbol].controllers[:sessions]
        Devise.mappings[klass_symbol].controllers[:sessions] = "rich/cms_sessions"
        warden.authenticate(:scope => klass_symbol)
      ensure
        Devise.mappings[klass_symbol].controllers[:sessions] = sessions
      end
    end
  end if enabled?
  !!admin
end

#login_required?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rich/cms/auth.rb', line 19

def 
  enabled? && admin.nil?
end

#logoutObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/rich/cms/auth.rb', line 44

def logout
  case specs.logic
  when :authlogic
    user_session = "#{klass.name}Session".constantize.find
    user_session.try :destroy
  when :devise
    sign_out klass_symbol
  end if enabled?
  session[:rich_cms] = nil
end

#setup {|specs| ... } ⇒ Object

Yields:

  • (specs)


10
11
12
13
# File 'lib/rich/cms/auth.rb', line 10

def setup
  @specs = Specs.new
  yield specs
end