work off today
This commit is contained in:
+35
-1
@@ -23,9 +23,11 @@ class Employee
|
||||
property :unconfirmed_email
|
||||
|
||||
property :name
|
||||
property :authentication_token
|
||||
#property :email
|
||||
|
||||
has_many :employee_shifts, dependent: :destroy
|
||||
view :by_authentication_token, key: :authentication_token
|
||||
view :by_email, key: :email
|
||||
|
||||
class << self
|
||||
@@ -57,9 +59,41 @@ class Employee
|
||||
#settings.persist!
|
||||
#orig_save(*args)
|
||||
#end
|
||||
before_save { settings.persist! }
|
||||
before_save do
|
||||
ensure_authentication_token
|
||||
settings.persist!
|
||||
end
|
||||
|
||||
def settings
|
||||
@settings || SupplierEmployeesSettings.new(Supplier.new).for_employee(self)
|
||||
end
|
||||
|
||||
#####################################
|
||||
# Taken from devise 2.2
|
||||
#####################################
|
||||
|
||||
# Generate new authentication token (a.k.a. "single access token").
|
||||
def reset_authentication_token
|
||||
self.authentication_token = self.class.authentication_token
|
||||
end
|
||||
|
||||
# Generate new authentication token and save the record.
|
||||
def reset_authentication_token!
|
||||
reset_authentication_token
|
||||
save(:validate => false)
|
||||
end
|
||||
|
||||
# Generate authentication token unless already exists.
|
||||
def ensure_authentication_token
|
||||
reset_authentication_token if authentication_token.blank?
|
||||
end
|
||||
|
||||
# Generate authentication token unless already exists and save the record.
|
||||
def ensure_authentication_token!
|
||||
reset_authentication_token! if authentication_token.blank?
|
||||
end
|
||||
|
||||
def self.authentication_token
|
||||
SecureRandom.hex(24)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user