Merge branch 'foodcourt' of gitlab.com:code2lab/SXRestaurant into foodcourt

This commit is contained in:
yarzar_code
2020-01-14 15:15:27 +06:30
7 changed files with 71 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
class Settings::EmployeesController < ApplicationController
load_and_authorize_resource
before_action :set_employee, only: [:show, :edit, :update, :destroy]
before_action :set_employee, only: [:show, :edit, :update, :destroy, :change_auth_token]
# GET /employees
@@ -38,6 +38,13 @@ class Settings::EmployeesController < ApplicationController
format.html { render :new }
end
end
end
def change_auth_token
@employee.auth_token = SecureRandom.hex(10)
@employee.save
flash[:notice] = 'Auth Token was successfully updated.'
redirect_to settings_employee_url(@employee)
end
# PATCH/PUT /employees/1
@@ -71,6 +78,6 @@ class Settings::EmployeesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def employee_params
params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path)
params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path, :app_id, :auth_token)
end
end

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

View File

@@ -54,12 +54,24 @@
<th><%= t("views.right_panel.detail.employee_photo") %></th>
<td><%= image_tag @employee.image_path, :size => '200x200'%></td>
</tr>
<% if @employee.role == 'app' %>
<tr>
<th><%= t("views.right_panel.detail.employee_app_id") %></th>
<td><%= @employee.app_id %></td>
</tr>
<tr>
<th><%= t("views.right_panel.detail.employee_auth_token") %></th>
<td><%= @employee.auth_token %></td>
</tr>
<% end %>
<tr>
<th></th>
<td>
<%= link_to t("views.btn.edit"), edit_settings_employee_path(@employee),:class => 'btn btn-primary btn-lg waves-effect' %>
<% if @employee.role == 'app' %>
<%= link_to t("views.btn.change_auth_token"), settings_change_auth_token_url(id: @employee.id), class: 'btn btn-primary btn-lg waves-effect' %>
<% end %>
<%if @employee.role != "administrator"%>
<button class="delete btn btn-danger btn-sm waves-effect" data-ref="<%=settings_employee_path(@employee)%>" data-method="delete">
<%= t("views.btn.delete") %>
</button>