add new files

This commit is contained in:
Sunandar
2017-01-24 17:45:40 +06:30
parent 2f427ae5b9
commit 2893f33a23
138 changed files with 36367 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
class Api::AuthController < ApplicationController
skip_before_filter :verify_authenticity_token
def login
username = params[:username]
access = params[:access_code]
user = Member.find_by_email(username)
if user && user.valid_password?(access)
user.session_token = SecureRandom.hex
if user.save
@out=true,user.session_token
else
@out=false,"Error occurs in login process."
end
else
@out=false,"Sorry!Unauthorized user!"
end
end
def logout
login_token = params[:session_token]
@user = Member.find_by_session_token(login_token)
if !@user.nil?
@user.session_token = nil
if @user.save
return @user
end
end
end
end

View File

@@ -0,0 +1,57 @@
class Api::BatchLineItemsController < ApplicationController
skip_before_filter :verify_authenticity_token
def register
batch_id=params[:batch_id]
session_token=params[:session_token]
manufacture_uid = params[:manufacture_uid]
card_type = params[:card_type]
user_id=""
check_member= Member.authenticate_session_token(session_token)
if !check_member.nil?
encrypt_key=""
find_user=User.find_by_id(check_member.user_id)
if !find_user.nil?
encrypt_key=find_user.secrect_key
user_id=find_user.id
end
if !encrypt_key.nil?
str="manufacture_uid="+manufacture_uid.to_s+"&serial_no="+serial_no.to_s
digest_data= Digest::MD5.hexdigest(str)
hex_data=digest_data.hex
hex_str=hex_data.to_s
wristband_code=hex_str[0..15]
check_manufacture = BatchLineItem.find_by_manufacture_uid_and_wristband_code(manufacture_uid,wristband_code)
if check_manufacture.nil?
serial_no=BatchLineItem.generate_serial_no(user_id.to_s)
batchLineItem=BatchLineItem.new
batchLineItem.wristband_code=wristband_code
batchLineItem.serial_no=serial_no
batchLineItem.batch_id=batch_id
batchLineItem.manufacture_uid = manufacture_uid
batchLineItem.card_type = card_type
if batchLineItem.save
lookup=Lookup.find_by_name('generate_serial_no')
max_serail_no=lookup.max_value
lookup.max_value=max_serail_no.to_i+1
lookup.save
@out = true,batchLineItem.serial_no,batchLineItem.wristband_code
else
@out=false,'Error occurs in registration encoder!'
end
else
@out=false,'Wristband code is already exists!'
end
else
@out=false,'Invalid Encryption Key!'
end
else
@out=false,'Sorry!Unauthorized user!'
end
end
end

View File

@@ -0,0 +1,73 @@
class Api::BatchesController < ApplicationController
skip_before_filter :verify_authenticity_token
def create
session_token=params[:session_token]
check_member= Member.authenticate_session_token(session_token)
if !check_member.nil?
date = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
created_by = params[:created_by]
order_ref = params[:order_ref]
card_qty = params[:card_qty]
user_id=check_member.user_id
batch = Batch.create_batch(created_by,date,order_ref,card_qty,user_id)
if !batch.nil?
@out=true,batch.id
else
@out=false,'Error occurs in creating batch!'
end
else
@out = false, "Sorry!Unauthorized user!"
end
end
def batch_end
session_token=params[:session_token]
batch_id=params[:batch_id]
is_authorize= Member.authenticate_session_token(session_token)
if is_authorize
batch=Batch.find_by_id(batch_id)
if !batch.nil?
batch.batch_end_time = DateTime.now.beginning_of_day.utc.to_time.strftime("%Y-%m-%d")
batch.batch_end = true
if batch.save
@out=true,"Batch end process is successfully finished."
else
@out=false,'Error occurs in batch end process!'
end
else
@out=false,'Invalid batch no!'
end
else
@out = false, "Sorry!Unauthorized user!"
end
end
def resume_batch
session_token=params[:session_token]
batch_id=params[:batch_id]
is_authorize= Member.authenticate_session_token(session_token)
if is_authorize
batch=Batch.find_by_id(batch_id)
tickets=batch.tickets.count
@out=true,tickets
else
@out = false, "Sorry!Unauthorized user!"
end
end
def batch_progress_list
created_by=params[:created_by]
if !created_by.nil?
batches = Batch.where('batch_end is null and created_by=?', created_by)
puts batches
if !batches.blank?
@out=true,batches
else
@out = false, "No Batch"
end
else
@out = false, "Sorry!Unauthorized user!"
end
end
end

View File

@@ -0,0 +1,36 @@
class BatchLineItemsController < ApplicationController
require "csv"
skip_before_filter :verify_authenticity_token
before_action :authenticate_member!
def index
@batches=Batch.all
@batchLineItems=BatchLineItem.joins('inner join batches on batches.id=batch_line_items.batch_id').select('batch_line_items.*,batches.order_ref as batch_name').page(params[:page]).per(2)
end
def create
batch_list=params[:batch]
if ! batch_list.nil?
batch_list.each do |batch|
find_batch=Batch.find_by_id(batch)
if !find_batch.nil?
export_count=find_batch.export_count
find_batch.export_count=export_count.to_i+1
find_batch.save
end
end
@batchLineItems = BatchLineItem.where('batch_id in (?) ',batch_list).select('*')
else
user_id=current_member.user_id
batches=Batch.all
batches.each do |batch|
export_count=batch.export_count
batch.export_count=export_count.to_i+1
batch.save
end
@batchLineItems = BatchLineItem.all.select('serial_no,wristband_code,batch_id,manufacture_uid,card_type')
end
respond_to do |format|
format.html
format.csv { send_data @batchLineItems.to_csv(user_id), filename: "encoder-#{Date.today}.csv" }
end
end
end

View File

@@ -0,0 +1,5 @@
class BatchesController < ApplicationController
def index
@batches=Batch.all.page(params[:page]).per(2)
end
end

View File

@@ -0,0 +1,10 @@
class HomeController < ApplicationController
skip_before_filter :verify_authenticity_token
def index
redirect_to new_member_session_path
end
def dashboard
@users=User.all
end
end

View File

@@ -0,0 +1,98 @@
class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
# GET /users.json
def index
@users = User.all.page(params[:page])
end
# GET /users/1
# GET /users/1.json
def show
end
# GET /users/new
def new
@user = User.new
end
# GET /users/1/edit
def edit
end
# POST /users
# POST /users.json
def create
@user = User.new(user_params)
email=params[:registered_email]
@user.is_active=true
respond_to do |format|
if @user.save
member_id= current_member.id
member=Member.find_by_email(email)
if !member.nil?
member.user_id =@user.id
member.save
end
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url, notice: 'User was successfully destroyed.' }
format.json { head :no_content }
end
end
def check_registered_email
registered_email = params[:registered_email]
member =Member.find_by_email(registered_email)
if !member.nil?
if member.user_id.nil?
render json: {:status => 'true'}
else
user = User.find_by_id(member.user_id)
render json: {:status => 'false',:data => user}
end
else
render json: {:status => 'false',:data => nil}
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :nrc, :email, :phone, :address,:is_active,:secrect_key)
end
end