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>

View File

@@ -4,28 +4,28 @@ class ActionController::Base
private
def lookup_domain
if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud"
from = request.host
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
if (!@license.nil?)
logger.info "Location - " + @license.dbschema
ActiveRecord::Base.establish_connection(website_connection(@license))
# authenticate_session_token
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
else
# reconnect_default_db
logger.info 'License is nil'
# redirect_to root_url(:host => request.domain) + "store_error"
render :json => [{ status: false, message: 'Invalid Access!'}]
end
else
# check for license file
if check_license
current_license(ENV["SX_PROVISION_URL"])
else
redirect_to activate_path
end
end
# if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud"
# from = request.host
# @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
# if (!@license.nil?)
# logger.info "Location - " + @license.dbschema
# ActiveRecord::Base.establish_connection(website_connection(@license))
# # authenticate_session_token
# # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
# else
# # reconnect_default_db
# logger.info 'License is nil'
# # redirect_to root_url(:host => request.domain) + "store_error"
# render :json => [{ status: false, message: 'Invalid Access!'}]
# end
# else
# # check for license file
# if check_license
# current_license(ENV["SX_PROVISION_URL"])
# else
# redirect_to activate_path
# end
# end
end

View File

@@ -112,6 +112,7 @@ en:
del: "DEL"
clr: "CLR"
assign: "ASSIGN"
change_auth_token: "Change Auth Token"
print_order_summary: "Print Order Summary"
memeber_card: "Member Card"
@@ -678,6 +679,8 @@ en:
edit_btn_txt: "to edit "
delete_btn_txt: "to delete "
update_btn_txt: "to update "
employee_app_id: "App ID"
employee_auth_token: "Auth Token"
helpers:
page_entries_info:

View File

@@ -432,7 +432,9 @@ scope "(:locale)", locale: /en|mm/ do
resources :display_images
end
#employees
resources :employees
resources :employees
get '/:id/change_auth_token' => 'employees#change_auth_token', as: 'change_auth_token'
#menu
resources :menus do
collection do

View File

@@ -0,0 +1,9 @@
class AddAppIdAndAuthTokenToEmployees < ActiveRecord::Migration[5.1]
def change
add_column :employees, :app_id, :string, unique: true
add_column :employees, :auth_token, :string, unique: true
add_index :employees, :app_id
add_index :employees, :auth_token
end
end