authpwn_rails 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/{lib/authpwn_rails → app/models}/credentials/email.rb +3 -13
- data/{lib/authpwn_rails → app/models}/credentials/facebook.rb +10 -26
- data/{lib/authpwn_rails → app/models}/credentials/password.rb +6 -8
- data/authpwn_rails.gemspec +10 -6
- data/lib/authpwn_rails/generators/templates/003_create_credentials.rb +1 -1
- data/lib/authpwn_rails/generators/templates/user.rb +5 -0
- data/lib/authpwn_rails/user_extensions/email_field.rb +58 -0
- data/lib/authpwn_rails/user_extensions/password_field.rb +79 -0
- data/lib/authpwn_rails/user_model.rb +26 -0
- data/lib/authpwn_rails.rb +13 -4
- data/test/email_credential_test.rb +2 -14
- data/test/email_field_test.rb +57 -0
- data/test/facebook_credential_test.rb +4 -3
- data/test/helpers/autoload_path.rb +4 -0
- data/test/password_credential_test.rb +2 -7
- data/test/password_field_test.rb +41 -0
- data/test/test_helper.rb +1 -0
- data/test/user_test.rb +7 -0
- metadata +25 -21
- data/lib/authpwn_rails/credentials.rb +0 -16
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.10.
|
1
|
+
0.10.2
|
@@ -18,19 +18,9 @@ class Email < ::Credential
|
|
18
18
|
def set_verified_to_false
|
19
19
|
self.verified ||= '0' if self.key.nil?
|
20
20
|
end
|
21
|
+
|
22
|
+
# Forms can only change the e-mail in the credential.
|
23
|
+
attr_accessible :email
|
21
24
|
end # class Credentials::Email
|
22
25
|
|
23
26
|
end # namespace Credentials
|
24
|
-
|
25
|
-
# :nodoc: adds e-mail integration to the user model
|
26
|
-
module Authpwn::UserModel::InstanceMethods
|
27
|
-
def email_credential
|
28
|
-
credentials.find { |c| c.instance_of?(Credentials::Email) }
|
29
|
-
end
|
30
|
-
|
31
|
-
# The e-mail from the user's Email credential, or nil no credential exists.
|
32
|
-
def email
|
33
|
-
credential = self.email_credential
|
34
|
-
credential && credential.email
|
35
|
-
end
|
36
|
-
end # module Authpwn::UserModel::InstanceMethods
|
@@ -30,12 +30,16 @@ class Facebook < ::Credential
|
|
30
30
|
uid = uid_from_token access_token
|
31
31
|
credential = self.where(:name => uid.to_str).first
|
32
32
|
if credential
|
33
|
-
credential.
|
33
|
+
credential.key = access_token
|
34
|
+
credential.save!
|
34
35
|
else
|
35
36
|
User.transaction do
|
36
37
|
user = User.create!
|
37
|
-
credential = self.
|
38
|
-
|
38
|
+
credential = self.new
|
39
|
+
credential.facebook_uid = uid
|
40
|
+
credential.access_token = access_token
|
41
|
+
credential.user = user
|
42
|
+
credential.save!
|
39
43
|
end
|
40
44
|
end
|
41
45
|
credential
|
@@ -49,29 +53,9 @@ class Facebook < ::Credential
|
|
49
53
|
def self.uid_from_token(access_token)
|
50
54
|
FBGraphRails.fbclient(access_token).selection.me.info!.id.to_s
|
51
55
|
end
|
56
|
+
|
57
|
+
# Forms should not be able to touch any attribute.
|
58
|
+
attr_accessible
|
52
59
|
end # class Credentials::Facebook
|
53
60
|
|
54
61
|
end # namespace Credentials
|
55
|
-
|
56
|
-
# :nodoc: adds Facebook integration methods to the User model.
|
57
|
-
module Authpwn::UserModel::ClassMethods
|
58
|
-
# Fills out a new user's information based on a Facebook access token.
|
59
|
-
def create_with_facebook_token(token)
|
60
|
-
self.create! :email => "#{token.external_uid}@graph.facebook.com"
|
61
|
-
end
|
62
|
-
|
63
|
-
# The user that owns a given Facebook OAuth2 token.
|
64
|
-
#
|
65
|
-
# A new user will be created if the token doesn't belong to any user. This
|
66
|
-
# is the case for a new visitor.
|
67
|
-
def for_facebook_token(access_token)
|
68
|
-
Credentials::Facebook.for(access_token).user
|
69
|
-
end
|
70
|
-
end # module Authpwn::UserModel::ClassMethods
|
71
|
-
|
72
|
-
# :nodoc: adds Facebook integration methods to the User model.
|
73
|
-
module Authpwn::UserModel::InstanceMethods
|
74
|
-
def facebook_credential
|
75
|
-
credentials.find { |c| c.instance_of?(Credentials::Facebook) }
|
76
|
-
end
|
77
|
-
end # module Authpwn::UserModel::InstanceMethods
|
@@ -5,7 +5,8 @@ module Credentials
|
|
5
5
|
class Password < ::Credential
|
6
6
|
# Virtual attribute: the user's password.
|
7
7
|
attr_accessor :password
|
8
|
-
validates :password, :
|
8
|
+
validates :password, :presence => { :on => :create },
|
9
|
+
:confirmation => { :allow_nil => true }
|
9
10
|
|
10
11
|
# Virtual attribute: confirmation for the user's password.
|
11
12
|
attr_accessor :password_confirmation
|
@@ -51,13 +52,10 @@ class Password < ::Credential
|
|
51
52
|
# Generates a random salt value.
|
52
53
|
def self.random_salt
|
53
54
|
[(0...12).map { |i| 1 + rand(255) }.pack('C*')].pack('m').strip
|
54
|
-
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Forms can only change the plain-text password fields.
|
58
|
+
attr_accessible :password, :password_confirmation
|
55
59
|
end # class Credentials::Password
|
56
60
|
|
57
61
|
end # namespace Credentials
|
58
|
-
|
59
|
-
module Authpwn::UserModel::InstanceMethods
|
60
|
-
def password_credential
|
61
|
-
credentials.find { |c| c.instance_of?(Credentials::Password) }
|
62
|
-
end
|
63
|
-
end
|
data/authpwn_rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "authpwn_rails"
|
8
|
-
s.version = "0.10.
|
8
|
+
s.version = "0.10.2"
|
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 = "2011-11-
|
12
|
+
s.date = "2011-11-25"
|
13
13
|
s.description = "Works with Facebook."
|
14
14
|
s.email = "victor@costan.us"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -27,14 +27,13 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"app/helpers/session_helper.rb",
|
30
|
+
"app/models/credentials/email.rb",
|
31
|
+
"app/models/credentials/facebook.rb",
|
32
|
+
"app/models/credentials/password.rb",
|
30
33
|
"authpwn_rails.gemspec",
|
31
34
|
"legacy/migrate_09_to_010.rb",
|
32
35
|
"lib/authpwn_rails.rb",
|
33
36
|
"lib/authpwn_rails/credential_model.rb",
|
34
|
-
"lib/authpwn_rails/credentials.rb",
|
35
|
-
"lib/authpwn_rails/credentials/email.rb",
|
36
|
-
"lib/authpwn_rails/credentials/facebook.rb",
|
37
|
-
"lib/authpwn_rails/credentials/password.rb",
|
38
37
|
"lib/authpwn_rails/engine.rb",
|
39
38
|
"lib/authpwn_rails/facebook_session.rb",
|
40
39
|
"lib/authpwn_rails/generators/all_generator.rb",
|
@@ -53,17 +52,22 @@ Gem::Specification.new do |s|
|
|
53
52
|
"lib/authpwn_rails/session.rb",
|
54
53
|
"lib/authpwn_rails/session_controller.rb",
|
55
54
|
"lib/authpwn_rails/test_extensions.rb",
|
55
|
+
"lib/authpwn_rails/user_extensions/email_field.rb",
|
56
|
+
"lib/authpwn_rails/user_extensions/password_field.rb",
|
56
57
|
"lib/authpwn_rails/user_model.rb",
|
57
58
|
"test/cookie_controller_test.rb",
|
58
59
|
"test/email_credential_test.rb",
|
60
|
+
"test/email_field_test.rb",
|
59
61
|
"test/facebook_controller_test.rb",
|
60
62
|
"test/facebook_credential_test.rb",
|
61
63
|
"test/helpers/application_controller.rb",
|
64
|
+
"test/helpers/autoload_path.rb",
|
62
65
|
"test/helpers/db_setup.rb",
|
63
66
|
"test/helpers/fbgraph.rb",
|
64
67
|
"test/helpers/routes.rb",
|
65
68
|
"test/helpers/view_helpers.rb",
|
66
69
|
"test/password_credential_test.rb",
|
70
|
+
"test/password_field_test.rb",
|
67
71
|
"test/session_controller_api_test.rb",
|
68
72
|
"test/test_helper.rb",
|
69
73
|
"test/user_test.rb"
|
@@ -3,7 +3,7 @@ class CreateCredentials < ActiveRecord::Migration
|
|
3
3
|
create_table :credentials do |t|
|
4
4
|
t.references :user, :null => false
|
5
5
|
t.string :type, :limit => 32, :null => false
|
6
|
-
t.string :name, :limit =>
|
6
|
+
t.string :name, :limit => 128, :null => true
|
7
7
|
|
8
8
|
t.boolean :verified, :null => false, :default => false
|
9
9
|
|
@@ -2,5 +2,10 @@
|
|
2
2
|
class User < ActiveRecord::Base
|
3
3
|
include Authpwn::UserModel
|
4
4
|
|
5
|
+
# Virtual email attribute, with validation.
|
6
|
+
# include Authpwn::UserExtensions::EmailField
|
7
|
+
# Virtual password attribute, with confirmation validation.
|
8
|
+
# include Authpwn::UserExtensions::PasswordField
|
9
|
+
|
5
10
|
# Add your extensions to the User class here.
|
6
11
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
# :nodoc: namespace
|
5
|
+
module Authpwn
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module UserExtensions
|
9
|
+
|
10
|
+
# Augments the User model with an email virtual attribute.
|
11
|
+
module EmailField
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
validates :email, :format => /^[A-Za-z0-9.+_]+@[^@]*\.(\w+)$/,
|
16
|
+
:presence => true
|
17
|
+
attr_accessible :email
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# The user who has a certain e-mail, or nil if the e-mail is unclaimed.
|
22
|
+
def with_email(email)
|
23
|
+
credential = Credentials::Email.where(:name => email).includes(:user).first
|
24
|
+
credential && credential.user
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
# Credentials::Email instance associated with this user.
|
30
|
+
def email_credential
|
31
|
+
credentials.find { |c| c.instance_of?(Credentials::Email) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# The e-mail from the user's Email credential.
|
35
|
+
#
|
36
|
+
# Returns nil if this user has no Email credential.
|
37
|
+
def email
|
38
|
+
credential = self.email_credential
|
39
|
+
credential && credential.email
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets the e-mail on the user's Email credential.
|
43
|
+
#
|
44
|
+
# Creates a new Credentials::Email instance if necessary.
|
45
|
+
def email=(new_email)
|
46
|
+
if credential = self.email_credential
|
47
|
+
credential.email = new_email
|
48
|
+
else
|
49
|
+
credentials << Credentials::Email.new(:email => new_email)
|
50
|
+
end
|
51
|
+
new_email
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end # module Authpwn::UserExtensions::EmailField
|
55
|
+
|
56
|
+
end # module Authpwn::UserExtensions
|
57
|
+
|
58
|
+
end # module Authpwn
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
require 'active_support'
|
3
|
+
|
4
|
+
# :nodoc: namespace
|
5
|
+
module Authpwn
|
6
|
+
|
7
|
+
# :nodoc: namespace
|
8
|
+
module UserExtensions
|
9
|
+
|
10
|
+
# Augments the User model with a password virtual attribute.
|
11
|
+
module PasswordField
|
12
|
+
extend ActiveSupport::Concern
|
13
|
+
|
14
|
+
included do
|
15
|
+
validates :password, :presence => { :on => :create },
|
16
|
+
:confirmation => { :allow_nil => true }
|
17
|
+
attr_accessible :password, :password_confirmation
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
# The user who has a certain e-mail, or nil if the e-mail is unclaimed.
|
22
|
+
def with_email(email)
|
23
|
+
credential = Credentials::Email.where(:name => email).includes(:user).first
|
24
|
+
credential && credential.user
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
# Credentials::Password instance associated with this user.
|
30
|
+
def password_credential
|
31
|
+
credentials.find { |c| c.instance_of?(Credentials::Password) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# The password from the user's Password credential, or nil.
|
35
|
+
#
|
36
|
+
# Returns nil if this user has no Password credential.
|
37
|
+
def password
|
38
|
+
credential = self.password_credential
|
39
|
+
credential && credential.password
|
40
|
+
end
|
41
|
+
|
42
|
+
# The password_confirmation from the user's Password credential, or nil.
|
43
|
+
#
|
44
|
+
# Returns nil if this user has no Password credential.
|
45
|
+
def password_confirmation
|
46
|
+
credential = self.password_credential
|
47
|
+
credential && credential.password_confirmation
|
48
|
+
end
|
49
|
+
|
50
|
+
# Sets the password on the user's Password credential.
|
51
|
+
#
|
52
|
+
# Creates a new Credentials::Password instance if necessary.
|
53
|
+
def password=(new_password)
|
54
|
+
if credential = self.password_credential
|
55
|
+
credential.password = new_password
|
56
|
+
else
|
57
|
+
credentials << Credentials::Password.new(:password => new_password)
|
58
|
+
end
|
59
|
+
new_password
|
60
|
+
end
|
61
|
+
|
62
|
+
# Sets the password on the user's Password credential.
|
63
|
+
#
|
64
|
+
# Creates a new Credentials::Password instance if necessary.
|
65
|
+
def password_confirmation=(new_password_confirmation)
|
66
|
+
if credential = self.password_credential
|
67
|
+
credential.password_confirmation = new_password_confirmation
|
68
|
+
else
|
69
|
+
credentials << Credentials::Password.new(:password_confirmation =>
|
70
|
+
new_password_confirmation)
|
71
|
+
end
|
72
|
+
new_password_confirmation
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end # module Authpwn::UserExtensions::PasswordField
|
76
|
+
|
77
|
+
end # module Authpwn::UserExtensions
|
78
|
+
|
79
|
+
end # module Authpwn
|
@@ -19,8 +19,15 @@ module UserModel
|
|
19
19
|
|
20
20
|
# Credentials used to authenticate the user.
|
21
21
|
has_many :credentials, :dependent => :destroy, :inverse_of => :user
|
22
|
+
validates_associated :credentials
|
23
|
+
# This is safe, because credentials use attr_accessible.
|
24
|
+
accepts_nested_attributes_for :credentials, :allow_destroy => true
|
22
25
|
|
26
|
+
# Automatically assign exuid.
|
23
27
|
before_validation :set_default_exuid, :on => :create
|
28
|
+
|
29
|
+
# Forms should not be able to touch any attribute.
|
30
|
+
attr_accessible :credentials_attributes
|
24
31
|
end
|
25
32
|
|
26
33
|
# Class methods on models that include Authpwn::UserModel.
|
@@ -49,3 +56,22 @@ module UserModel
|
|
49
56
|
end # namespace Authpwn::UserModel
|
50
57
|
|
51
58
|
end # namespace Authpwn
|
59
|
+
|
60
|
+
|
61
|
+
# :nodoc: adds Facebook integration methods to the User model.
|
62
|
+
module Authpwn::UserModel::ClassMethods
|
63
|
+
# The user that owns a given Facebook OAuth2 token.
|
64
|
+
#
|
65
|
+
# A new user will be created if the token doesn't belong to any user. This
|
66
|
+
# is the case for a new visitor.
|
67
|
+
def for_facebook_token(access_token)
|
68
|
+
Credentials::Facebook.for(access_token).user
|
69
|
+
end
|
70
|
+
end # module Authpwn::UserModel::ClassMethods
|
71
|
+
|
72
|
+
# :nodoc: adds Facebook integration methods to the User model.
|
73
|
+
module Authpwn::UserModel::InstanceMethods
|
74
|
+
def facebook_credential
|
75
|
+
credentials.find { |c| c.instance_of?(Credentials::Facebook) }
|
76
|
+
end
|
77
|
+
end # module Authpwn::UserModel::InstanceMethods
|
data/lib/authpwn_rails.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
1
3
|
# :nodoc: namespace
|
2
4
|
module Authpwn
|
5
|
+
extend ActiveSupport::Autoload
|
6
|
+
|
7
|
+
autoload :CredentialModel, 'authpwn_rails/credential_model.rb'
|
8
|
+
autoload :SessionController, 'authpwn_rails/session_controller.rb'
|
9
|
+
autoload :UserModel, 'authpwn_rails/user_model.rb'
|
10
|
+
|
11
|
+
# Contains extensions to the User model.
|
12
|
+
module UserExtensions
|
13
|
+
autoload :EmailField, 'authpwn_rails/user_extensions/email_field.rb'
|
14
|
+
autoload :PasswordField, 'authpwn_rails/user_extensions/password_field.rb'
|
15
|
+
end
|
3
16
|
end
|
4
17
|
|
5
|
-
require 'authpwn_rails/credential_model.rb'
|
6
|
-
require 'authpwn_rails/credentials.rb'
|
7
18
|
require 'authpwn_rails/facebook_session.rb'
|
8
19
|
require 'authpwn_rails/session.rb'
|
9
|
-
require 'authpwn_rails/session_controller.rb'
|
10
20
|
require 'authpwn_rails/test_extensions.rb'
|
11
|
-
require 'authpwn_rails/user_model.rb'
|
12
21
|
|
13
22
|
if defined?(Rails)
|
14
23
|
require 'authpwn_rails/engine.rb'
|
@@ -2,8 +2,8 @@ require File.expand_path('../test_helper', __FILE__)
|
|
2
2
|
|
3
3
|
class EmailCredentialTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
|
-
@credential = Credentials::Email.new :email => 'dvdjohn@mit.edu'
|
6
|
-
|
5
|
+
@credential = Credentials::Email.new :email => 'dvdjohn@mit.edu'
|
6
|
+
@credential.user = users(:bill)
|
7
7
|
end
|
8
8
|
|
9
9
|
test 'setup' do
|
@@ -41,16 +41,4 @@ class EmailCredentialTest < ActiveSupport::TestCase
|
|
41
41
|
@credential.email = credentials(:john_email).email
|
42
42
|
assert !@credential.valid?
|
43
43
|
end
|
44
|
-
|
45
|
-
test 'User#email_credential' do
|
46
|
-
assert_equal credentials(:john_email), users(:john).email_credential
|
47
|
-
assert_equal credentials(:jane_email), users(:jane).email_credential
|
48
|
-
assert_nil users(:bill).email_credential
|
49
|
-
end
|
50
|
-
|
51
|
-
test 'User#email' do
|
52
|
-
assert_equal credentials(:john_email).email, users(:john).email
|
53
|
-
assert_equal credentials(:jane_email).email, users(:jane).email
|
54
|
-
assert_nil users(:bill).email
|
55
|
-
end
|
56
44
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class UserWithEmail < User
|
4
|
+
include Authpwn::UserExtensions::EmailField
|
5
|
+
end
|
6
|
+
|
7
|
+
class EmailFieldTest < ActiveSupport::TestCase
|
8
|
+
def setup
|
9
|
+
@user = UserWithEmail.new :email => 'blah@gmail.com'
|
10
|
+
|
11
|
+
@john = UserWithEmail.find_by_id(users(:john).id)
|
12
|
+
@jane = UserWithEmail.find_by_id(users(:jane).id)
|
13
|
+
@bill = UserWithEmail.find_by_id(users(:bill).id)
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'setup' do
|
17
|
+
@user.save!
|
18
|
+
assert @user.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'email presence' do
|
22
|
+
@user.email = nil
|
23
|
+
assert !@user.valid?
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'email_credential' do
|
27
|
+
assert_equal credentials(:john_email), @john.email_credential
|
28
|
+
assert_equal credentials(:jane_email), @jane.email_credential
|
29
|
+
assert_nil @bill.email_credential
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'email length' do
|
33
|
+
@user.email = 'abcde' * 25 + '@mit.edu'
|
34
|
+
assert !@user.valid?, 'Overly long email'
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'email format' do
|
38
|
+
['cos tan@gmail.com', 'costan@x@mit.edu'].each do |email|
|
39
|
+
@user.email = email
|
40
|
+
assert !@user.valid?, "Bad email format - #{email}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
test 'email' do
|
45
|
+
assert_equal credentials(:john_email).email, @john.email
|
46
|
+
assert_equal credentials(:jane_email).email, @jane.email
|
47
|
+
assert_nil @bill.email
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'with_email' do
|
51
|
+
assert_equal users(:john),
|
52
|
+
UserWithEmail.with_email(credentials(:john_email).email)
|
53
|
+
assert_equal users(:jane),
|
54
|
+
UserWithEmail.with_email(credentials(:jane_email).email)
|
55
|
+
assert_nil UserWithEmail.with_email('nosuch@email.com')
|
56
|
+
end
|
57
|
+
end
|
@@ -3,9 +3,10 @@ require File.expand_path('../test_helper', __FILE__)
|
|
3
3
|
class FacebookCredentialTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
@code = 'AAAEj8jKX2a8BAA4kNheRhOs6SlECVcZCE9o5pPKMytOjjoiNAoZBGZAwuL4KrrxXWesfJRhzDZCJiqrcQG3UdjRRNtyMJQMZD'
|
6
|
-
@credential = Credentials::Facebook.new
|
7
|
-
|
8
|
-
|
6
|
+
@credential = Credentials::Facebook.new
|
7
|
+
@credential.facebook_uid = '1181310542'
|
8
|
+
@credential.key = 'AAAEj8jKX2a8BAOBMZCjxBe4dw7cRoD1JVxUgZAtB6ozJlR4Viazh6OAYcHB5kZAtUwgjpDy7a54ZA1DObLmBT9X99CLWYOj5Stqx8bHwnE7EzyBS1WxY'
|
9
|
+
@credential.user = users(:bill)
|
9
10
|
end
|
10
11
|
|
11
12
|
test 'setup' do
|
@@ -3,7 +3,8 @@ require File.expand_path('../test_helper', __FILE__)
|
|
3
3
|
class PasswordCredentialTest < ActiveSupport::TestCase
|
4
4
|
def setup
|
5
5
|
@credential = Credentials::Password.new :password => 'awesome',
|
6
|
-
|
6
|
+
:password_confirmation => 'awesome'
|
7
|
+
@credential.user = users(:bill)
|
7
8
|
end
|
8
9
|
|
9
10
|
test 'setup' do
|
@@ -58,10 +59,4 @@ class PasswordCredentialTest < ActiveSupport::TestCase
|
|
58
59
|
Credentials::Password.authenticate_email('john@gmail.com', 'awesome'),
|
59
60
|
'Bogus password'
|
60
61
|
end
|
61
|
-
|
62
|
-
test 'User#password_credential' do
|
63
|
-
assert_equal credentials(:john_password), users(:john).password_credential
|
64
|
-
assert_equal credentials(:jane_password), users(:jane).password_credential
|
65
|
-
assert_nil users(:bill).password_credential
|
66
|
-
end
|
67
62
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class UserWithPassword < User
|
4
|
+
include Authpwn::UserExtensions::PasswordField
|
5
|
+
end
|
6
|
+
|
7
|
+
class PasswordFieldTest < ActiveSupport::TestCase
|
8
|
+
def setup
|
9
|
+
@user = UserWithPassword.new :password => 'awesome',
|
10
|
+
:password_confirmation => 'awesome'
|
11
|
+
|
12
|
+
@john = UserWithPassword.find_by_id(users(:john).id)
|
13
|
+
@jane = UserWithPassword.find_by_id(users(:jane).id)
|
14
|
+
@bill = UserWithPassword.find_by_id(users(:bill).id)
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'setup' do
|
18
|
+
assert @user.valid?
|
19
|
+
end
|
20
|
+
|
21
|
+
test 'password required' do
|
22
|
+
@user.password = @user.password_confirmation = nil
|
23
|
+
assert !@user.valid?
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'password assumed ok for existing records' do
|
27
|
+
@john.save!
|
28
|
+
assert @john.valid?
|
29
|
+
end
|
30
|
+
|
31
|
+
test 'password confirmation' do
|
32
|
+
@user.password_confirmation = 'not awesome'
|
33
|
+
assert !@user.valid?
|
34
|
+
end
|
35
|
+
|
36
|
+
test 'password_credential' do
|
37
|
+
assert_equal credentials(:john_password), @john.password_credential
|
38
|
+
assert_equal credentials(:jane_password), @jane.password_credential
|
39
|
+
assert_nil @bill.password_credential
|
40
|
+
end
|
41
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -15,6 +15,7 @@ require 'authpwn_rails'
|
|
15
15
|
require 'helpers/view_helpers.rb'
|
16
16
|
# NOTE: application_controller has to follow view_helpers
|
17
17
|
require 'helpers/application_controller.rb'
|
18
|
+
require 'helpers/autoload_path.rb'
|
18
19
|
require 'helpers/db_setup.rb'
|
19
20
|
require 'helpers/fbgraph.rb'
|
20
21
|
require 'helpers/routes.rb'
|
data/test/user_test.rb
CHANGED
@@ -34,4 +34,11 @@ class UserTest < ActiveSupport::TestCase
|
|
34
34
|
assert_equal nil, User.find_by_param('bogus id')
|
35
35
|
assert_equal nil, User.find_by_param(nil)
|
36
36
|
end
|
37
|
+
|
38
|
+
test 'nested attributes' do
|
39
|
+
@user = User.new :credentials_attributes => { 0 =>
|
40
|
+
{:name => 'test@email.com', :type => 'Credentials::Password'}}
|
41
|
+
assert_equal 1, @user.credentials.length
|
42
|
+
assert_equal 'test@email.com', @user.credentials.first.name
|
43
|
+
end
|
37
44
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authpwn_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fbgraph_rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &17655420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.2.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *17655420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &17653940 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.1.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *17653940
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &17652840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *17652840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: flexmock
|
49
|
-
requirement: &
|
49
|
+
requirement: &17599820 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 0.9.0
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *17599820
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: jeweler
|
60
|
-
requirement: &
|
60
|
+
requirement: &17598940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.6.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *17598940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rcov
|
71
|
-
requirement: &
|
71
|
+
requirement: &17598120 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *17598120
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: sqlite3
|
82
|
-
requirement: &
|
82
|
+
requirement: &17597180 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: 1.3.3
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *17597180
|
91
91
|
description: Works with Facebook.
|
92
92
|
email: victor@costan.us
|
93
93
|
executables: []
|
@@ -106,14 +106,13 @@ files:
|
|
106
106
|
- Rakefile
|
107
107
|
- VERSION
|
108
108
|
- app/helpers/session_helper.rb
|
109
|
+
- app/models/credentials/email.rb
|
110
|
+
- app/models/credentials/facebook.rb
|
111
|
+
- app/models/credentials/password.rb
|
109
112
|
- authpwn_rails.gemspec
|
110
113
|
- legacy/migrate_09_to_010.rb
|
111
114
|
- lib/authpwn_rails.rb
|
112
115
|
- lib/authpwn_rails/credential_model.rb
|
113
|
-
- lib/authpwn_rails/credentials.rb
|
114
|
-
- lib/authpwn_rails/credentials/email.rb
|
115
|
-
- lib/authpwn_rails/credentials/facebook.rb
|
116
|
-
- lib/authpwn_rails/credentials/password.rb
|
117
116
|
- lib/authpwn_rails/engine.rb
|
118
117
|
- lib/authpwn_rails/facebook_session.rb
|
119
118
|
- lib/authpwn_rails/generators/all_generator.rb
|
@@ -132,17 +131,22 @@ files:
|
|
132
131
|
- lib/authpwn_rails/session.rb
|
133
132
|
- lib/authpwn_rails/session_controller.rb
|
134
133
|
- lib/authpwn_rails/test_extensions.rb
|
134
|
+
- lib/authpwn_rails/user_extensions/email_field.rb
|
135
|
+
- lib/authpwn_rails/user_extensions/password_field.rb
|
135
136
|
- lib/authpwn_rails/user_model.rb
|
136
137
|
- test/cookie_controller_test.rb
|
137
138
|
- test/email_credential_test.rb
|
139
|
+
- test/email_field_test.rb
|
138
140
|
- test/facebook_controller_test.rb
|
139
141
|
- test/facebook_credential_test.rb
|
140
142
|
- test/helpers/application_controller.rb
|
143
|
+
- test/helpers/autoload_path.rb
|
141
144
|
- test/helpers/db_setup.rb
|
142
145
|
- test/helpers/fbgraph.rb
|
143
146
|
- test/helpers/routes.rb
|
144
147
|
- test/helpers/view_helpers.rb
|
145
148
|
- test/password_credential_test.rb
|
149
|
+
- test/password_field_test.rb
|
146
150
|
- test/session_controller_api_test.rb
|
147
151
|
- test/test_helper.rb
|
148
152
|
- test/user_test.rb
|
@@ -161,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
165
|
version: '0'
|
162
166
|
segments:
|
163
167
|
- 0
|
164
|
-
hash:
|
168
|
+
hash: -3179900965882251985
|
165
169
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
170
|
none: false
|
167
171
|
requirements:
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# Loads sub-classes of the Credential model.
|
2
|
-
#
|
3
|
-
# We allow the Credential model to be defined in the Rails application, so the
|
4
|
-
# application can choose the storage model (ActiveRecord vs Mongoid etc.). This
|
5
|
-
# means that we have to load the classes that inherit from Credential after it's
|
6
|
-
# defined, which is long after the authpwn_rails engine is loaded.
|
7
|
-
|
8
|
-
require 'active_support'
|
9
|
-
|
10
|
-
module Credentials
|
11
|
-
extend ActiveSupport::Autoload
|
12
|
-
|
13
|
-
autoload :Email, 'authpwn_rails/credentials/email.rb'
|
14
|
-
autoload :Facebook, 'authpwn_rails/credentials/facebook.rb'
|
15
|
-
autoload :Password, 'authpwn_rails/credentials/password.rb'
|
16
|
-
end
|