add app_id and auth_token to employee

This commit is contained in:
Zin Moe
2020-01-14 14:58:23 +06:30
parent 48e6afa505
commit c5eb5d6678
7 changed files with 71 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
class Employee < ApplicationRecord
has_secure_password
# has_secure_token :auth_token
has_many :commissioners
has_many :shit_sales
has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale"
@@ -11,6 +12,7 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
before_create :generate_app_id, :generate_auth_token #, if: Proc.new { self.role == "app" }
# Employee Image Uploader
mount_uploader :image_path, EmployeeImageUploader
@@ -89,4 +91,14 @@ class Employee < ApplicationRecord
return expiry_time
end
def generate_app_id
return if self.role != 'app'
self.app_id = SecureRandom.urlsafe_base64(nil, false)
end
def generate_auth_token
return if self.role != 'app'
self.auth_token = SecureRandom.hex(10)
end
end