add app_id and auth_token to employee
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
class Settings::EmployeesController < ApplicationController
|
class Settings::EmployeesController < ApplicationController
|
||||||
load_and_authorize_resource
|
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
|
# GET /employees
|
||||||
@@ -38,6 +38,13 @@ class Settings::EmployeesController < ApplicationController
|
|||||||
format.html { render :new }
|
format.html { render :new }
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
# PATCH/PUT /employees/1
|
# 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.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def employee_params
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class Employee < ApplicationRecord
|
class Employee < ApplicationRecord
|
||||||
has_secure_password
|
has_secure_password
|
||||||
|
# has_secure_token :auth_token
|
||||||
has_many :commissioners
|
has_many :commissioners
|
||||||
has_many :shit_sales
|
has_many :shit_sales
|
||||||
has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale"
|
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 :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
|
||||||
validates :password, numericality: true, length: {in: 3..9}, 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
|
# Employee Image Uploader
|
||||||
mount_uploader :image_path, EmployeeImageUploader
|
mount_uploader :image_path, EmployeeImageUploader
|
||||||
|
|
||||||
@@ -89,4 +91,14 @@ class Employee < ApplicationRecord
|
|||||||
|
|
||||||
return expiry_time
|
return expiry_time
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -54,12 +54,24 @@
|
|||||||
<th><%= t("views.right_panel.detail.employee_photo") %></th>
|
<th><%= t("views.right_panel.detail.employee_photo") %></th>
|
||||||
<td><%= image_tag @employee.image_path, :size => '200x200'%></td>
|
<td><%= image_tag @employee.image_path, :size => '200x200'%></td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
<td>
|
<td>
|
||||||
<%= link_to t("views.btn.edit"), edit_settings_employee_path(@employee),:class => 'btn btn-primary btn-lg waves-effect' %>
|
<%= 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"%>
|
<%if @employee.role != "administrator"%>
|
||||||
|
|
||||||
<button class="delete btn btn-danger btn-sm waves-effect" data-ref="<%=settings_employee_path(@employee)%>" data-method="delete">
|
<button class="delete btn btn-danger btn-sm waves-effect" data-ref="<%=settings_employee_path(@employee)%>" data-method="delete">
|
||||||
<%= t("views.btn.delete") %>
|
<%= t("views.btn.delete") %>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -4,28 +4,28 @@ class ActionController::Base
|
|||||||
private
|
private
|
||||||
|
|
||||||
def lookup_domain
|
def lookup_domain
|
||||||
if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud"
|
# if request.subdomains.last && request.subdomains.last != "www" && ENV["SERVER_CODE"] = "cloud"
|
||||||
from = request.host
|
# from = request.host
|
||||||
@license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
|
# @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase
|
||||||
if (!@license.nil?)
|
# if (!@license.nil?)
|
||||||
logger.info "Location - " + @license.dbschema
|
# logger.info "Location - " + @license.dbschema
|
||||||
ActiveRecord::Base.establish_connection(website_connection(@license))
|
# ActiveRecord::Base.establish_connection(website_connection(@license))
|
||||||
# authenticate_session_token
|
# # authenticate_session_token
|
||||||
# logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
# # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema
|
||||||
else
|
# else
|
||||||
# reconnect_default_db
|
# # reconnect_default_db
|
||||||
logger.info 'License is nil'
|
# logger.info 'License is nil'
|
||||||
# redirect_to root_url(:host => request.domain) + "store_error"
|
# # redirect_to root_url(:host => request.domain) + "store_error"
|
||||||
render :json => [{ status: false, message: 'Invalid Access!'}]
|
# render :json => [{ status: false, message: 'Invalid Access!'}]
|
||||||
end
|
# end
|
||||||
else
|
# else
|
||||||
# check for license file
|
# # check for license file
|
||||||
if check_license
|
# if check_license
|
||||||
current_license(ENV["SX_PROVISION_URL"])
|
# current_license(ENV["SX_PROVISION_URL"])
|
||||||
else
|
# else
|
||||||
redirect_to activate_path
|
# redirect_to activate_path
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ en:
|
|||||||
del: "DEL"
|
del: "DEL"
|
||||||
clr: "CLR"
|
clr: "CLR"
|
||||||
assign: "ASSIGN"
|
assign: "ASSIGN"
|
||||||
|
change_auth_token: "Change Auth Token"
|
||||||
|
|
||||||
print_order_summary: "Print Order Summary"
|
print_order_summary: "Print Order Summary"
|
||||||
memeber_card: "Member Card"
|
memeber_card: "Member Card"
|
||||||
@@ -678,6 +679,8 @@ en:
|
|||||||
edit_btn_txt: "to edit "
|
edit_btn_txt: "to edit "
|
||||||
delete_btn_txt: "to delete "
|
delete_btn_txt: "to delete "
|
||||||
update_btn_txt: "to update "
|
update_btn_txt: "to update "
|
||||||
|
employee_app_id: "App ID"
|
||||||
|
employee_auth_token: "Auth Token"
|
||||||
|
|
||||||
helpers:
|
helpers:
|
||||||
page_entries_info:
|
page_entries_info:
|
||||||
|
|||||||
@@ -432,7 +432,9 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
resources :display_images
|
resources :display_images
|
||||||
end
|
end
|
||||||
#employees
|
#employees
|
||||||
resources :employees
|
resources :employees
|
||||||
|
get '/:id/change_auth_token' => 'employees#change_auth_token', as: 'change_auth_token'
|
||||||
|
|
||||||
#menu
|
#menu
|
||||||
resources :menus do
|
resources :menus do
|
||||||
collection do
|
collection do
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user