authpwn_rails 0.4.7 → 0.5.0
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/VERSION +1 -1
- data/authpwn_rails.gemspec +2 -2
- data/lib/authpwn_rails/session.rb +6 -6
- data/lib/authpwn_rails/user_model.rb +10 -0
- data/test/user_test.rb +11 -0
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/authpwn_rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{authpwn_rails}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Victor Costan"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-05}
|
13
13
|
s.description = %q{Works with Facebook.}
|
14
14
|
s.email = %q{victor@costan.us}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,7 +42,7 @@ module ControllerInstanceMethods
|
|
42
42
|
def current_user=(user)
|
43
43
|
@current_user = user
|
44
44
|
if user
|
45
|
-
session[:current_user_id] = user.
|
45
|
+
session[:current_user_id] = user.to_param
|
46
46
|
else
|
47
47
|
session.delete :current_user_id
|
48
48
|
end
|
@@ -50,8 +50,8 @@ module ControllerInstanceMethods
|
|
50
50
|
|
51
51
|
def authenticate_using_session
|
52
52
|
return true if current_user
|
53
|
-
|
54
|
-
user =
|
53
|
+
user_param = session[:current_user_id]
|
54
|
+
user = user_param && User.find_by_param(user_param)
|
55
55
|
self.current_user = user if user
|
56
56
|
end
|
57
57
|
private :authenticate_using_session
|
@@ -118,13 +118,13 @@ ActionController::Base.send :include, ControllerMixin
|
|
118
118
|
class ActionController::TestCase
|
119
119
|
# Sets the authenticated user in the test session.
|
120
120
|
def set_session_current_user(user)
|
121
|
-
request.session[:current_user_id] = user ? user.
|
121
|
+
request.session[:current_user_id] = user ? user.to_param : nil
|
122
122
|
end
|
123
123
|
|
124
124
|
# The authenticated user in the test session.
|
125
125
|
def session_current_user
|
126
|
-
return nil unless
|
127
|
-
User.
|
126
|
+
return nil unless user_param = request.session[:current_user_id]
|
127
|
+
User.find_by_param user_param
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
@@ -45,6 +45,11 @@ end # module AuthpwnRails::UserModel::ModelClassMethods
|
|
45
45
|
|
46
46
|
# Included in the metaclass of models that call pwnauth_user_model.
|
47
47
|
module ModelMetaclassMethods
|
48
|
+
# Queries by the values generated by to_param.
|
49
|
+
def find_by_param(param)
|
50
|
+
self.where(:email => param).first
|
51
|
+
end
|
52
|
+
|
48
53
|
# The authenticated user or nil.
|
49
54
|
def find_by_email_and_password(email, password)
|
50
55
|
@user = where(:email => email).first
|
@@ -96,6 +101,11 @@ module ModelInstanceMethods
|
|
96
101
|
self.password_salt = self.class.random_salt
|
97
102
|
self.password_hash = self.class.hash_password new_password, password_salt
|
98
103
|
end
|
104
|
+
|
105
|
+
# Use e-mails instead of exposing ActiveRecord IDs.
|
106
|
+
def to_param
|
107
|
+
email
|
108
|
+
end
|
99
109
|
end # module AuthpwnRails::UserModel::ModelInstanceMethods
|
100
110
|
|
101
111
|
ActiveRecord::Base.send :include, ModelMixin
|
data/test/user_test.rb
CHANGED
@@ -63,6 +63,10 @@ class UserTest < ActiveSupport::TestCase
|
|
63
63
|
assert !@user.valid?
|
64
64
|
end
|
65
65
|
|
66
|
+
test 'to_param' do
|
67
|
+
assert_equal @user.email, @user.to_param
|
68
|
+
end
|
69
|
+
|
66
70
|
test 'password_matches?' do
|
67
71
|
assert_equal true, @user.password_matches?('awesome')
|
68
72
|
assert_equal false, @user.password_matches?('not awesome'), 'Bogus password'
|
@@ -70,6 +74,13 @@ class UserTest < ActiveSupport::TestCase
|
|
70
74
|
"Another user's password"
|
71
75
|
end
|
72
76
|
|
77
|
+
test 'find_by_param' do
|
78
|
+
assert_equal users(:john), User.find_by_param(users(:john).to_param)
|
79
|
+
assert_equal users(:jane), User.find_by_param(users(:jane).to_param)
|
80
|
+
assert_equal nil, User.find_by_param('bogus email')
|
81
|
+
assert_equal nil, User.find_by_param(nil)
|
82
|
+
end
|
83
|
+
|
73
84
|
test 'find_by_email_and_password' do
|
74
85
|
assert_equal users(:john),
|
75
86
|
User.find_by_email_and_password('john@gmail.com', 'password')
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Victor Costan
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-05 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|