Class: Netzke::Basepack::AuthApp

Inherits:
SimpleApp
  • Object
show all
Defined in:
lib/netzke/basepack/auth_app.rb

Overview

Extension to SimpleApp that brings in support for authentication and masquerading ** NOTE: it’s WIP **

Direct Known Subclasses

BasicApp

Instance Method Summary collapse

Methods inherited from SimpleApp

#configuration, #js_component_html, #js_component_render, #main_panel_config, #menu_bar_config, #status_bar_config

Constructor Details

#initialize(*args) ⇒ AuthApp

Returns a new instance of AuthApp.



119
120
121
122
123
124
125
126
127
128
# File 'lib/netzke/basepack/auth_app.rb', line 119

def initialize(*args)
  super

  if session[:netzke_just_logged_in] || session[:netzke_just_logged_out]
    session[:config_mode] = false
    session[:masq_world] = session[:masq_user] = session[:masq_roles] = nil
  end

  strong_children_config.deep_merge!(:mode => :config) if session[:config_mode]
end

Instance Method Details

#default_configObject



7
8
9
10
11
12
# File 'lib/netzke/basepack/auth_app.rb', line 7

def default_config
  super.tap do |c|
    c[:login_url] = "/login"
    c[:logout_url] = "/logout"
  end
end

Set the Logout button if Netzke::Core.current_user is set



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/netzke/basepack/auth_app.rb', line 99

def menu
  [].tap do |menu|
    user = Netzke::Core.current_user
    if !user.nil?
      user_name = user.respond_to?(:name) ? user.name : user.email # try to display user's name, fallback to email
      menu << "->" <<
      {
        :text => user_name,
        :menu => user_menu
      }
    else
      menu << "->" << :login.action
    end
  end
end

#user_menuObject



115
116
117
# File 'lib/netzke/basepack/auth_app.rb', line 115

def user_menu
  [:logout.action]
end