Class: Gatleon::Authform::Rails::User
- Inherits:
-
Object
- Object
- Gatleon::Authform::Rails::User
- Defined in:
- lib/gatleon/authform/rails/user.rb
Constant Summary collapse
- PERMITTED_CHARS =
/\A[a-zA-Z0-9_)]*\z/
Instance Method Summary collapse
-
#[](key) ⇒ Object
Getters.
-
#[]=(key, value) ⇒ Object
Setters.
- #_email ⇒ Object
-
#_id ⇒ Object
Getters.
- #_json ⇒ Object
- #data ⇒ Object
-
#initialize(_cookies:, _authform_user_cookie_key:, _form_secret_key:, _domain:, _authform_base_url:) ⇒ User
constructor
A new instance of User.
- #parse! ⇒ Object
- #signoff! ⇒ Object (also: #sign_off!, #signout!, #sign_out!, #logout!, #log_out!, #logoff!, #log_off!)
Constructor Details
#initialize(_cookies:, _authform_user_cookie_key:, _form_secret_key:, _domain:, _authform_base_url:) ⇒ User
Returns a new instance of User.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/gatleon/authform/rails/user.rb', line 9 def initialize(_cookies:, _authform_user_cookie_key:, _form_secret_key:, _domain:, _authform_base_url:) @_cookies = @_authform_user_cookie_key = @_form_secret_key = _form_secret_key @_domain = _domain @_authform_base_url = _authform_base_url parse! end |
Instance Method Details
#[](key) ⇒ Object
Getters
41 42 43 |
# File 'lib/gatleon/authform/rails/user.rb', line 41 def [](key) data[key.to_s] end |
#[]=(key, value) ⇒ Object
Setters
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gatleon/authform/rails/user.rb', line 47 def []=(key, value) key = _clean_key(key) raise Gatleon::Authform::Rails::Error, "can't set reserved field name #{key}" if key[0] == "_" # anything starting with _ raise Gatleon::Authform::Rails::Error, "can't set empty field name" if key == "" raise Gatleon::Authform::Rails::Error, "only characters a-z, A-Z, 0-9, and _ permitted in field name" unless key.match?(PERMITTED_CHARS) data[key] = value.to_s end |
#_email ⇒ Object
35 36 37 |
# File 'lib/gatleon/authform/rails/user.rb', line 35 def _email data["_email"] end |
#_id ⇒ Object
Getters
31 32 33 |
# File 'lib/gatleon/authform/rails/user.rb', line 31 def _id data["_id"] end |
#_json ⇒ Object
63 64 65 |
# File 'lib/gatleon/authform/rails/user.rb', line 63 def _json @_json ||= JSON.parse(@_cookies[@_authform_user_cookie_key]) end |
#data ⇒ Object
59 60 61 |
# File 'lib/gatleon/authform/rails/user.rb', line 59 def data _json["data"] end |
#parse! ⇒ Object
23 24 25 26 27 |
# File 'lib/gatleon/authform/rails/user.rb', line 23 def parse! !!_id rescue raise Gatleon::Authform::Rails::Error end |
#signoff! ⇒ Object Also known as: sign_off!, signout!, sign_out!, logout!, log_out!, logoff!, log_off!
67 68 69 70 71 72 73 |
# File 'lib/gatleon/authform/rails/user.rb', line 67 def signoff! if @_domain @_cookies.delete(@_authform_user_cookie_key, domain: @_domain) else @_cookies.delete(@_authform_user_cookie_key) end end |