Class: Manuscript::Keymaster

Inherits:
Object
  • Object
show all
Defined in:
lib/manuscript/keymaster.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Keymaster

Returns a new instance of Keymaster.



4
5
6
7
# File 'lib/manuscript/keymaster.rb', line 4

def initialize(app, options={})
  @app = app
  @hotink_account_id = options[:hotink_account_id] || 1
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/manuscript/keymaster.rb', line 9

def call(env)
  request = Rack::Request.new(env)
  session = env['rack.session']
  if env['PATH_INFO']=~/^\/admin/
    if (session[:sso] && session[:sso][:user_id]) && (session[:sso][:is_admin?]=='true' || session[:sso]["account_#{@hotink_account_id}_manager"]=='true')
      @app.call(env)
    else
      [302, {"Location" => "/sso/login?return_to=#{request.url}"}, "Redirecting to SSO server..."]
    end
  else
    @app.call(env)
  end
end