class Gatleon::Authform::Rails::User

Constants

PERMITTED_CHARS

Public Class Methods

new(_cookies:, _authform_user_cookie_key:, _form_secret_key:, _domain:, _authform_base_url:) click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 9
def initialize(_cookies:,
               _authform_user_cookie_key:,
               _form_secret_key:,
               _domain:,
               _authform_base_url:)
  @_cookies = _cookies
  @_authform_user_cookie_key = _authform_user_cookie_key
  @_form_secret_key = _form_secret_key
  @_domain = _domain
  @_authform_base_url = _authform_base_url

  parse!
end

Public Instance Methods

[](key) click to toggle source

Getters

# File lib/gatleon/authform/rails/user.rb, line 41
def [](key)
  data[key.to_s]
end
[]=(key, value) click to toggle source

Setters

# 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() click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 35
def _email
  data["_email"]
end
_id() click to toggle source

Getters

# File lib/gatleon/authform/rails/user.rb, line 31
def _id
  data["_id"]
end
_json() click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 63
def _json
  @_json ||= JSON.parse(@_cookies[@_authform_user_cookie_key])
end
data() click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 59
def data
  _json["data"]
end
log_off!()
Alias for: signoff!
log_out!()
Alias for: signoff!
logoff!()
Alias for: signoff!
logout!()
Alias for: signoff!
parse!() click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 23
def parse!
  !!_id
rescue
  raise Gatleon::Authform::Rails::Error
end
sign_off!()
Alias for: signoff!
sign_out!()
Alias for: signoff!
signoff!() click to toggle source
# 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
signout!()
Alias for: signoff!

Private Instance Methods

_clean_key(k_or_v) click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 94
def _clean_key(k_or_v)
  k_or_v.to_s.strip
end
_persist(key, value) click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 84
def _persist(key, value)
  uri = _persist_url(key, vlue)
  
  Net::HTTP.get_response(uri) # TODO: move to post request
end
_persist_url(key, value) click to toggle source
# File lib/gatleon/authform/rails/user.rb, line 90
def _persist_url(key, value)
  URI("#{@_authform_base_url}/v1/setUser?_id=#{_id}&_secretKey=#{@_form_secret_key}&#{key}=#{value}")
end