Class: ODDB::Html::Util::Session

Inherits:
SBSM::Session
  • Object
show all
Includes:
SBSM::Redirector
Defined in:
lib/oddb/html/util/session.rb

Constant Summary collapse

DEFAULT_FLAVOR =
'oddb'
DEFAULT_LANGUAGE =
'de'
DEFAULT_STATE =
State::Drugs::Init
DEFAULT_ZONE =
'drugs'
EXPIRES =
ODDB.config.session_timeout
LF_FACTORY =
LookandfeelFactory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#desired_stateObject (readonly)

Returns the value of attribute desired_state.



16
17
18
# File 'lib/oddb/html/util/session.rb', line 16

def desired_state
  @desired_state
end

Class Method Details

.reset_query_limit(ip = nil) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/oddb/html/util/session.rb', line 25

def Session.reset_query_limit(ip = nil)
  if(ip)
    @@requests.delete(ip)
  else
    @@requests.clear
  end
end

Instance Method Details

#allowed?(*args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/oddb/html/util/session.rb', line 32

def allowed?(*args)
  @user.allowed?(*args)
rescue
  false
end

#limit_queriesObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oddb/html/util/session.rb', line 37

def limit_queries
  requests = (@@requests[remote_ip] ||= [])
  if(@state.limited?)
    requests.delete_if { |other| 
      (@process_start - other) >= ODDB.config.query_limit_phase
    }
    requests.push(@process_start)
    if(requests.size > ODDB.config.query_limit)
      @desired_state = @state
      @active_state = @state = @state.limit_state
      @state.request_path = @desired_state.request_path
    end
  end
end

#loginObject



51
52
53
54
55
# File 'lib/oddb/html/util/session.rb', line 51

def 
  @user = @app.(user_input(:email), user_input(:pass))
  @user.session = self if(@user.respond_to?(:session=))
  @user
end

#logoutObject



56
57
58
59
# File 'lib/oddb/html/util/session.rb', line 56

def logout
  @app.logout(@user.auth_session) if(@user.respond_to?(:auth_session))
  super
end


60
61
62
# File 'lib/oddb/html/util/session.rb', line 60

def navigation
  state.navigation
end

#pagelengthObject



63
64
65
# File 'lib/oddb/html/util/session.rb', line 63

def pagelength
  100
end

#passed_turing_test?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/oddb/html/util/session.rb', line 66

def passed_turing_test?
  ## At the moment, attempting to produce a captcha using the Turing-Gem
  #  results in a Segmentation-Fault. Returning true here is a convenient way
  #  of disabling the captcha.
  # state.respond_to?(:passed_turing_test) && state.passed_turing_test
  true
end

#process(request) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/oddb/html/util/session.rb', line 73

def process(request)
  @request_path = request.unparsed_uri
  @process_start = Time.now
  super
  if(!is_crawler? && lookandfeel.enabled?(:query_limit))
    limit_queries 
  end
  '' ## return empty string across the drb-border
end

#server_nameObject



82
83
84
# File 'lib/oddb/html/util/session.rb', line 82

def server_name
  super || @server_name = ODDB.config.server_name
end