authentication fixed

This commit is contained in:
Yan
2017-06-15 10:48:32 +06:30
parent 541907d204
commit e133595d49
4 changed files with 33 additions and 29 deletions

View File

@@ -10,16 +10,20 @@ class HomeController < ApplicationController
@login_form.emp_id = params[:login_form][:emp_id]
@login_form.password = params[:login_form][:password]
@employee = Employee.login(@login_form.emp_id, @login_form.password)
puts @employee.role
if @employee.role == "administrator"
session[:session_token] = @employee.token_session
redirect_to dashboard_path
elsif @employee.role == "cashier"
session[:session_token] = @employee.token_session
redirect_to origami_root_path
else
render :index
end
if @employee != nil
if @employee.role == "administrator"
session[:session_token] = @employee.token_session
redirect_to dashboard_path
elsif @employee.role == "cashier"
session[:session_token] = @employee.token_session
redirect_to origami_root_path
else
render :index
end
else
redirect_to origami_root_path, :notice => "Username and Password dosn't match!"
end
end

View File

@@ -1,25 +1,25 @@
<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| %>
<div class="card">
<h4 class="card-title text-center" style="margin:10px">Login</h4>
<div class="content" style="margin:10px">
<div class="form-group">
<%= f.input :emp_id, required: false, autofocus: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.input :password, required: false, class: "form-control" %>
</div>
<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| %>
<div class="card">
<h4 class="card-title text-center" style="margin:10px">Login</h4>
<div class="content" style="margin:10px">
<div class="form-group">
<%= f.input :emp_id, required: false, autofocus: true, class: "form-control" %>
</div>
<div class="footer text-center" style="margin:10px">
<%= f.button :submit, "Log in", class: "form-control btn btn-fill btn-warning btn-wd" %>
<div class="form-group">
<%= f.input :password, required: false, class: "form-control" %>
</div>
</div>
<div class="footer text-center" style="margin:10px">
<%= f.button :submit, "Log in", class: "form-control btn btn-fill btn-warning btn-wd" %>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
</div>

View File

@@ -18,7 +18,7 @@
<%= render 'layouts/header' %>
<div class="container-fluid">
<% flash.each do |type, message| %>
<div class="alert fade in">
<div class="alert fade-in">
<button class="close" aria-hidden="true" data-dismiss="alert" type="button">×</button>
<%= message %>
</div>

BIN
dump.rdb

Binary file not shown.