authform-rails 0.1.3 → 0.2.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: 23ebb35a910472a07da2364cfc0c642b1f93001f27f072601c8c3e4212518635
4
- data.tar.gz: fb4d2bace799e5201cf5f1e9d5f3b4e81ed90a4fd01df237276932859b52cb9b
3
+ metadata.gz: 7b38c9d775b5e9861d131ce83c0525ea036c1650b89c7fab83cfb7b294e7e349
4
+ data.tar.gz: 857853905a28f5bd2270d8df9ae2ec862f105f17774ac37ea39cc895f507bfca
5
5
  SHA512:
6
- metadata.gz: 167d5b9fd8d25b1799f24fadba55f3d33099b238063719540ef254ee10c22ce6f7c7022c6f661c4d0c7643538d60875ff4ea1a5d27549cbd991f461f0b3d29dc
7
- data.tar.gz: 9cf97a175dcf44700716495114796a64e44bbde96b144d6aba4a1e124b79fb77a315309b043935b7d55df2dd169ff281d48626cbd4be5ab153952dfbe6100653
6
+ metadata.gz: 6a28bf0004e36d4f765d022dbbf8244092cbb180f70fb36ac2c528fcdb332ff013777009b1c528539b8e7fe30434bfce72a43af91a2f305d1fbdf72c72823329
7
+ data.tar.gz: 46c3ce5bf584903a592fe69ef8150ab740426a4b8463188b7466023015bb767e9711671009e2c5f20c1af6c4dd378a0fca07b6035f334818131a299fee7669b1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- authform-rails (0.1.3)
4
+ authform-rails (0.2.0)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -1,34 +1,44 @@
1
1
  module Authform
2
2
  module Rails
3
- module Concern
4
- extend ActiveSupport::Concern
3
+ class Concern < Module
4
+ def initialize(form_uuid:)
5
+ super() do
6
+ extend ActiveSupport::Concern
5
7
 
6
- included do
7
- helper_method :authform_current_user
8
- before_action :check_for_authform_voucher
9
- end
8
+ included do
9
+ helper_method :current_user
10
+ before_action :_exchange_voucher_for_user
11
+ end
10
12
 
11
- private
13
+ private
12
14
 
13
- def authform_current_user
14
- JSON.parse(cookies[:_authform_current_user])["data"]
15
- rescue
16
- nil
17
- end
15
+ define_method :current_user do
16
+ begin
17
+ JSON.parse(cookies[authform_user_cookie_key])["data"]
18
+ rescue
19
+ nil
20
+ end
21
+ end
18
22
 
19
- def check_for_authform_voucher
20
- if params[:_authformVoucher]
21
- response = Faraday.get("#{Rails.application.credentials.root_url}/v1/exchangeVoucherForUser.json", { voucher: params[:_authformVoucher] })
23
+ define_method :_exchange_voucher_for_user do
24
+ if params[:_authformVoucher]
25
+ response = Faraday.get("https://api.authform.io/v1/exchangeVoucherForUser.json", { formUuid: form_uuid, voucher: params[:_authformVoucher] })
22
26
 
23
- if response.status == 200
24
- cookies[:_authform_current_user] = response.body
25
- end
27
+ if response.status == 200
28
+ cookies[authform_user_cookie_key] = response.body
29
+ end
30
+
31
+ q = Rack::Utils.parse_query(URI.parse(request.url).query)
32
+ q.delete("_authformVoucher")
33
+ url = q.empty? ? request.path : "#{request.path}?#{q.to_query}"
26
34
 
27
- q = Rack::Utils.parse_query(URI.parse(request.url).query)
28
- q.delete("_authformVoucher")
29
- url = q.empty? ? request.path : "#{request.path}?#{q.to_query}"
35
+ redirect_to url, status: 302 # redirect to finish removal of query param
36
+ end
37
+ end
30
38
 
31
- redirect_to url, status: 302 # redirect to finish removal of query param
39
+ define_method :authform_user_cookie_key do
40
+ "user#{form_uuid}"
41
+ end
32
42
  end
33
43
  end
34
44
  end
@@ -1,5 +1,5 @@
1
1
  module Authform
2
2
  module Rails
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authform-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gatleon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-02 00:00:00.000000000 Z
11
+ date: 2020-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday