New Login form

This commit is contained in:
Min Zeya Phyo
2017-06-26 21:56:13 +06:30
parent 1f6a0eb1f6
commit b607154037
12 changed files with 154 additions and 19 deletions

View File

@@ -122,7 +122,6 @@ GEM
nokogiri (1.8.0)
mini_portile2 (~> 2.2.0)
pdf-core (0.7.0)
pg (0.21.0)
prawn (2.2.2)
pdf-core (~> 0.7.0)
ttfunk (~> 1.5)
@@ -261,7 +260,6 @@ DEPENDENCIES
kaminari (~> 1.0.1)
listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.5)
pg
prawn
prawn-table
puma (~> 3.0)

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -29,7 +29,9 @@ class ApplicationController < ActionController::Base
end
def current_login_employee
@employee = Employee.find_by_token_session(session[:session_token])
if (!session[:session_token].nil?)
@employee = Employee.find_by_token_session(session[:session_token])
end
end
private

View File

@@ -1,10 +1,30 @@
class HomeController < ApplicationController
skip_before_action :authenticate, only: [:index, :create, :destroy]
skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy]
def index
@employees = Employee.all.order("name asc")
@login_form = LoginForm.new()
end
def show
@login_form = LoginForm.new()
@login_form.emp_id = params[:emp_id]
end
def update
@login_form = LoginForm.new()
@login_form.emp_id = params[:emp_id]
@login_form.password = params[:login_form][:password]
@employee = Employee.login(@login_form.emp_id, @login_form.password)
if @employee != nil
session[:session_token] = @employee.token_session
redirect_to origami_root_path
else
render :show, flash[:notice] => "Invalid PIN for Employee. Please try again!"
end
end
def create
@login_form = LoginForm.new()
@login_form.emp_id = params[:login_form][:emp_id]
@@ -21,9 +41,9 @@ class HomeController < ApplicationController
else
render :index
end
else
else
redirect_to origami_root_path, :notice => "Username and Password dosn't match!"
end
end
end

View File

@@ -1,2 +1,11 @@
module ApplicationHelper
def flash_class(level)
case level
when :notice then "alert alert-info fade-in"
when :success then "alert alert-success fade-in"
when :error then "alert alert-error fade-in"
when :alert then "alert alert-error fade-in"
end
end
end

View File

@@ -13,9 +13,9 @@ class Employee < ApplicationRecord
def self.login(emp_id, password)
user = Employee.find_by_emp_id(emp_id)
if (user)
user.authenticate(password)
#user.authenticate(password)
if (user)
if (user.authenticate(password))
user.generate_token
user.session_expiry = DateTime.now.utc + 30.minutes
user.session_last_login = DateTime.now.utc

View File

@@ -1,7 +1,7 @@
<!--
<div class="row">
<div class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3">
<%= simple_form_for(@login_form, url: login_path, method: "POST") do |f| %>
<%= simple_form_for(@login_form, url: login_path, method: "POST") do |f| %>
<div class="card">
<h4 class="card-title text-center" style="margin:10px">Login</h4>
<div class="content" style="margin:10px">
@@ -22,4 +22,40 @@
<% end %>
</div>
</div> -->
<div class="row">
<div class="col-md-12 col-lg-12">
<div class="card-deck">
<% @employees.each do |employee| %>
<div data-formid="#form_<%= employee.emp_id %>" class="empBtn card card-inverse card-primary mb-3 text-center" style="width: 15rem;height:15rem;">
<form id="form_<%=employee.emp_id%>" action="<%= emp_login_path(employee.emp_id) %>" method="PATCH"></form>
<div class="card-block">
<h4 class="card-title">
<%= employee.name %>
</h4>
<div class="card-content">
(<%= employee.emp_id%>)
</div>
<div class="card-footer">
<small><%= employee.role %></small>
</div>
</div>
</div>
<% end %>
</div>
</div>
</div>
<script type="text/javascript">
$(document).on('turbolinks:load', function() {
$(".empBtn").click(function(event){
event.preventDefault();
console.log($(this).data("formid"));
var item = $(this).data("formid");
$(item).submit();
});
});
</script>

View File

@@ -0,0 +1,68 @@
<style>
.pin_pad {
width:10rem;
height:10rem;
text-align: center;
vertical-align: middle;
line-height: 10rem;
margin:2px;
margin-top:4px;
margin-bottom:4px;
font-size:3rem;
}
</style>
<div class="row">
<div class="col-md-4 col-sm-6 col-md-offset-4 col-sm-offset-3">
<%= simple_form_for(@login_form, url: emp_login_update_path, method: "PATCH") do |f| %>
<div class="card">
<div class="content" style="margin:10px">
<div class="form-group">
<%= f.input :emp_id,as: :hidden, label: "Access PIN", required: false, class: "form-control" %>
<%= f.input :password, label: "Access PIN", required: false, class: "form-control" %>
</div>
</div>
<div class="content" style="margin:10px; margin-top:0px; text-align:center">
<button class="pin_pad" data-value="1">1</button>
<button class="pin_pad" data-value="2">2</button>
<button class="pin_pad" data-value="3">3</button>
<button class="pin_pad" data-value="4">4</button>
<button class="pin_pad" data-value="5">5</button>
<button class="pin_pad" data-value="6">6</button>
<button class="pin_pad" data-value="7">7</button>
<button class="pin_pad" data-value="8">8</button>
<button class="pin_pad" data-value="9">9</button>
<button class="pin_pad" data-value="CLR">CLR</button>
<button class="pin_pad" data-value="8">0</button>
<button class="pin_pad btn-warning" data-value="ENT">ENT</button>
</div>
<div class="footer text-center" style="margin:10px">
</div>
</div>
<% end %>
</div>
</div>
<script type="text/javascript">
$(document).on('turbolinks:load', function() {
$(".pin_pad").click(function(event){
event.preventDefault();
console.log($(this).data("value"));
var value = $(this).data("value");
if (value == "CLR") {
$("#login_form_password").val("");
} else if(value == "ENT") {
$("#new_login_form").submit();
} else {
var old_value = $("#login_form_password").val();
$("#login_form_password").val(old_value + value);
}
});
});
</script>

View File

@@ -17,12 +17,11 @@
<body>
<%= render 'layouts/header' %>
<div class="container-fluid">
<% flash.each do |type, message| %>
<div class="alert fade-in">
<button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
<%= message %>
</div>
<% end %>
<% flash.each do |key, value| %>
<div class="<%= flash_class(key) %>">
<%= value %>
</div>
<% end %>
<%= yield %>
</div>

View File

@@ -2,9 +2,6 @@ require 'sidekiq/web'
Rails.application.routes.draw do
namespace :settings do
resources :membership_actions
end
root 'home#index'
mount Sidekiq::Web => '/kiq'
@@ -16,6 +13,9 @@ Rails.application.routes.draw do
post 'install' => 'install#create'
#--------- Login/Authentication ------------#
get 'emp_login/:emp_id' => 'home#show' , as: :emp_login
patch "emp_login/:emp_id" => 'home#update', as: :emp_login_update
post 'login' => 'home#create'
delete 'logout' => 'home#destroy'
get 'dashboard' => 'home#dashboard'
@@ -196,6 +196,8 @@ Rails.application.routes.draw do
resources :payment_method_settings
#membership_settings
resources :membership_settings
resources :membership_actions
#zones
resources :zones do
#tables
@@ -205,6 +207,7 @@ Rails.application.routes.draw do
end
end
#--------- Transactions Sections ------------#
namespace :transactions do
resources :sales