Guest User

Untitled

a guest
Oct 27th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. class Users
  2. include DataMapper::Resource
  3.  
  4. property :id, Serial
  5. property :username, String, :required => true, :unique => true
  6. property :email, String, :required => true, :format => :email_address
  7. property :password, BCryptHash, :required => true
  8. property :created_at, DateTime
  9. property :updated_at, DateTime
  10.  
  11. def password
  12. @password ||= BCrypt::Password.new(self.password)
  13. end
  14.  
  15. def password=(password)
  16. @password = BCrypt::Password.create(password)
  17. self.password = @password
  18. end
  19.  
  20. def authenticates password
  21. self.password == password
  22. end
  23. end
  24.  
  25. # This hangs
  26. Users.create(:username => 'foo', :email => 'foo@wat.com', :password => 'lol')
  27.  
  28. # This does not
  29. Users.create(:username => 'foo', :email => 'foo@wat.com')
Add Comment
Please, Sign In to add comment