Class: DealRedemptions::User

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/deal_redemptions/user.rb

Constant Summary collapse

VALID_EMAIL_REGEX =
/\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



9
10
11
# File 'app/models/deal_redemptions/user.rb', line 9

def password
  @password
end

Class Method Details

.authenticate(email, password) ⇒ Object



16
17
18
19
20
21
22
23
# File 'app/models/deal_redemptions/user.rb', line 16

def self.authenticate(email, password)
  user = find_by_email(email)
  if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
    user
  else
    nil
  end
end

Instance Method Details

#encrypt_passwordObject



25
26
27
28
29
30
# File 'app/models/deal_redemptions/user.rb', line 25

def encrypt_password
  if password.present?
    self.password_salt = BCrypt::Engine.generate_salt
    self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
  end
end

#log_last_loginObject



32
33
34
# File 'app/models/deal_redemptions/user.rb', line 32

def 
  self. = Time.now
end

#send_confirmation_emailObject



36
37
38
# File 'app/models/deal_redemptions/user.rb', line 36

def send_confirmation_email
  DealRedemptions::AdminUserMailer.new_confirmation(self).deliver
end