dm-is-authenticatable 0.2.0 → 0.3.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/ChangeLog.md +6 -0
- data/Gemfile +2 -2
- data/LICENSE.txt +1 -1
- data/README.md +10 -5
- data/Rakefile +1 -0
- data/dm-is-authenticatable.gemspec +38 -105
- data/gemspec.yml +1 -1
- data/lib/dm-is-authenticatable/is/authenticatable.rb +15 -1
- data/spec/integration/authenticatable_spec.rb +34 -2
- metadata +4 -5
data/ChangeLog.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 0.3.0 / 2013-04-22
|
2
|
+
|
3
|
+
* If `encrypted_password` is `nil`, have
|
4
|
+
{DataMapper::Is::Authenticatable::InstanceMethods#has_password?} only accept
|
5
|
+
`nil` or `""`.
|
6
|
+
|
1
7
|
### 0.2.0 / 2012-10-06
|
2
8
|
|
3
9
|
* Added {DataMapper::Is::Authenticatable::InstanceMethods#password_required?}.
|
data/Gemfile
CHANGED
@@ -80,7 +80,7 @@
|
|
80
80
|
# Gemfile.lock is added to the .gitignore file, so you don't need to worry
|
81
81
|
# about accidentally checking it into version control.
|
82
82
|
|
83
|
-
source
|
83
|
+
source 'https://rubygems.org'
|
84
84
|
|
85
85
|
DATAMAPPER = 'http://github.com/datamapper'
|
86
86
|
DM_VERSION = '~> 1.0'
|
@@ -95,7 +95,7 @@ gem 'dm-types', DM_VERSION, :git => "#{DATAMAPPER}/dm-types.git"
|
|
95
95
|
gem 'dm-validations', DM_VERSION, :git => "#{DATAMAPPER}/dm-validations.git"
|
96
96
|
|
97
97
|
group :development do
|
98
|
-
gem 'rake', '~> 0
|
98
|
+
gem 'rake', '~> 10.0'
|
99
99
|
gem 'rubygems-tasks', '~> 0.1'
|
100
100
|
gem 'rspec', '~> 2.4'
|
101
101
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -85,10 +85,10 @@ Using dm-is-authenticatable with [warden]:
|
|
85
85
|
|
86
86
|
## Requirements
|
87
87
|
|
88
|
-
* [bcrypt-ruby]
|
89
|
-
* [dm-core]
|
90
|
-
* [dm-types]
|
91
|
-
* [dm-validations]
|
88
|
+
* [bcrypt-ruby] ~> 3.0, >= 2.1.0
|
89
|
+
* [dm-core] ~> 1.0
|
90
|
+
* [dm-types] ~> 1.0
|
91
|
+
* [dm-validations] ~> 1.0
|
92
92
|
|
93
93
|
## Install
|
94
94
|
|
@@ -96,10 +96,15 @@ Using dm-is-authenticatable with [warden]:
|
|
96
96
|
|
97
97
|
## License
|
98
98
|
|
99
|
-
Copyright (c) 2010-
|
99
|
+
Copyright (c) 2010-2013 Hal Brodigan
|
100
100
|
|
101
101
|
See {file:LICENSE.txt} for license information.
|
102
102
|
|
103
103
|
[warden]: https://github.com/hassox/warden#readme
|
104
104
|
[sinatra_warden]: https://github.com/jsmestad/sinatra_warden#readme
|
105
105
|
[padrino-warden]: https://github.com/jondot/padrino-warden#readme
|
106
|
+
|
107
|
+
[bcrypt-ruby]: https://github.com/codahale/bcrypt-ruby#readme
|
108
|
+
[dm-core]: https://github.com/datamapper/dm-core#readme
|
109
|
+
[dm-types]: https://github.com/datamapper/dm-types#readme
|
110
|
+
[dm-validations]: https://github.com/datamapper/dm-validations#readme
|
data/Rakefile
CHANGED
@@ -2,126 +2,59 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
`git ls-files`.split($/)
|
8
|
-
elsif File.directory?('.hg')
|
9
|
-
`hg manifest`.split($/)
|
10
|
-
elsif File.directory?('.svn')
|
11
|
-
`svn ls -R`.split($/).select { |path| File.file?(path) }
|
12
|
-
else
|
13
|
-
Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
14
|
-
end
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
when String
|
21
|
-
(files & Dir[paths])
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
version = {
|
26
|
-
:file => 'lib/dm-is-authenticatable/version.rb',
|
27
|
-
:constant => 'DataMapper::Is::Authenticatable::VERSION'
|
28
|
-
}
|
29
|
-
|
30
|
-
defaults = {
|
31
|
-
'name' => File.basename(File.dirname(__FILE__)),
|
32
|
-
'files' => files,
|
33
|
-
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
34
|
-
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
35
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
36
|
-
}
|
37
|
-
|
38
|
-
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
39
|
-
|
40
|
-
gemspec.name = metadata.fetch('name',defaults[:name])
|
41
|
-
gemspec.version = if metadata['version']
|
42
|
-
metadata['version']
|
43
|
-
elsif File.file?(version[:file])
|
44
|
-
require File.join('.',version[:file])
|
45
|
-
eval(version[:constant])
|
46
|
-
end
|
47
|
-
|
48
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
49
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
50
|
-
|
51
|
-
case metadata['license']
|
52
|
-
when Array
|
53
|
-
gemspec.licenses = metadata['license']
|
54
|
-
when String
|
55
|
-
gemspec.license = metadata['license']
|
56
|
-
end
|
57
|
-
|
58
|
-
case metadata['authors']
|
59
|
-
when Array
|
60
|
-
gemspec.authors = metadata['authors']
|
61
|
-
when String
|
62
|
-
gemspec.author = metadata['authors']
|
63
|
-
end
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
64
12
|
|
65
|
-
|
66
|
-
|
13
|
+
require 'dm-is-authenticatable/is/authenticatable/version'
|
14
|
+
DataMapper::Is::Authenticatable::VERSION
|
15
|
+
end
|
67
16
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
74
23
|
|
75
|
-
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
76
25
|
|
77
|
-
|
78
|
-
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
79
28
|
|
80
|
-
|
81
|
-
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
82
31
|
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
83
33
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
gemspec.extra_rdoc_files = metadata['extra_doc_files']
|
88
|
-
end
|
89
|
-
|
90
|
-
gemspec.post_install_message = metadata['post_install_message']
|
91
|
-
gemspec.requirements = metadata['requirements']
|
92
|
-
|
93
|
-
if gemspec.respond_to?(:required_ruby_version=)
|
94
|
-
gemspec.required_ruby_version = metadata['required_ruby_version']
|
95
|
-
end
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
96
37
|
|
97
|
-
|
98
|
-
|
99
|
-
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
100
41
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
when String
|
106
|
-
versions.split(/,\s*/)
|
107
|
-
end
|
108
|
-
}
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
109
46
|
|
110
|
-
|
111
|
-
metadata['dependencies'].each do |name,versions|
|
112
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
113
|
-
end
|
114
|
-
end
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
115
48
|
|
116
|
-
if
|
117
|
-
|
118
|
-
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
119
52
|
end
|
120
53
|
end
|
121
54
|
|
122
|
-
if
|
123
|
-
|
124
|
-
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
125
58
|
end
|
126
59
|
end
|
127
60
|
end
|
data/gemspec.yml
CHANGED
@@ -4,6 +4,10 @@ require 'dm-validations'
|
|
4
4
|
module DataMapper
|
5
5
|
module Is
|
6
6
|
module Authenticatable
|
7
|
+
#
|
8
|
+
# Adds the `encrypted_password property` and mixs in {ClassMethods}
|
9
|
+
# and {InstanceMethods}.
|
10
|
+
#
|
7
11
|
def is_authenticatable(options={})
|
8
12
|
# The encrypted password
|
9
13
|
property :encrypted_password, DataMapper::Property::BCryptHash
|
@@ -14,6 +18,9 @@ module DataMapper
|
|
14
18
|
validates_confirmation_of :password
|
15
19
|
end
|
16
20
|
|
21
|
+
#
|
22
|
+
# Class methods.
|
23
|
+
#
|
17
24
|
module ClassMethods
|
18
25
|
#
|
19
26
|
# Finds and authenticates a resource.
|
@@ -38,6 +45,9 @@ module DataMapper
|
|
38
45
|
end
|
39
46
|
end
|
40
47
|
|
48
|
+
#
|
49
|
+
# Instance methods.
|
50
|
+
#
|
41
51
|
module InstanceMethods
|
42
52
|
# The clear-text password
|
43
53
|
attr_reader :password
|
@@ -83,7 +93,11 @@ module DataMapper
|
|
83
93
|
# @since 0.2.0
|
84
94
|
#
|
85
95
|
def has_password?(submitted_password)
|
86
|
-
|
96
|
+
if password_required?
|
97
|
+
self.encrypted_password == submitted_password
|
98
|
+
else
|
99
|
+
submitted_password.nil? || submitted_password.empty?
|
100
|
+
end
|
87
101
|
end
|
88
102
|
end
|
89
103
|
end
|
@@ -72,8 +72,16 @@ describe DataMapper::Is::Authenticatable do
|
|
72
72
|
context "when #password_required? is false" do
|
73
73
|
before { subject.stub(:password_required?).and_return(false) }
|
74
74
|
|
75
|
-
it "should return true" do
|
76
|
-
subject.should have_password(
|
75
|
+
it "should return true for nil" do
|
76
|
+
subject.should have_password(nil)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should return true for ''" do
|
80
|
+
subject.should have_password('')
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should return false for any other String" do
|
84
|
+
subject.should_not have_password('foo')
|
77
85
|
end
|
78
86
|
end
|
79
87
|
end
|
@@ -117,5 +125,29 @@ describe DataMapper::Is::Authenticatable do
|
|
117
125
|
|
118
126
|
user.should be_nil
|
119
127
|
end
|
128
|
+
|
129
|
+
context "when encrypted password is nil" do
|
130
|
+
before(:all) do
|
131
|
+
User.first(:name => name).update(:encrypted_password => nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should allow authenticating with a nil password" do
|
135
|
+
user = subject.authenticate(:name => name, :password => nil)
|
136
|
+
|
137
|
+
user.name.should == name
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should allow authenticating with an empty password" do
|
141
|
+
user = subject.authenticate(:name => name, :password => '')
|
142
|
+
|
143
|
+
user.name.should == name
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should not allow authenticating with any other password" do
|
147
|
+
user = subject.authenticate(:name => name, :password => 'foo')
|
148
|
+
|
149
|
+
user.should be_nil
|
150
|
+
end
|
151
|
+
end
|
120
152
|
end
|
121
153
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-is-authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bcrypt-ruby
|
@@ -159,9 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
version: '0'
|
160
160
|
requirements: []
|
161
161
|
rubyforge_project:
|
162
|
-
rubygems_version: 1.8.
|
162
|
+
rubygems_version: 1.8.25
|
163
163
|
signing_key:
|
164
164
|
specification_version: 3
|
165
165
|
summary: DataMapper plugin for adding authentication to models.
|
166
|
-
test_files:
|
167
|
-
- spec/integration/authenticatable_spec.rb
|
166
|
+
test_files: []
|