Class: Clerk

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

Constant Summary collapse

PEPPER =
"0bfa9e2cb4a5efd0d976518a3d82e345060547913d2fd1dd2f32b0c8dbbbb5d3dc20b86d0fed31aca9513bccdf51643700ea277d9c64d9ce8ef886bf39293453"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'app/models/clerk.rb', line 5

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



5
6
7
# File 'app/models/clerk.rb', line 5

def password_confirmation
  @password_confirmation
end

Instance Method Details

#last_addressObject



39
40
41
42
# File 'app/models/clerk.rb', line 39

def last_address
  order = orders.last 
  order ? order.address : {}
end

#ordersObject

just an ar association with order of the same email



35
36
37
# File 'app/models/clerk.rb', line 35

def orders
  Order.where(:email => self.email)
end

#valid_password?(password) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
# File 'app/models/clerk.rb', line 24

def valid_password?(password)
  return false if password.blank? 
  encrypted = encrypt_password(password)
  return false if self.encrypted_password.blank? || encrypted.bytesize != self.encrypted_password.bytesize
  left = encrypted.unpack "C#{encrypted.bytesize}"
  res = 0
  self.encrypted_password.each_byte { |byte| res |= byte ^ left.shift }
  res == 0
end

#whole_addressObject



20
21
22
# File 'app/models/clerk.rb', line 20

def whole_address
  [ name , street , city , phone ].join(" ")
end