README.md in dm-is-authenticatable-0.1.1 vs README.md in dm-is-authenticatable-0.1.2
- old
+ new
@@ -20,15 +20,18 @@
class User
include DataMapper::Resource
is :authenticatable
+
+ property :id, Serial
# Name of the Licence
property :name, String
end
+ DataMapper.finalize
user = User.new(:name => 'bob')
user.password = 'secret'
# => "secret"
@@ -54,12 +57,37 @@
# => true
User.authenticate(:name => 'bob', :password => 'secret')
# => #<User: ...>
+Using dm-is-authenticatable with [Warden](http://github.com/hassox/warden#readme):
+
+ Warden::Manager.serialize_into_session { |user| user.id }
+ Warden::Manager.serialize_from_session { |id| User.get(id) }
+
+ Warden::Strategies.add(:password) do
+ def valid?
+ # must specify both name and password
+ params['name'] && params['password']
+ end
+
+ def authenticate!
+ attributes = {
+ :name => params['name'],
+ :password => params['password']
+ }
+
+ if (user = User.authenticate(attributes))
+ success! user
+ else
+ fail! 'Invalid user name or password'
+ end
+ end
+ end
+
## Requirements
-* [bcrypt-ruby](http://rubygems.org/gems/bcrypt-ruby) ~> 2.1
+* [bcrypt-ruby](http://rubygems.org/gems/bcrypt-ruby) ~> 3.0, >= 2.1.0
* [dm-core](http://github.com/datamapper/dm-core/) ~> 1.0
* [dm-types](http://github.com/datamapper/dm-types/) ~> 1.0
* [dm-validations](http://github.com/datamapper/dm-validations/) ~> 1.0
## Install