Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 29 lines (20 sloc) 0.659 kb
cf8a67b Steve Klabnik Bye bye, octopress.
authored
1 require 'bcrypt'
2
3 DataMapper.setup(:default, ENV['DATABASE_URL'] || {:adapter => 'sqlite3', :database => 'db/development.sqlite3'})
4
5 class User
6 include DataMapper::Resource
7
8 property :id, Serial
9 property :email, String
10 property :encrypted_password, String
11
12 attr_accessor :password
13
14 before :create do |user|
15 user.encrypted_password = BCrypt::Password.create(user.password, :cost => 5)
16 end
17
18 def self.authenticate(email, password)
19 u = first(:email => email)
20 return nil if u.nil?
21 return nil unless u.encrypted_password = BCrypt::Password.create(password, :cost => 5)
22 u
23 end
24 end
25
26 DataMapper.finalize
27 DataMapper.auto_upgrade!
28
Something went wrong with that request. Please try again.