aaalex-permanent_cookies 0.0.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.
- data/MIT-LICENSE +20 -0
- data/README +12 -0
- data/lib/permanent_cookies.rb +62 -0
- data/test/permanent_cookies_test.rb +8 -0
- metadata +57 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Aaalex
|
2
|
+
module PermanentCookies
|
3
|
+
def self.included(base)
|
4
|
+
base.around_filter :permanent_cookies
|
5
|
+
end
|
6
|
+
|
7
|
+
MAX = 4096
|
8
|
+
PCOOKIE_SUFFIX = "_pcookie"
|
9
|
+
SECRET = "534b44a19bf18d20b71ecc4eb77c572f"
|
10
|
+
|
11
|
+
def permanent_cookies
|
12
|
+
@pcookies = {}
|
13
|
+
cookies.each_pair do |cname, cvalue|
|
14
|
+
if cname.include?(PCOOKIE_SUFFIX)
|
15
|
+
@pcookies[cname.split(PCOOKIE_SUFFIX).first] = unmarshal( cvalue.first)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
logger.info "got pcookie\n#{@pcookies.to_yaml}"
|
19
|
+
|
20
|
+
yield
|
21
|
+
|
22
|
+
@pcookies.each_pair do |pcookie_name, pcookie_val|
|
23
|
+
pc_val = if pcookie_val.is_a?( Hash)
|
24
|
+
pcookie_val
|
25
|
+
else
|
26
|
+
{ :value => pcookie_val,
|
27
|
+
:expires => 1.week.from_now }
|
28
|
+
end
|
29
|
+
pc_val[:value] = marshal pc_val[:value]
|
30
|
+
raise StandardError if pc_val[:value].size > MAX
|
31
|
+
cookies[pcookie_name + PCOOKIE_SUFFIX] = pc_val
|
32
|
+
end
|
33
|
+
# delete all other unused pcookies
|
34
|
+
# pcookies = defined?(@pcookies) ? @pcookies : {}
|
35
|
+
# cookies.each_key do |cookie|
|
36
|
+
# if cookie.include?(PCOOKIE_SUFFIX) && !pcookies.key?(cookie)
|
37
|
+
# cookies[cookie] = {:value => nil, :expires => 1.year.ago}
|
38
|
+
# end
|
39
|
+
# end
|
40
|
+
end
|
41
|
+
def generate_digest(data)
|
42
|
+
OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), SECRET, data)
|
43
|
+
end
|
44
|
+
def marshal(var)
|
45
|
+
data = ActiveSupport::Base64.encode64(Marshal.dump(var)).chop
|
46
|
+
"#{data}--#{generate_digest(data)}"
|
47
|
+
end
|
48
|
+
def unmarshal(cookie)
|
49
|
+
if cookie
|
50
|
+
data, digest = cookie.split('--')
|
51
|
+
unless digest == generate_digest(data) || digest == generate_digest(data = CGI.unescape(data))
|
52
|
+
# tampered with cookie
|
53
|
+
raise StandardError
|
54
|
+
end
|
55
|
+
Marshal.load(ActiveSupport::Base64.decode64(data))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
ActionController::Base.send(:include, Aaalex::PermanentCookies)
|
62
|
+
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aaalex-permanent_cookies
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Peuchert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-07-07 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: RoR before_filter to detect mobile browsers
|
17
|
+
email: apeuchert@googlemail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- MIT-LICENSE
|
25
|
+
files:
|
26
|
+
- lib/permanent_cookies.rb
|
27
|
+
- README
|
28
|
+
- MIT-LICENSE
|
29
|
+
has_rdoc: true
|
30
|
+
homepage: http://github.com/aaalex/permanent_cookies
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options:
|
33
|
+
- --main
|
34
|
+
- README
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.2.0
|
53
|
+
signing_key:
|
54
|
+
specification_version: 2
|
55
|
+
summary: use permanent cookies to store data on the client on RoR
|
56
|
+
test_files:
|
57
|
+
- test/permanent_cookies_test.rb
|