Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/access_log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ def person_name
rescue
"Pessoa Desconhecida"
end

def course_name
personable.course
rescue
"Visitante"
end
end
103 changes: 93 additions & 10 deletions app/views/access/identification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,115 @@
<h1>Validação de Acesso RU-Connect</h1>
<p class="mt-4"><small>Acesso administrativo: <%= link_to "Entrar", new_user_session_path %></small></p>

<p class="lead">Aproxime o QR Code ou insira o identificador.</p>
<p class="lead">Método de Identificação:</p>

<%= form_with url: identify_path, method: :post, local: true, data: { turbo: false } do |f| %>
<div class="form-group my-3">
<%= f.label :identifier, "Código de Identificação:" %>
<%= f.text_field :identifier, class: "form-control form-control-lg", autofocus: true %>
<div class="row my-4">
<div class="col-md-6 mx-auto">
<h3>Entrada Manual</h3>
<p>Digite o CPF ou Matrícula</p>

<%= form_with url: identify_path, method: :post, local: true, data: { turbo: false } do |f| %>
<div class="form-group my-3">
<%= f.label :identifier, "Identificador:" %>
<%= f.text_field :identifier, class: "form-control form-control-lg", autofocus: true %>
<%= f.submit "Validar Manualmente", class: "btn btn-primary btn-lg" %>
</div>
<% end %>
</div>

<div class="actions">
<%= f.submit "Validar", class: "btn btn-primary btn-lg" %>

<div class="col-md-12 my-4">
<hr>
<h3>OU</h3>
<hr>
</div>

<div class="col-md-6 mx-auto">
<h3>Leitura por Câmera</h3>

<button id="start-scanner-btn" class="btn btn-success btn-lg mb-3">
▶️ Start Scanning
</button>

<div id="reader" style="width:300px; margin: 0 auto; display: none;"></div>
</div>
<% end %>

</div>

<div class="my-5">
<% if notice %>
<div class="alert alert-success"><%= notice %></div>
<% end %>
<% if alert %>
<div class="alert alert-danger"><%= alert %></div>
<div><%= link_to "Cadastrar", new_student_path %></div>
<div><%= link_to "Cadastrar Novo Aluno", new_student_path %></div>
<% end %>
</div>
</div>

<hr class="my-5">

<script>
const feedbackElement = document.getElementById('scan-feedback');
const readerElement = document.getElementById('reader');
const startButton = document.getElementById('start-scanner-btn');

var html5QrcodeScanner = new Html5QrcodeScanner(
"reader", { fps: 10, qrbox: 250 }, false);

function onScanSuccess(decodedText, decodedResult) {
html5QrcodeScanner.pause(true);

if (readerElement) {
readerElement.style.display = 'none';
}
if (feedbackElement) {
feedbackElement.classList.remove('d-none');
}

console.log(`Enviando código lido: ${decodedText}`);

const form = document.createElement('form');
form.method = 'POST';
form.action = '<%= identify_path %>';

const identifierField = document.createElement('input');
identifierField.type = 'hidden';
identifierField.name = 'identifier';
identifierField.value = decodedText;
form.appendChild(identifierField);

const csrfToken = document.querySelector('meta[name="csrf-token"]').content;
const csrfField = document.createElement('input');
csrfField.type = 'hidden';
csrfField.name = 'authenticity_token';
csrfField.value = csrfToken;
form.appendChild(csrfField);

document.body.appendChild(form);
form.submit();
}

function startScanner() {
startButton.style.display = 'none';
readerElement.style.display = 'block';

html5QrcodeScanner.render(onScanSuccess, onScanFailure);
}

if (startButton) {
startButton.addEventListener('click', startScanner);
}

function onScanFailure(error) {
}

document.addEventListener('turbo:before-render', () => {
html5QrcodeScanner.clear().catch(error => {
console.warn("Falha ao desligar o leitor de QR Code:", error);
});
});
</script>

<h2>Últimos Acessos de Hoje</h2>

<% if @today_logs.present? %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/access_logs/_access_logs_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<th>Hora</th>
<th>Matrícula/CPF</th>
<th>Nome</th>
<th>Curso</th>
<th>Resultado</th>
<th>Ações</th>
</tr>
Expand All @@ -14,6 +15,7 @@
<td><%= l(log.created_at) %></td>
<td><%= log.identifier %></td>
<td><%= log.person_name %></td>
<td><%= log.course_name %></td>

<td>
<% if log.allowed? %>
Expand Down
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<%# Includes all stylesheet files in app/assets/stylesheets %>
<%= stylesheet_link_tag :app, "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
<script src="https://unpkg.com/html5-qrcode" type="text/javascript"></script>
</head>

<body>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
devise_for :users

root "access#identification"
get "identify", to: "access#identification"
get "identify", to: "access#identification", as: :identify
post "identify", to: "access#process_identification"
get "menu", to: "daily_menus#today", as: :public_menu

Expand Down