Class: Sinatra::Rider::User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sinatra::Rider::User
- Defined in:
- lib/sinatra/rider/user.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.authenticate(username, pass) ⇒ Object
14 15 16 17 |
# File 'lib/sinatra/rider/user.rb', line 14 def self.authenticate(username, pass) user = where(username: username).first user if user && user.valid_password?(pass) end |
.signup(attrs) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/sinatra/rider/user.rb', line 6 def self.signup(attrs) where(username: attrs[:username]).first_or_initialize.tap do |u| u.name = attrs[:name] u.password = attrs[:password] u.save! end end |
Instance Method Details
#password ⇒ Object
19 20 21 |
# File 'lib/sinatra/rider/user.rb', line 19 def password encrypted_password end |
#password=(pass) ⇒ Object
23 24 25 |
# File 'lib/sinatra/rider/user.rb', line 23 def password=(pass) self.encrypted_password = Digest::SHA1.hexdigest(pass) end |
#valid_password?(pass) ⇒ Boolean
27 28 29 |
# File 'lib/sinatra/rider/user.rb', line 27 def valid_password?(pass) encrypted_password == Digest::SHA1.hexdigest(pass) end |