challah 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/challah.rb +1 -1
- data/lib/challah/audit.rb +51 -50
- data/lib/challah/concerns/user/findable.rb +17 -19
- data/lib/challah/controller.rb +72 -73
- data/lib/challah/cookie_store.rb +6 -5
- data/lib/challah/encrypter.rb +14 -5
- data/lib/challah/engine.rb +27 -31
- data/lib/challah/session.rb +51 -52
- data/lib/challah/simple_cookie_store.rb +82 -81
- data/lib/challah/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f03909894b61ef1fdbfc44ee6f84b221e10abe97
|
4
|
+
data.tar.gz: 66cb9a87b30a57581d45afaebdcde5e8e748b81f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c392131e19fa54603ffda28f8466888440635c71a97e55ff1401c02efb0faab5e46ed6d2089e86cf083ab03410e0bf88fdb71621191d7aadccc29642243be6d3
|
7
|
+
data.tar.gz: 1db8e607039db9d51cd02d9f9de641f7756a92f034331b96a73d7e93b43144f8ae6c7c88564a6856d2bce7d51c67dc0ea980daba5ee31b064ab903905f0091a9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Challah 1.2.2
|
2
|
+
|
3
|
+
* Bug fix for “A copy of User has been removed from the module tree but is still active!” error in Rails development mode. Fix was to not cache the `User` model reference from within the engine.
|
4
|
+
|
1
5
|
## Challah 1.2.1
|
2
6
|
|
3
7
|
* Bug fixed when loading `challah/test` in minitest.
|
data/lib/challah.rb
CHANGED
data/lib/challah/audit.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Challah
|
2
|
-
# The audit methods are included into ActiveRecord::Base automatically and add
|
3
|
-
# basic audit trail functionality for your models. Certain columns will be
|
2
|
+
# The audit methods are included into ActiveRecord::Base automatically and add
|
3
|
+
# basic audit trail functionality for your models. Certain columns will be
|
4
4
|
# updated with the current user's id if provided at save time.
|
5
5
|
#
|
6
6
|
# For new records, the following fields will be updated if +current_user+ is provided:
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# * created_by
|
9
9
|
# * created_user_id
|
10
10
|
#
|
@@ -28,17 +28,17 @@ module Challah
|
|
28
28
|
# end
|
29
29
|
#
|
30
30
|
module Audit
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
extend ActiveSupport::Concern
|
32
|
+
|
33
|
+
included do
|
34
|
+
before_save :before_save_audit
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# @private
|
38
38
|
def initialize_dup(other)
|
39
39
|
clear_audit_attributes
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
def current_user=(value)
|
43
43
|
@current_user_id = (Object === value ? value[:id] : value)
|
44
44
|
end
|
@@ -54,53 +54,54 @@ module Challah
|
|
54
54
|
|
55
55
|
@current_user_id
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
private
|
59
|
-
def before_save_audit
|
60
|
-
if new_record?
|
61
|
-
all_audit_attributes.each do |attr_name|
|
62
|
-
attr_name = attr_name.to_s
|
63
|
-
column = column_for_attribute(attr_name)
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
def before_save_audit
|
61
|
+
if new_record?
|
62
|
+
all_audit_attributes.each do |attr_name|
|
63
|
+
attr_name = attr_name.to_s
|
64
|
+
column = column_for_attribute(attr_name)
|
65
|
+
|
66
|
+
if column || @attributes.has_key?(attr_name)
|
67
|
+
write_attribute(attr_name, current_user_id)
|
68
68
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
end
|
70
|
+
else
|
71
|
+
audit_attributes_for_update.each do |column|
|
72
|
+
if respond_to?(column) && respond_to?("#{ column }=")
|
73
|
+
column = column.to_s
|
74
|
+
next if attribute_changed?(column) # don't update the column if we already manually did
|
75
|
+
write_attribute(column, current_user_id)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
changed_attributes.delete(attribute_name)
|
79
|
+
end
|
80
|
+
|
81
|
+
# @private
|
82
|
+
def audit_attributes_for_update
|
83
|
+
[ :updated_by, :modifed_by, :updated_user_id ]
|
84
|
+
end
|
85
|
+
|
86
|
+
# @private
|
87
|
+
def audit_attributes_for_create
|
88
|
+
[ :created_by, :created_user_id ]
|
89
|
+
end
|
90
|
+
|
91
|
+
# @private
|
92
|
+
def all_audit_attributes
|
93
|
+
audit_attributes_for_update + audit_attributes_for_create
|
94
|
+
end
|
95
|
+
|
96
|
+
# Clear attributes and changed_attributes
|
97
|
+
def clear_audit_attributes
|
98
|
+
all_audit_attributes.each do |attribute_name|
|
99
|
+
if respond_to?(attribute_name) && respond_to?("#{ attribute_name }=")
|
100
|
+
write_attribute(attribute_name, nil)
|
103
101
|
end
|
102
|
+
|
103
|
+
changed_attributes.delete(attribute_name)
|
104
104
|
end
|
105
|
+
end
|
105
106
|
end
|
106
|
-
end
|
107
|
+
end
|
@@ -14,32 +14,30 @@ module Challah
|
|
14
14
|
# Find a user instance by username first, or email address if needed.
|
15
15
|
# If no user is found matching, return nil
|
16
16
|
def find_for_session(username_or_email)
|
17
|
-
return
|
17
|
+
return if username_or_email.to_s.blank?
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
result = where(email: username_or_email).first
|
23
|
-
end
|
19
|
+
username_or_email = username_or_email.downcase.strip
|
20
|
+
find_by_email(username_or_email) || find_by_authorization(username_or_email)
|
21
|
+
end
|
24
22
|
|
25
|
-
|
26
|
-
|
23
|
+
def inactive
|
24
|
+
where.not(active: true)
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
authorization = authorization.where(provider: :password, uid: uid)
|
30
|
-
authorization = authorization.first
|
27
|
+
protected
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def find_by_authorization(uid)
|
30
|
+
authorization = self.authorization_model
|
31
|
+
result = authorization.where(provider: :password, uid: uid).first
|
32
|
+
if result
|
33
|
+
result.user
|
35
34
|
end
|
36
|
-
|
37
|
-
result
|
38
35
|
end
|
39
36
|
|
40
|
-
def
|
41
|
-
|
37
|
+
def find_by_email(email)
|
38
|
+
return unless email.include?('@')
|
39
|
+
where(email: email).first
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
45
|
-
end
|
43
|
+
end
|
data/lib/challah/controller.rb
CHANGED
@@ -2,10 +2,10 @@ module Challah
|
|
2
2
|
# These methods are added into ActionController::Base and are available in all
|
3
3
|
# of your app's controllers.
|
4
4
|
module Controller
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
extend ClassMethods
|
9
9
|
end
|
10
10
|
|
11
11
|
module ClassMethods
|
@@ -41,79 +41,78 @@ module Challah
|
|
41
41
|
alias_method :login_required, :signin_required
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
protected
|
46
|
-
# Is there currently a logged in user? Returns true if it is safe to use
|
47
|
-
# the {#current_user current_user} method.
|
48
|
-
#
|
49
|
-
# @note This method is also available as a helper in your views.
|
50
|
-
#
|
51
|
-
# @see #current_user current_user
|
52
|
-
#
|
53
|
-
# @return [Boolean] Is there a user logged in?
|
54
|
-
def current_user?
|
55
|
-
!!current_user
|
56
|
-
end
|
44
|
+
protected
|
57
45
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
46
|
+
# Is there currently a logged in user? Returns true if it is safe to use
|
47
|
+
# the {#current_user current_user} method.
|
48
|
+
#
|
49
|
+
# @note This method is also available as a helper in your views.
|
50
|
+
#
|
51
|
+
# @see #current_user current_user
|
52
|
+
#
|
53
|
+
# @return [Boolean] Is there a user logged in?
|
54
|
+
def current_user?
|
55
|
+
!!current_user
|
56
|
+
end
|
63
57
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# @return [User, nil] The current authenticated user.
|
70
|
-
def current_user
|
71
|
-
@current_user ||= current_user_session.user
|
72
|
-
end
|
58
|
+
# Alias for current_user?
|
59
|
+
def signed_in?
|
60
|
+
current_user?
|
61
|
+
end
|
62
|
+
alias_method :logged_in?, :signed_in?
|
73
63
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
64
|
+
# The user that is currently logged into this session. If there is no
|
65
|
+
# user logged in, nil will be returned.
|
66
|
+
#
|
67
|
+
# @note This method is also available as a helper in your views.
|
68
|
+
#
|
69
|
+
# @return [User, nil] The current authenticated user.
|
70
|
+
def current_user
|
71
|
+
@current_user ||= current_user_session.user
|
72
|
+
end
|
82
73
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
# @example
|
92
|
-
# class YourController < ApplicationController
|
93
|
-
# before_filter :login_required
|
94
|
-
#
|
95
|
-
# # ...
|
96
|
-
# end
|
97
|
-
#
|
98
|
-
# @example Specifing certain actions.
|
99
|
-
# class YourOtherController < ApplicationController
|
100
|
-
# before_filter :login_required, :only => [ :create, :update, :destroy ]
|
101
|
-
#
|
102
|
-
# # ...
|
103
|
-
# end
|
104
|
-
#
|
105
|
-
# @see Controller::ClassMethods#restrict_to_authenticated restrict_to_authenticated
|
106
|
-
def signin_required
|
107
|
-
unless signed_in?
|
108
|
-
session[:return_to] = request.url
|
109
|
-
redirect_to signin_path and return
|
110
|
-
end
|
111
|
-
end
|
112
|
-
alias_method :login_required, :signin_required
|
74
|
+
# The current authentication session, if one exists. A {Session} object will be
|
75
|
+
# returned regardless of its valid status. If an invalid session is returned, the
|
76
|
+
# {Session#user user} attribute will be nil.
|
77
|
+
#
|
78
|
+
# @return [Session] The current browser session.
|
79
|
+
def current_user_session
|
80
|
+
@current_user_session ||= Challah::Session.find(request, params, user_model)
|
81
|
+
end
|
113
82
|
|
114
|
-
|
115
|
-
|
116
|
-
|
83
|
+
# Restrict a controller to only authenticated users. If someone tries to access
|
84
|
+
# a restricted action and is not logged in, they will be redirected to the
|
85
|
+
# login page.
|
86
|
+
#
|
87
|
+
# This method is an alias for:
|
88
|
+
#
|
89
|
+
# restrict_to_authenticated
|
90
|
+
#
|
91
|
+
# @example
|
92
|
+
# class YourController < ApplicationController
|
93
|
+
# before_filter :login_required
|
94
|
+
#
|
95
|
+
# # ...
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# @example Specifing certain actions.
|
99
|
+
# class YourOtherController < ApplicationController
|
100
|
+
# before_filter :login_required, :only => [ :create, :update, :destroy ]
|
101
|
+
#
|
102
|
+
# # ...
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# @see Controller::ClassMethods#restrict_to_authenticated restrict_to_authenticated
|
106
|
+
def signin_required
|
107
|
+
unless signed_in?
|
108
|
+
session[:return_to] = request.url
|
109
|
+
redirect_to signin_path and return
|
110
|
+
end
|
111
|
+
end
|
112
|
+
alias_method :login_required, :signin_required
|
113
|
+
|
114
|
+
def user_model
|
115
|
+
@_challah_user_model ||= Challah.user
|
117
116
|
end
|
118
117
|
end
|
119
|
-
end
|
118
|
+
end
|
data/lib/challah/cookie_store.rb
CHANGED
@@ -14,9 +14,10 @@ module Challah
|
|
14
14
|
end
|
15
15
|
|
16
16
|
protected
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
|
18
|
+
def validation_cookie_value(value = nil)
|
19
|
+
value = session_cookie_value unless value
|
20
|
+
Encrypter.md5(value, request.user_agent, request.remote_ip)
|
21
|
+
end
|
21
22
|
end
|
22
|
-
end
|
23
|
+
end
|
data/lib/challah/encrypter.rb
CHANGED
@@ -39,11 +39,20 @@ module Challah
|
|
39
39
|
false
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
def self.compare(*args)
|
43
|
+
new().compare(*args)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.encrypt(*args)
|
47
|
+
new().encrypt(*args)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.hash(*args)
|
51
|
+
new().hash(*args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.md5(*args)
|
55
|
+
new().md5(*args)
|
47
56
|
end
|
48
57
|
end
|
49
58
|
end
|
data/lib/challah/engine.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Challah
|
2
|
-
|
3
2
|
class Engine < ::Rails::Engine
|
4
3
|
|
5
4
|
initializer 'challah.router' do |app|
|
@@ -18,45 +17,42 @@ module Challah
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
proc.call
|
38
|
-
end
|
20
|
+
# Set up controller methods
|
21
|
+
def self.setup_action_controller!
|
22
|
+
if defined?(ActionController)
|
23
|
+
ActionController::Base.send(:include, Challah::Controller)
|
24
|
+
ActionController::Base.send(:helper_method,
|
25
|
+
:current_user_session,
|
26
|
+
:current_user,
|
27
|
+
:current_user?,
|
28
|
+
:logged_in?,
|
29
|
+
:signed_in?
|
30
|
+
)
|
31
|
+
|
32
|
+
# Load any ActionController/Challah plugins
|
33
|
+
Challah.plugins.values.each do |plugin|
|
34
|
+
plugin.action_controller.each do |proc|
|
35
|
+
proc.call
|
39
36
|
end
|
40
37
|
end
|
41
38
|
end
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
# Set up active record with Challah methods
|
42
|
+
def self.setup_active_record!
|
43
|
+
if defined?(ActiveRecord)
|
44
|
+
Challah.options[:logger] = ActiveRecord::Base.logger
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
ActiveRecord::Base.send(:include, Challah::ActiveRecordExtensions)
|
47
|
+
ActiveRecord::Base.send(:include, Challah::Audit)
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
49
|
+
# Load any ActiveRecord/Challah plugins
|
50
|
+
Challah.plugins.values.each do |plugin|
|
51
|
+
plugin.active_record.each do |proc|
|
52
|
+
proc.call
|
56
53
|
end
|
57
54
|
end
|
58
55
|
end
|
59
56
|
end
|
60
57
|
end
|
61
|
-
|
62
58
|
end
|
data/lib/challah/session.rb
CHANGED
@@ -96,72 +96,71 @@ module Challah
|
|
96
96
|
super(sym, *args, &block)
|
97
97
|
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
user_model = Challah.user if user_model.nil?
|
99
|
+
# Manually create a new Session
|
100
|
+
def self.create(user_or_user_id, request = nil, params = nil, user_model = nil)
|
101
|
+
user_model = Challah.user if user_model.nil?
|
103
102
|
|
104
|
-
|
103
|
+
user_record = user_model === user_or_user_id ? user_or_user_id : user_model.find_by_id(user_or_user_id)
|
105
104
|
|
106
|
-
|
105
|
+
session = Session.new(request, params, user_model)
|
107
106
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
session
|
107
|
+
if user_record and user_record.active?
|
108
|
+
session.user = user_record
|
109
|
+
session.persist = true
|
114
110
|
end
|
115
111
|
|
116
|
-
|
117
|
-
|
118
|
-
session = create(user_or_user_id, request, params, user_model)
|
119
|
-
session.save
|
120
|
-
session
|
121
|
-
end
|
112
|
+
session
|
113
|
+
end
|
122
114
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
115
|
+
# Manually create a session, and save it.
|
116
|
+
def self.create!(user_or_user_id, request = nil, params = nil, user_model = nil)
|
117
|
+
session = create(user_or_user_id, request, params, user_model)
|
118
|
+
session.save
|
119
|
+
session
|
120
|
+
end
|
129
121
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
122
|
+
# Clear out any existing sessions
|
123
|
+
def self.destroy
|
124
|
+
session = Session.find
|
125
|
+
session.destroy if session
|
126
|
+
session
|
127
|
+
end
|
128
|
+
|
129
|
+
# Load any existing session from the session store
|
130
|
+
def self.find(*args)
|
131
|
+
session = Session.new(*args)
|
132
|
+
session.find
|
133
|
+
session
|
136
134
|
end
|
137
135
|
|
138
136
|
protected
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
if @user
|
149
|
-
@persist = technique.respond_to?(:persist?) ? technique.persist? : false
|
150
|
-
break
|
151
|
-
end
|
152
|
-
end
|
137
|
+
|
138
|
+
# Try and authenticate against the various auth techniques. If one
|
139
|
+
# technique works, then just exist and make the session active.
|
140
|
+
def authenticate!
|
141
|
+
Challah.techniques.values.each do |klass|
|
142
|
+
technique = klass.new(self)
|
143
|
+
technique.user_model = user_model if technique.respond_to?(:"user_model=")
|
144
|
+
|
145
|
+
@user = technique.authenticate
|
153
146
|
|
154
147
|
if @user
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
end
|
148
|
+
@persist = technique.respond_to?(:persist?) ? technique.persist? : false
|
149
|
+
break
|
150
|
+
end
|
151
|
+
end
|
160
152
|
|
161
|
-
|
153
|
+
if @user
|
154
|
+
# Only update user record if persistence is on for the technique.
|
155
|
+
# Otherwise this builds up quick (one session for each API call)
|
156
|
+
if @persist
|
157
|
+
@user.successful_authentication!(ip)
|
162
158
|
end
|
163
159
|
|
164
|
-
@valid =
|
160
|
+
return @valid = true
|
165
161
|
end
|
162
|
+
|
163
|
+
@valid = false
|
164
|
+
end
|
166
165
|
end
|
167
|
-
end
|
166
|
+
end
|
@@ -28,107 +28,108 @@ module Challah
|
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
31
|
-
def clear
|
32
|
-
cookies.delete(session_cookie_name, domain: domain)
|
33
|
-
cookies.delete(validation_cookie_name, domain: domain)
|
34
|
-
end
|
35
31
|
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
def clear
|
33
|
+
cookies.delete(session_cookie_name, domain: domain)
|
34
|
+
cookies.delete(validation_cookie_name, domain: domain)
|
35
|
+
end
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
def cookie_values
|
38
|
+
session_cookie && session_cookie.to_s.split(joiner)
|
39
|
+
end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
def cookies
|
42
|
+
request.cookie_jar
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
def default_cookie_prefix
|
46
|
+
Challah.options[:cookie_prefix]
|
47
|
+
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
def domain
|
50
|
+
request.session_options[:domain]
|
51
|
+
end
|
55
52
|
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
# Do the cookies exist, and are they valid?
|
54
|
+
def existing?
|
55
|
+
exists = false
|
59
56
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
57
|
+
if session_cookie and validation_cookie
|
58
|
+
session_tmp = session_cookie.to_s
|
59
|
+
validation_tmp = validation_cookie.to_s
|
64
60
|
|
65
|
-
|
61
|
+
if validation_tmp == validation_cookie_value(session_tmp)
|
62
|
+
exists = true
|
63
|
+
end
|
66
64
|
end
|
67
65
|
|
68
|
-
|
69
|
-
|
70
|
-
end
|
66
|
+
exists
|
67
|
+
end
|
71
68
|
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
def expiration
|
70
|
+
@expiration ||= 1.month.from_now
|
71
|
+
end
|
75
72
|
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
def joiner
|
74
|
+
'@'
|
75
|
+
end
|
79
76
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
77
|
+
def prefix
|
78
|
+
@prefix ||= [ default_cookie_prefix, user_model_id ].compact.join('-')
|
79
|
+
end
|
84
80
|
|
85
|
-
|
86
|
-
|
87
|
-
|
81
|
+
def request
|
82
|
+
raise "No Request Provided" unless @session and @session.request
|
83
|
+
@session.request
|
84
|
+
end
|
88
85
|
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
def session_cookie
|
87
|
+
cookies[session_cookie_name]
|
88
|
+
end
|
92
89
|
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
def session_cookie_name
|
91
|
+
"#{prefix}-s"
|
92
|
+
end
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
end
|
101
|
-
end
|
94
|
+
def session_cookie_value
|
95
|
+
"#@token#{joiner}#@user_id"
|
96
|
+
end
|
102
97
|
|
103
|
-
|
104
|
-
|
98
|
+
def user_model_id
|
99
|
+
if @session && @session.user_model && @session.user_model.table_name != 'users'
|
100
|
+
Encrypter.md5(@session.user_model.table_name).slice(0..5)
|
105
101
|
end
|
102
|
+
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
104
|
+
def validation_cookie
|
105
|
+
cookies[validation_cookie_name]
|
106
|
+
end
|
110
107
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
end
|
108
|
+
def validation_cookie_name
|
109
|
+
"#{prefix}-v"
|
110
|
+
end
|
115
111
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
112
|
+
def validation_cookie_value(value = nil)
|
113
|
+
value = session_cookie_value unless value
|
114
|
+
Encrypter.md5(value)
|
115
|
+
end
|
116
|
+
|
117
|
+
def write_cookies!
|
118
|
+
cookies[session_cookie_name] = {
|
119
|
+
value: session_cookie_value,
|
120
|
+
expires: expiration,
|
121
|
+
secure: false,
|
122
|
+
httponly: true,
|
123
|
+
domain: domain
|
124
|
+
}
|
125
|
+
|
126
|
+
cookies[validation_cookie_name] = {
|
127
|
+
value: validation_cookie_value,
|
128
|
+
expires: expiration,
|
129
|
+
secure: false,
|
130
|
+
httponly: true,
|
131
|
+
domain: domain
|
132
|
+
}
|
133
|
+
end
|
133
134
|
end
|
134
|
-
end
|
135
|
+
end
|
data/lib/challah/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: challah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Tornow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
142
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.0.
|
143
|
+
rubygems_version: 2.0.14
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: Rails 4 authentication and sessions
|