Class: Rhoconnect::Middleware::CurrentUser

Inherits:
Object
  • Object
show all
Defined in:
lib/rhoconnect/middleware/current_user.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CurrentUser

Returns a new instance of CurrentUser.



7
8
9
# File 'lib/rhoconnect/middleware/current_user.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
# File 'lib/rhoconnect/middleware/current_user.rb', line 11

def call(env)
  #puts "env is *** #{env.inspect}"
  env[Rhoconnect::CURRENT_USER] = extract_current_user(env)
  @app.call(env)
end

#extract_current_user(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rhoconnect/middleware/current_user.rb', line 17

def extract_current_user(env)
  user = nil
  if User.is_exist?(env['rack.session'][:login])
    user = User.load(env['rack.session'][:login])
  end
  if user and (user.admin == 1 || env['rack.session'][:app_name] == APP_NAME)
    user
  else  
    nil
  end
end