Class: Isomorfeus::Empowerment::Session
- Inherits:
-
LucidObject::Base
- Object
- LucidObject::Base
- Isomorfeus::Empowerment::Session
- Defined in:
- lib/isomorfeus/empowerment/session.rb
Class Method Summary collapse
- .add(session_id:, cookie:, user:, accessor:) ⇒ Object
- .get_user(session_id:) ⇒ Object
- .remove(session_id:) ⇒ Object
- .take_cookie(accessor:) ⇒ Object
- .touch(session_id:) ⇒ Object (also: get_session)
Class Method Details
.add(session_id:, cookie:, user:, accessor:) ⇒ Object
13 14 15 16 |
# File 'lib/isomorfeus/empowerment/session.rb', line 13 def add(session_id:, cookie:, user:, accessor:) t = Time.now self.create(key: session_id, attributes: { user_class_name: user.class.name, user_key: user.key, cookie: , accessor: accessor, ctime: t, atime: t }) end |
.get_user(session_id:) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/isomorfeus/empowerment/session.rb', line 38 def get_user(session_id:) s = touch(session_id: session_id) s.user_class_name.constantize.load(key: s.user_key) if s rescue nil end |
.remove(session_id:) ⇒ Object
57 58 59 |
# File 'lib/isomorfeus/empowerment/session.rb', line 57 def remove(session_id:) self.destroy(key: session_id) end |
.take_cookie(accessor:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/isomorfeus/empowerment/session.rb', line 18 def (accessor:) s = self.search(:accessor, accessor).first if s = s. if session_info = .split('; ').first session_id = session_info.split('=').last.strip s. = nil s.save else # asked for the same cookie a second time # can probably only be due to session hijacking # so delete session associated with that accessor s.destroy nil end end end |
.touch(session_id:) ⇒ Object Also known as: get_session
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/isomorfeus/empowerment/session.rb', line 45 def touch(session_id:) s = self.load(key: session_id) return nil unless s t = Time.now if (t - s.atime) > 600 s.atime = t s.save end s end |