Class: Hancock::User
- Inherits:
-
Object
- Object
- Hancock::User
- Includes:
- DataMapper::Resource
- Defined in:
- lib/models/user.rb
Instance Attribute Summary collapse
-
#password ⇒ Object
Returns the value of attribute password.
-
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
Class Method Summary collapse
Instance Method Summary collapse
- #authenticated?(password) ⇒ Boolean
- #encrypt(password) ⇒ Object
- #encrypt_password ⇒ Object
- #password_required? ⇒ Boolean
- #reset_access_token ⇒ Object
Instance Attribute Details
#password ⇒ Object
Returns the value of attribute password.
16 17 18 |
# File 'lib/models/user.rb', line 16 def password @password end |
#password_confirmation ⇒ Object
Returns the value of attribute password_confirmation.
16 17 18 |
# File 'lib/models/user.rb', line 16 def password_confirmation @password_confirmation end |
Class Method Details
.authenticate(email, password) ⇒ Object
59 60 61 62 |
# File 'lib/models/user.rb', line 59 def self.authenticate(email, password) u = first(:email => email) u && u.authenticated?(password) && u.enabled ? u : nil end |
.encrypt(password, salt) ⇒ Object
46 47 48 |
# File 'lib/models/user.rb', line 46 def self.encrypt(password, salt) Digest::SHA1.hexdigest("--#{salt}--#{password}--") end |
.signup(params) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/models/user.rb', line 50 def self.signup(params) seed = Guid.new.to_s new(:email => params['email'], :first_name => params['first_name'], :last_name => params['last_name'], :password => Digest::SHA1.hexdigest(seed), :password_confirmation => Digest::SHA1.hexdigest(seed)) end |
Instance Method Details
#authenticated?(password) ⇒ Boolean
22 23 24 |
# File 'lib/models/user.rb', line 22 def authenticated?(password) crypted_password == encrypt(password) end |
#encrypt(password) ⇒ Object
26 27 28 |
# File 'lib/models/user.rb', line 26 def encrypt(password) self.class.encrypt(password, salt) end |
#encrypt_password ⇒ Object
34 35 36 37 38 |
# File 'lib/models/user.rb', line 34 def encrypt_password return if password.blank? @salt = Digest::SHA1.hexdigest("--#{Guid.new.to_s}}--email--") if new_record? @crypted_password = encrypt(password) end |
#password_required? ⇒ Boolean
30 31 32 |
# File 'lib/models/user.rb', line 30 def password_required? crypted_password.blank? || !password.blank? end |
#reset_access_token ⇒ Object
18 19 20 |
# File 'lib/models/user.rb', line 18 def reset_access_token @access_token = Digest::SHA1.hexdigest(Guid.new.to_s) end |