repost 0.2.8 → 0.2.9

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: 0c1eb812466ae1d54e302afadfa2b7576e69495df40f154679a0168aa0e38b36
4
- data.tar.gz: a09f449f0856017e620eb9677f19c863ca04518df9f8fa805480f23784658d45
3
+ metadata.gz: c596318ae45ed6b77e768fc7eb3db94c21af30e4f92878421ac984ea7da664ee
4
+ data.tar.gz: 990b52812aa4e79247eaf99180535925cd4cf9cbd9a962fdcba96afb8693b47e
5
5
  SHA512:
6
- metadata.gz: 4e33d7fac875714bfab601362aa4682fca3cb41cc38e893ac44369fa29050a93b2d25ae4919080886bec98e841fb4be1b0a0c05be813f2cf4ab666bf06e12dee
7
- data.tar.gz: 540c5cecdabf30b9225af96d0475a305fd5beef07e4d1380fffa82151bed725a62261244d9b710956bca9c209857fe0b3db5b93f6ff98659ef0f944848caf38c
6
+ metadata.gz: 761da6f4e436e85a1dc62c8446010a8465a18e7584df595b19176b85624a1459a38cda391b7aee2363b26509bcfbd04c15468bd7e0c832edb960d730b0d0d2c5
7
+ data.tar.gz: ed1c4a2c9350388846f9bafac08aac3439f98fa2802a69d6dc92e53d8a16b463d1823ffd57eee2bee0242f21e4a1818149139689031d91388cadbe666e09584c
@@ -1,10 +1,20 @@
1
1
  if defined?(Rails)
2
2
  class ::ActionController::Base
3
3
 
4
- def repost(*args)
5
- render html: Repost::Senpai.perform(*args).html_safe
4
+ def repost(url, params: {}, options: {})
5
+ render html: Repost::Senpai.perform(
6
+ url,
7
+ params: params,
8
+ options: options.reverse_merge(authenticity_token: form_authenticity_token)
9
+ ).html_safe
6
10
  end
7
11
 
8
12
  alias :redirect_post :repost
13
+
9
14
  end
10
15
  end
16
+
17
+ # Sinatra & Rack Protection
18
+ # TODO
19
+ # defined?(Sinatra::Base) && defined?(Rack::Protection::AuthenticityToken)
20
+ # env&.fetch('rack.session', :csrf)
@@ -1,18 +1,21 @@
1
1
  module Repost
2
2
  class Senpai < Action
3
3
  DEFAULT_SUBMIT_BUTTON_TEXT = 'Continue'
4
+ DEFAULT_CHARSET = 'UTF-8'
4
5
 
5
6
  def initialize(url, params: {}, options: {})
6
- @url = url
7
- @params = params
8
- @options = options
9
- @method = options[:method] || :post
10
- @form_id = options[:form_id] || generated_form_id
11
- @autosubmit = options.fetch(:autosubmit, true)
12
- @section_classes = options.dig(:decor, :section, :classes)
13
- @section_html = options.dig(:decor, :section, :html)
14
- @submit_classes = options.dig(:decor, :submit, :classes)
15
- @submit_text = options.dig(:decor, :submit, :text) || DEFAULT_SUBMIT_BUTTON_TEXT
7
+ @url = url
8
+ @params = params
9
+ @options = options
10
+ @method = options.fetch(:method, :post)
11
+ @authenticity_token = options.fetch(:authenticity_token, nil)
12
+ @charset = options.fetch(:charset, DEFAULT_CHARSET)
13
+ @form_id = options.fetch(:form_id, generated_form_id)
14
+ @autosubmit = options.fetch(:autosubmit, true)
15
+ @section_classes = options.dig(:decor, :section, :classes)
16
+ @section_html = options.dig(:decor, :section, :html)
17
+ @submit_classes = options.dig(:decor, :submit, :classes)
18
+ @submit_text = options.dig(:decor, :submit, :text) || DEFAULT_SUBMIT_BUTTON_TEXT
16
19
  end
17
20
 
18
21
  def perform
@@ -27,23 +30,29 @@ module Repost
27
30
  private
28
31
 
29
32
  attr_reader :url, :params, :options, :method, :form_id, :autosubmit,
30
- :section_classes, :section_html, :submit_classes, :submit_text
33
+ :section_classes, :section_html, :submit_classes,
34
+ :submit_text, :authenticity_token, :charset
35
+
36
+ def form_head
37
+ "<form id='#{form_id}' action='#{url}' method='#{method}' accept-charset='#{charset}'>"
38
+ end
31
39
 
32
40
  def form_body
33
41
  inputs = params.map do |key, value|
34
42
  "<input type='hidden' name='#{key}' value='#{value}'>"
35
43
  end
44
+ inputs.unshift(csrf_token) if authenticity_token
36
45
  inputs.join
37
46
  end
38
47
 
39
- def form_head
40
- "<form id='#{form_id}' action='#{url}' method='#{method}'>"
41
- end
42
-
43
48
  def form_footer
44
49
  "</form>"
45
50
  end
46
51
 
52
+ def csrf_token
53
+ "<input name='authenticity_token' value='#{authenticity_token}' type='hidden'>"
54
+ end
55
+
47
56
  def no_script
48
57
  "<noscript>
49
58
  #{submit_section}
@@ -1,3 +1,3 @@
1
1
  module Repost
2
- VERSION = "0.2.8"
2
+ VERSION = "0.2.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - YaroslavO
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
- rubygems_version: 3.0.2
89
+ rubygems_version: 3.0.1
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Gem implements Redirect using POST method