gatleon-authform-rails 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2aad9fabb2346b07e8aa80a03f2e06bdeda6fe6eead9ad8dc72fa9a8a1c0ffe7
4
- data.tar.gz: 366e08bf5690ec7a6db9156cc663d7355b551a07fa8d8bc2b4703a418e52702f
3
+ metadata.gz: b75dc2e45b5f446a8bf28e95e4d48eb096d5acef5de2b2cb453c3cc5ceaa626a
4
+ data.tar.gz: 8568b98d4cfb5e26b3c3d6d9d0bc5a0591d47a4a4e31dbfeb89bc0d9fd15757d
5
5
  SHA512:
6
- metadata.gz: 9fcbe5be7e43150b8c6f17070dcc8cf2401f6d1883be0ce35bb8f6632aa233f277d81bd3ea3a66c04de28d9893582b50aad4361965923a770b7ddd0819929091
7
- data.tar.gz: 89c79d90bdcdebbff0944d7a9f7f000407612b72f130bca589f5c80ccaa8677e6eec265a5c473f26df17c7c85a12acdcf8048191f72aeaf9c7c054d1dce17ffb
6
+ metadata.gz: 990f100b99d36e4c6b005a18dc270176fe25a86ce753731b3958bdaba10b74bf2fdd34813facd7768a25be4671f27d22cf4ca5993a6760d26714d4af30816e80
7
+ data.tar.gz: 507266798a6df6e2cea497455779d7a1e888dcaf0a697db6d5fe7f73a593866659de8eca4eb0ce789760cb710afb6d5fe067d3a20314f7c1ac06c58a8a5c5d80
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .byebug_history
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gatleon-authform-rails (0.2.0)
4
+ gatleon-authform-rails (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,5 @@
1
+ require "json"
2
+
1
3
  module Gatleon
2
4
  module Authform
3
5
  module Rails
@@ -20,9 +22,11 @@ module Gatleon
20
22
  # defaults to current_user
21
23
  define_method current_user_method_name do
22
24
  begin
23
- json = JSON.parse(cookies[_authform_user_cookie_key])["data"]
24
-
25
- Gatleon::Authform::Rails::User.new(json: json, _form_secret_key: secret_key, _authform_base_url: _authform_base_url)
25
+ Gatleon::Authform::Rails::User.new(_cookies: cookies,
26
+ _form_public_key: public_key,
27
+ _form_secret_key: secret_key,
28
+ _domain: domain,
29
+ _authform_base_url: _authform_base_url)
26
30
  rescue
27
31
  nil
28
32
  end
@@ -1,30 +1,45 @@
1
+ require "json"
2
+
1
3
  module Gatleon
2
4
  module Authform
3
5
  module Rails
4
6
  class User
5
7
  PERMITTED_CHARS = /\A[a-zA-Z0-9_)]*\z/
6
8
 
7
- def initialize(json:, _form_secret_key:, _authform_base_url:)
8
- @json = json
9
-
9
+ def initialize(_cookies:,
10
+ _form_public_key:,
11
+ _form_secret_key:,
12
+ _domain:,
13
+ _authform_base_url:)
14
+ @_cookies = _cookies
15
+ @_form_public_key = _form_public_key
10
16
  @_form_secret_key = _form_secret_key
17
+ @_domain = _domain
11
18
  @_authform_base_url = _authform_base_url
19
+
20
+ parse!
21
+ end
22
+
23
+ def parse!
24
+ !!_id
25
+ rescue
26
+ raise Gatleon::Authform::Rails::Error
12
27
  end
13
28
 
14
29
  # Getters
15
30
  #
16
31
  def _id
17
- @json["_id"]
32
+ data["_id"]
18
33
  end
19
34
 
20
35
  def _email
21
- @json["_email"]
36
+ data["_email"]
22
37
  end
23
38
 
24
39
  # Getters
25
40
  #
26
41
  def [](key)
27
- @json[key.to_s]
42
+ data[key.to_s]
28
43
  end
29
44
 
30
45
  # Setters
@@ -38,8 +53,31 @@ module Gatleon
38
53
 
39
54
  raise Gatleon::Authform::Rails::Error, "only characters a-z, A-Z, 0-9, and _ permitted in field name" unless key.match?(PERMITTED_CHARS)
40
55
 
41
- @json[key] = value.to_s
56
+ data[key] = value.to_s
57
+ end
58
+
59
+ def data
60
+ _json["data"]
61
+ end
62
+
63
+ def _json
64
+ @_json ||= JSON.parse(@_cookies[@_form_public_key])
65
+ end
66
+
67
+ def signoff!
68
+ if @_domain
69
+ @_cookies.delete(@_form_public_key, domain: @_domain)
70
+ else
71
+ @_cookies.delete(@_form_public_key)
72
+ end
42
73
  end
74
+ alias_method :sign_off!, :signoff!
75
+ alias_method :signout!, :signoff!
76
+ alias_method :sign_out!, :signoff!
77
+ alias_method :logout!, :signoff!
78
+ alias_method :log_out!, :signoff!
79
+ alias_method :logoff!, :signoff!
80
+ alias_method :log_off!, :signoff!
43
81
 
44
82
  private
45
83
 
@@ -1,7 +1,7 @@
1
1
  module Gatleon
2
2
  module Authform
3
3
  module Rails
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gatleon-authform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gatleon