glib-web 3.22.1 → 3.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/concerns/glib/json/libs.rb +28 -9
- data/app/helpers/glib/urls_helper.rb +2 -2
- data/lib/glib/crypt/utils.rb +2 -1
- data/lib/glib/crypt.rb +27 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 806df354ed58edcee98f342d40209e0f42b16343f79427941accd17b796d6c33
|
4
|
+
data.tar.gz: 8b0de205b315c74ad1a773cf6963f461e2952cf1fbf5f36e63aea66c648c4640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e9062feefed9651443c3a128de05df41e63a755cafdc10b66167f60643b9bf847a1dc4c68af9f95e8b9eff4f7a0f3b52d31fa61907575a6f09de7903dffb684
|
7
|
+
data.tar.gz: 651ae04bd671192239d8bc08e144733a011f6777e6b33347739579ec7511c7ff9bd9d0f23ff36ff110076242424606ac0500cb80ba0212b4487f788b177b7f55
|
@@ -62,14 +62,27 @@ module Glib::Json::Libs
|
|
62
62
|
JSON.parse(render_to_string(template, locals: args))
|
63
63
|
end
|
64
64
|
|
65
|
-
def
|
65
|
+
def glib_html_url(url)
|
66
|
+
url = url.include?('?') ? url.sub(/.json\?/, '?') : url.sub(/.json$/, '')
|
67
|
+
|
68
|
+
# As much as possible, try retaining the front fragment by matching the back, because
|
69
|
+
# the front could be either a `?` or `&`
|
70
|
+
url = url.sub(/format=json\&/, '');
|
71
|
+
|
72
|
+
# If no match, then we replace the front fragment
|
73
|
+
url.sub(/[\&\?]format=json/, '');
|
74
|
+
end
|
75
|
+
|
76
|
+
def glib_redirect_to(url, return_to_previous: false)
|
77
|
+
url = __delete_redirect_back_url(url) if return_to_previous
|
78
|
+
|
66
79
|
respond_to do |format|
|
67
80
|
format.html do
|
68
81
|
redirect_to url
|
69
82
|
end
|
70
83
|
format.json do
|
71
84
|
if __json_ui_rendering?
|
72
|
-
redirect_to url
|
85
|
+
redirect_to glib_html_url(url)
|
73
86
|
return
|
74
87
|
end
|
75
88
|
|
@@ -147,10 +160,10 @@ module Glib::Json::Libs
|
|
147
160
|
session.delete(REDIRECT_BACK_KEY) || url
|
148
161
|
end
|
149
162
|
|
150
|
-
def html_ui_redirect_back_or_to(default_url)
|
151
|
-
|
152
|
-
|
153
|
-
end
|
163
|
+
# def html_ui_redirect_back_or_to(default_url)
|
164
|
+
# redirect_url = __delete_redirect_back_url(default_url)
|
165
|
+
# redirect_to redirect_url
|
166
|
+
# end
|
154
167
|
|
155
168
|
def json_ui_redirect_back_or_to(default_url, json_action)
|
156
169
|
redirect_url = __delete_redirect_back_url(default_url)
|
@@ -210,9 +223,15 @@ module Glib::Json::Libs
|
|
210
223
|
end
|
211
224
|
|
212
225
|
def json_ui_redirect_to(url)
|
213
|
-
|
214
|
-
|
215
|
-
|
226
|
+
# `onLoad` also executes in `onResponse` situation, e.g. form submit.
|
227
|
+
on_load = { action: 'windows/open', url: url }
|
228
|
+
|
229
|
+
if glib_json_dialog_mode?
|
230
|
+
# Only do this in dialog mode because this seems to add to the rendering time
|
231
|
+
# (i.e. longer flicker time), presumably due to the use of things like `nextTick()`.
|
232
|
+
on_load = { action: 'dialogs/close', onClose: on_load }
|
233
|
+
end
|
234
|
+
render json: { onLoad: on_load }
|
216
235
|
end
|
217
236
|
|
218
237
|
module ClassMethods
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Glib
|
2
2
|
module UrlsHelper
|
3
|
-
def glib_url_current(
|
4
|
-
url_for(
|
3
|
+
def glib_url_current(override_params: params.to_unsafe_h, extra_params: {})
|
4
|
+
url_for(override_params.merge(extra_params.merge(only_path: false)))
|
5
5
|
end
|
6
6
|
|
7
7
|
def glib_url_equals_current?(url)
|
data/lib/glib/crypt/utils.rb
CHANGED
data/lib/glib/crypt.rb
CHANGED
@@ -1 +1,28 @@
|
|
1
1
|
require_relative './crypt/utils'
|
2
|
+
|
3
|
+
# A replacement of Glib::Crypt::Utils
|
4
|
+
module Glib
|
5
|
+
class Crypt
|
6
|
+
# Recommended digest: 'SHA256'
|
7
|
+
def self.encrypt(original_message, encryption_secret, encryption_salt, digest)
|
8
|
+
encryptor = message_encryptor(encryption_secret, encryption_salt, digest)
|
9
|
+
CGI.escape(encryptor.encrypt_and_sign(original_message))
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.decrypt(encrypted_message, encryption_secret, encryption_salt, digest)
|
13
|
+
encryptor = message_encryptor(encryption_secret, encryption_salt, digest)
|
14
|
+
begin
|
15
|
+
encryptor.decrypt_and_verify(CGI.unescape(encrypted_message))
|
16
|
+
rescue ActiveSupport::MessageEncryptor::InvalidMessage
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def self.message_encryptor(encryption_secret, encryption_salt, digest)
|
23
|
+
key_generator = ActiveSupport::KeyGenerator.new(encryption_secret, iterations: 1000)
|
24
|
+
key_secret = key_generator.generate_key(encryption_salt, 32)
|
25
|
+
ActiveSupport::MessageEncryptor.new(key_secret, digest: digest, serializer: JSON)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|