Class: Rack::Bacoo::SessionCookie
- Inherits:
-
Object
- Object
- Rack::Bacoo::SessionCookie
- Defined in:
- lib/rack/bacoo/session_cookie.rb
Constant Summary collapse
- WRONG_USERNAME =
SecureRandom.hex
- WRONG_PASSWORD =
BCrypt::Password.create(SecureRandom.hex, cost: 1)
Instance Method Summary collapse
-
#initialize(cookie_attributes, encryptor, env) ⇒ SessionCookie
constructor
A new instance of SessionCookie.
- #password ⇒ Object
- #set(headers, username, encrypted_password) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(cookie_attributes, encryptor, env) ⇒ SessionCookie
Returns a new instance of SessionCookie.
12 13 14 15 16 17 |
# File 'lib/rack/bacoo/session_cookie.rb', line 12 def initialize(, encryptor, env) @cookie_attributes = .dup @cookie_name = @cookie_attributes.delete(:cookie_name) @encryptor = encryptor @env = env end |
Instance Method Details
#password ⇒ Object
23 24 25 |
# File 'lib/rack/bacoo/session_cookie.rb', line 23 def password get.nil? ? WRONG_PASSWORD : get.last end |
#set(headers, username, encrypted_password) ⇒ Object
27 28 29 30 31 |
# File 'lib/rack/bacoo/session_cookie.rb', line 27 def set(headers, username, encrypted_password) value = @encryptor.encrypt("#{username}:#{encrypted_password}:#{expires_at}") value = @cookie_attributes.merge(value: value) Utils.(headers, @cookie_name, value) end |
#username ⇒ Object
19 20 21 |
# File 'lib/rack/bacoo/session_cookie.rb', line 19 def username get.nil? ? WRONG_USERNAME : get.first end |