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 +4 -4
- data/lib/repost/extend_controller.rb +12 -2
- data/lib/repost/senpai.rb +24 -15
- data/lib/repost/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c596318ae45ed6b77e768fc7eb3db94c21af30e4f92878421ac984ea7da664ee
|
4
|
+
data.tar.gz: 990b52812aa4e79247eaf99180535925cd4cf9cbd9a962fdcba96afb8693b47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
5
|
-
render html: Repost::Senpai.perform(
|
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)
|
data/lib/repost/senpai.rb
CHANGED
@@ -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
|
7
|
-
@params
|
8
|
-
@options
|
9
|
-
@method
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
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,
|
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}
|
data/lib/repost/version.rb
CHANGED
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.
|
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-
|
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.
|
89
|
+
rubygems_version: 3.0.1
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Gem implements Redirect using POST method
|