Class: Mumukit::Login::Mucookie
- Inherits:
-
Object
- Object
- Mumukit::Login::Mucookie
- Defined in:
- lib/mumukit/login/mucookie.rb
Defined Under Namespace
Modules: Encryptor
Class Method Summary collapse
Instance Method Summary collapse
- #decode_and_read(key) ⇒ Object
- #decrypt_and_read(key) ⇒ Object
- #delete!(key) ⇒ Object
- #encode_and_write!(key, value, options = {}) ⇒ Object
- #encrypt_and_write!(key, value, options = {}) ⇒ Object
-
#initialize(controller) ⇒ Mucookie
constructor
A new instance of Mucookie.
- #read(key) ⇒ Object
- #spec ⇒ Object
- #write!(key, value, options = {}) ⇒ Object
Constructor Details
#initialize(controller) ⇒ Mucookie
4 5 6 |
# File 'lib/mumukit/login/mucookie.rb', line 4 def initialize(controller) @controller = controller end |
Class Method Details
.cookie_same_site ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/mumukit/login/mucookie.rb', line 48 def self. if %w(RACK_ENV RAILS_ENV).any? { |it| ENV[it] == 'production' } :none else :lax end end |
Instance Method Details
#decode_and_read(key) ⇒ Object
32 33 34 |
# File 'lib/mumukit/login/mucookie.rb', line 32 def decode_and_read(key) Base64.decode64 read(key) end |
#decrypt_and_read(key) ⇒ Object
28 29 30 |
# File 'lib/mumukit/login/mucookie.rb', line 28 def decrypt_and_read(key) Encryptor.decrypt read(key) end |
#delete!(key) ⇒ Object
36 37 38 |
# File 'lib/mumukit/login/mucookie.rb', line 36 def delete!(key) @controller. (key), Mumukit::Login.config. end |
#encode_and_write!(key, value, options = {}) ⇒ Object
20 21 22 |
# File 'lib/mumukit/login/mucookie.rb', line 20 def encode_and_write!(key, value, ={}) write! key, Base64.encode64(value), end |
#encrypt_and_write!(key, value, options = {}) ⇒ Object
16 17 18 |
# File 'lib/mumukit/login/mucookie.rb', line 16 def encrypt_and_write!(key, value, ={}) write! key, Encryptor.encrypt(value), end |
#read(key) ⇒ Object
24 25 26 |
# File 'lib/mumukit/login/mucookie.rb', line 24 def read(key) @controller. (key) end |
#spec ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/mumukit/login/mucookie.rb', line 40 def spec { path: '/', expires: Mumukit::Login.config..days.since, domain: Mumukit::Login.config. } end |
#write!(key, value, options = {}) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/mumukit/login/mucookie.rb', line 8 def write!(key, value, ={}) @controller. (key), spec.merge( value: value.to_s, httponly: !![:httponly], same_site: self.class.) end |