diff --git a/Gemfile.lock b/Gemfile.lock index e4b905ea..5c0f8a10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/assets/images/profile-1.png b/app/assets/images/profile-1.png new file mode 100644 index 00000000..bc020542 Binary files /dev/null and b/app/assets/images/profile-1.png differ diff --git a/app/assets/images/profile-2.png b/app/assets/images/profile-2.png new file mode 100644 index 00000000..b56112e2 Binary files /dev/null and b/app/assets/images/profile-2.png differ diff --git a/app/assets/images/profile-3.png b/app/assets/images/profile-3.png new file mode 100644 index 00000000..f2f65cc6 Binary files /dev/null and b/app/assets/images/profile-3.png differ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d0a8ca9e..f923858a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 29e9082a..d290c25a 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index de6be794..96956958 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/employee.rb b/app/models/employee.rb index 98b8380b..69eb3fae 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -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 diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 35eb6481..87bf3f50 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -1,7 +1,7 @@ - + +