Merge branch 'master' of git.wmi.amu.edu.pl:s452108/atcheck

This commit is contained in:
s416422 2019-12-16 15:49:44 +01:00
commit bb3af844ca
18 changed files with 46 additions and 5720 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
use App\Attendance; use App\Attendance;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Controllers\UserCache;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Subject; use App\Subject;
@ -11,6 +12,7 @@ use App\Classes;
use App\Room; use App\Room;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
class UserClassesController extends Controller class UserClassesController extends Controller
{ {
@ -68,6 +70,25 @@ class UserClassesController extends Controller
$classes->save(); $classes->save();
$classes->refresh(); $classes->refresh();
} }
$userCache = new UserCache();
$cache = $userCache->get($classes_code);
if($cache) {
$student_id_number = $cache->index;
$student_name = $cache->name;
$student_surname = $cache->surname;
$classes = DB::table("classes")->where("classes_code", $cache->classcode)->first();
$attendances = Attendance::where('classes_id', $classes->id)->get();
$seat_numbers = $attendances->pluck('seat_number')->toArray();
$subject = Subject::find($classes->subject_id);
$room_arrangement = Room::find($subject->room_id)->arrangement;
if(!$room_arrangement) {
$room_arrangement = Room::where('name', 'Inna sala')->first()->arrangement;
}
$userCache->delete($cache->classcode);
return view('map.seat_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'seat_numbers' => $seat_numbers, 'room_arrangement' => $room_arrangement]);
}
return view('map.start_map', ['classes_code' => $classes_code, 'classes' => $classes]); return view('map.start_map', ['classes_code' => $classes_code, 'classes' => $classes]);
} }

View File

@ -11,9 +11,7 @@ use App\Room;
class UserSubjectsController extends Controller class UserSubjectsController extends Controller
{ {
public function index($groupBy='weekday') public function index($groupBy = 'weekday') {
{
setlocale(LC_ALL, 'pl', 'pl_PL', 'pl_PL.ISO8859-2', 'plk', 'polish', 'Polish'); setlocale(LC_ALL, 'pl', 'pl_PL', 'pl_PL.ISO8859-2', 'plk', 'polish', 'Polish');
$user_id = Auth::id(); $user_id = Auth::id();
$subjects = Subject::where('user_id', $user_id)->get(); $subjects = Subject::where('user_id', $user_id)->get();
@ -25,14 +23,12 @@ class UserSubjectsController extends Controller
if(date('w')-1 < 0 ) { if(date('w')-1 < 0 ) {
$defaultWeekday = $weekdays[6]; $defaultWeekday = $weekdays[6];
} else { } else {
$defaultWeekday = $weekdays[date('w')-1]; $defaultWeekday = "Poniedziałek";//$weekdays[date('w') - 1];
} }
return view('user.user_subjects', ['subjects' => $subjects, 'weekdays' => $weekdays, return view('user.user_subjects', ['subjects' => $subjects, 'weekdays' => $weekdays, 'subjects_grouped' => $subjects_grouped, 'grouped_by' => $groupBy, 'defaultTime' => $defaultTime, 'defaultWeekday' => $defaultWeekday, 'rooms' => $rooms]);
'subjects_grouped' => $subjects_grouped, 'grouped_by' => $groupBy, 'defaultTime' => $defaultTime, 'defaultWeekday' => $defaultWeekday, 'rooms' => $rooms]);
} }
public function add_subject(Request $request) public function add_subject(Request $request) {
{
$name = $request->input('name'); $name = $request->input('name');
// $type = $request->input('type'); // $type = $request->input('type');
$weekday = $request->input('weekday'); $weekday = $request->input('weekday');

View File

@ -20,6 +20,8 @@ class VerifyCsrfToken extends Middleware
*/ */
protected $except = [ protected $except = [
'user/classes/start', 'user/classes/start',
'user/classes/save' 'user/classes/save',
'add/cache',
'delete/cache'
]; ];
} }

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -1,55 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Add classes</title>
</head>
<body>
<div class="container">
<form>
<div>
<h5 class="center">Enter class data</h3>
<br /> Professor:
<input type="text" id="professor" required autofocus/>
<br /> Class name:
<input type="text" id="name" required autofocus/>
<br /> Date:
<input type="datetime-local" id="date" class="c-datepicker-input" required autofocus/>
</div>
<br />
<button class="btn waves-effect waves-light" type="submit">Add</button>
</form>
</div>
<script>
const electron = require('electron');
const {
ipcRenderer
} = electron;
const form = document.querySelector("form");
form.addEventListener("submit", submitForm);
function submitForm(e) {
e.preventDefault();
var name = document.querySelector("#name").value;
var professor = document.querySelector("#professor").value;
var date = document.querySelector("#date").value;
var item = [name, professor, date];
ipcRenderer.send("item:add_class", item);
}
</script>
</body>
</html>

View File

@ -1,42 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Add student</title>
</head>
<body>
<div class="container">
<form>
<div>
<h5 class="center">Enter student data</h3> <br />
Name: <input type="text" id="name" required autofocus/> <br />
Surname: <input type="text" id="surname" required autofocus/> <br />
Index: <input type="text" id="index" required autofocus/> <br />
</div>
<br />
<button class="btn waves-effect waves-light" type="submit">Add</button>
</form>
</div>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const form = document.querySelector("form");
form.addEventListener("submit",submitForm);
function submitForm(e){
e.preventDefault();
var name = document.querySelector("#name").value;
var surname = document.querySelector("#surname").value;
var index = document.querySelector("#index").value;
const item = [name,surname,index];
ipcRenderer.send("item:add",item);
}
</script>
</body>
</html>

View File

@ -1,57 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Student counter</title>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">Student counter</a>
</div>
</nav>
<ul>
</ul>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const ul = document.querySelector("ul");
ipcRenderer.on("item:add",function(e,item) {
console.log(item);
ul.className = "collection";
const li = document.createElement('li');
li.className = "collection-item";
var date = item[3] ? item[3] : Date.now();
const itemText = document.createTextNode(item[0] + " " + item[1] + " " + item[2] + " " + date);
li.appendChild(itemText);
li.id = item[2];
ul.appendChild(li);
});
ul.addEventListener('dblclick',removeItem);
function removeItem(item) {
ipcRenderer.send("item:delete",item.target.id);
item.target.remove();
if (ul.children.length == 0) {
ul.className = "";
}
}
</script>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1,365 +0,0 @@
//Get required packages
const electron = require('electron');
const path = require('path');
const url = require('url');
const fs = require('fs');
const asn1js = require('asn1js');
const util = require('util');
const notifier = require('node-notifier');
const smartcard = require('smartcard');
const {
app,
BrowserWindow,
Menu,
ipcMain
} = electron;
const Devices = smartcard.Devices;
const devices = new Devices();
const Iso7816Application = smartcard.Iso7816Application;
let mainWindow;
let AddWindow;
let AddClassesWindow;
let SelectClassesWindow;
var current_classes = -1;
//Listen for the app to be ready
app.on('ready', function () {
//Create new window
mainWindow = new BrowserWindow({
width: 500,
height: 600,
webPreferences: {
nodeIntegration: true
}});
//Load html into window
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
}));
//Quit app when closed
mainWindow.on("closed", function () {
app.quit();
})
//Menu from template
const mainMenu = Menu.buildFromTemplate(mainMenuTemplate);
Menu.setApplicationMenu(mainMenu);
});
devices.on('device-activated', event => {
console.log('Smart card reader active');
const currentDevices = event.devices;
let device = event.device;
device.on('error', function (message) {
console.log(`Error '${message}' received`);
});
device.on('card-inserted', event => {
let card = event.card;
//console.log(`Card '${card.getAtr()}' inserted into '${event.device}'` + '\n');
const application = new Iso7816Application(card);
application.selectFile([0xD6, 0x16, 0x00, 0x00, 0x30, 0x01, 0x01])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
application.issueCommand([0x00, 0xA4, 0x02, 0x00, 0x02, 0x00, 0x02, 0x12])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
application.issueCommand([0x00, 0xB0, 0x00, 0x00, 0xF8])
.then(response => {
console.info(`Response: '${response}' '${response.meaning()}'`);
var response2 = `${response}`;
var start = response2.indexOf("2a8468016504010101") + 18;
response2 = response2.substring(start);
while (1) {
var type = response2.substring(0, 2);
if (type == "30") break;
if (parseInt(response2.substring(2, 4), 16) > 127) {
var count = parseInt(response2.substring(2, 4), 16) - 128;
var length = "";
var k = 1;
for (k = 1; k <= count; k++) {
length += response2.substring(2 + (k * 2), 4 + (k * 2));
}
var total_length = parseInt(length, 16) * 2;
response2 = response2.substr(4 + (k - 1) * 2, total_length);
} else {
var total_length = parseInt(response2.substring(2, 4), 16) * 2 + 4;
response2 = response2.substr(4, total_length);
}
}
//region How to work with ASN.1 strings
let bmp_string_encoded = new ArrayBuffer(response2.length / 2);
let bmp_string_view = new Uint8Array(bmp_string_encoded);
var kk = 0;
for (var i = 0; i < (response2.length / 2); i++) {
bmp_string_view[i] = "0x" + response2.substring(kk, kk + 2);
kk += 2;
}
let bmp_string_decoded = asn1js.fromBER(bmp_string_encoded);
if (bmp_string_decoded.offset === (-1)) return; // Error during decoding
let obj = bmp_string_decoded.result.valueBlock.value;
var names = obj[4].valueBlock.value[0].valueBlock.value;
var surnames = obj[3].valueBlock.value[0].valueBlock.value;
var index = obj[5].valueBlock.value;
var output = [names, surnames, index];
printStudent(output);
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
}).catch(error => {
//console.error('Error:', error, error.stack + '\n');
});
});
device.on('card-removed', event => {
console.log(`Card removed from '${event.name}' ` + '\n');
});
});
devices.on('device-deactivated', event => {
console.log(`Device '${event.device}' deactivated, devices: [${event.devices}]` + '\n');
});
//Add student manually
function createAddWindow() {
//Create new window
AddWindow = new BrowserWindow({
width: 300,
height: 400,
title: "Add student manually"
});
//Load html into window
AddWindow.loadURL(url.format({
pathname: path.join(__dirname, "addstudent.html"),
protocol: "file:",
slashes: true
}));
//Garbage
AddWindow.on("close", function () {
AddWindow = null;
});
}
function createAddClassesWindow() {
//Create new window
AddClassesWindow = new BrowserWindow({
width: 350,
height: 500,
title: "Add classes"
});
//Load html into window
AddClassesWindow.loadURL(url.format({
pathname: path.join(__dirname, "addclasses.html"),
protocol: "file:",
slashes: true
}));
//Garbage
AddClassesWindow.on("close", function () {
AddClassesWindow = null;
});
}
function createSelectClassesWindow() {
//Create new window
SelectClassesWindow = new BrowserWindow({
width: 500,
height: 475,
title: "Add classes"
});
//Load html into window
SelectClassesWindow.loadURL(url.format({
pathname: path.join(__dirname, "selectclasses.html"),
protocol: "file:",
slashes: true
}));
//Garbage
SelectClassesWindow.on("close", function () {
SelectClassesWindow = null;
});
}
function printStudent(item) {
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('d-m-Y H:M:S');
item.push(formatted);
mainWindow.webContents.send("item:add", item);
notifier.notify({
title: "Student registered",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'ok.png')
});
/*
if (false) { //current_classes == -1
notifier.notify({
title: "No current classes selected",
message: "Adding student unsuccessful",
icon: path.join(__dirname, 'wrong.png')
});
} else {
if (true) {
var dateTime = require('node-datetime');
var dt = dateTime.create();
var formatted = dt.format('d-m-Y H:M:S');
item.push(formatted);
console.log(item);
mainWindow.webContents.send("item:add", item);
notifier.notify({
title: "Student registered",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'ok.png')
});
} else {
notifier.notify({
title: "Student already exists",
message: item[0] + " " + item[1],
icon: path.join(__dirname, 'wrong.png')
});
}
}*/
}
//Catch
ipcMain.on("item:add", function (e, item) {
printStudent(item);
AddWindow.close();
})
//Menu template
const mainMenuTemplate = [{
label: "Student",
submenu: [{
label: "Add student",
accelerator: process.platfrom == "darwin" ? "Command+E" : "Ctrl+E",
click() {
createAddWindow();
}
},
{
label: "Quit program",
accelerator: process.platfrom == "darwin" ? "Command+Q" : "Ctrl+Q",
click() {
app.quit();
}
}
]
}, {
label: "Classes",
submenu: [{
label: "Add classes",
click() {
createAddClassesWindow();
}
},
{
label: "Pick classes",
click() {
createSelectClassesWindow();
}
}
]
}];
//If mac psuh empty obj to Menu
if (process.platfrom == "darwin") {
mainMenuTemplate.unshift({});
}
//Add dev tools on DEV
if (process.env.NODE_ENV !== 'production') {
mainMenuTemplate.push({
label: "DEV",
submenu: [{
label: "Toggle dev tools",
accelerator: process.platfrom == "darwin" ? "Command+I" : "Ctrl+I",
click(item, focusedWindow) {
focusedWindow.toggleDevTools();
}
},
{
role: "reload"
}
]
});
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

File diff suppressed because it is too large Load Diff

View File

@ -1,25 +0,0 @@
{
"name": "atcheck",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "electron ."
},
"author": "Me",
"license": "ISC",
"devDependencies": {
"electron": "^7.1.2",
"electron-rebuild": "^1.8.8"
},
"dependencies": {
"asn1js": "^2.0.26",
"fs": "0.0.1-security",
"node-datetime": "^2.1.2",
"node-notifier": "^6.0.0",
"npm": "^6.13.1",
"pcsclite": "^1.0.0",
"smartcard": "^1.0.32"
}
}

View File

@ -1,49 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0-beta/css/materialize.min.css">
<meta charset="UTF-8">
<title>Student counter</title>
</head>
<body>
<nav>
<div class="nav-wrapper">
<a class="brand-logo center">Select classes</a>
</div>
</nav>
<ul>
</ul>
<script>
const electron = require('electron');
const {ipcRenderer} = electron;
const ul = document.querySelector("ul");
ipcRenderer.send("item:start");
ipcRenderer.on("item:add_select_classes",function(e,item) {
ul.className = "collection";
const li = document.createElement('li');
li.className = "collection-item";
li.id = item[3];
li.style.cursor = "pointer";
const itemText = document.createTextNode(item[0] + " " + item[1] + " " + item[2]);
li.appendChild(itemText);
ul.appendChild(li);
});
ul.addEventListener('click',selectItem);
function selectItem(item) {
ipcRenderer.send("item:select",item.target.id);
}
</script>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

View File

@ -10,8 +10,8 @@
<title>@CHECK | @yield('title')</title> <title>@CHECK | @yield('title')</title>
<!-- Scripts --> <!-- Scripts -->
<script src="{{ secure_asset('js/app.js') }}" defer></script> <script src="{{ asset('js/app.js') }}" defer></script>
<script src="{{ secure_asset('js/custom.js') }}" defer></script> <script src="{{ asset('js/custom.js') }}" defer></script>
<!-- Fonts --> <!-- Fonts -->
@ -19,8 +19,8 @@
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
<!-- Styles --> <!-- Styles -->
<link href="{{ secure_asset('css/app.css') }}" rel="stylesheet"> <link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link rel="shortcut icon" href="{{ secure_asset('img/favicon.png') }}"> <link rel="shortcut icon" href="{{ asset('img/favicon.png') }}">
@yield('main_meta') @yield('main_meta')
</head> </head>

View File

@ -30,4 +30,12 @@
<button type="submit" class="checkout-button"> Dodaj studenta </button> <button type="submit" class="checkout-button"> Dodaj studenta </button>
</form> </form>
</div> </div>
<script>
// Your application has indicated there's an error
window.setTimeout(function(){
// Move to a new location or you can do something else
window.location.href = window.location.href;
}, 3000);
</script>
@endsection @endsection

View File

@ -16,11 +16,4 @@ use Illuminate\Http\Request;
Route::middleware('auth:api')->get('/user', function (Request $request) { Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user(); return $request->user();
}); });
Route::post('/card_details', function (Request $request) {
$name = $request->input('name');
$surname = $request->input('surname');
$id_number = $request->input('id_number');
return array('name' => $name, 'surname' => $surname, 'id_number' => $id_number );
});

View File

@ -17,6 +17,10 @@ Route::get('/', function () {
Auth::routes(); Auth::routes();
Route::get('/home', 'HomeController@index')->name('home'); Route::get('/home', 'HomeController@index')->name('home');
Route::post('/add/cache', 'UserCache@add');
Route::post('/delete/cache', 'UserCache@delete');
Route::group(array('prefix' => 'admin', 'namespace' => 'Admin'), function() Route::group(array('prefix' => 'admin', 'namespace' => 'Admin'), function()
{ {
Route::get('/', 'AdminPanelController@index')->name('admin'); Route::get('/', 'AdminPanelController@index')->name('admin');
@ -49,7 +53,6 @@ Route::group(array('prefix' => 'admin', 'namespace' => 'Admin'), function()
Route::get('/attendance/{attendance_id}', 'AdminAttendancesController@edit_attendance')->name('admin_edit_attendance'); Route::get('/attendance/{attendance_id}', 'AdminAttendancesController@edit_attendance')->name('admin_edit_attendance');
}); });
}); });
Route::group(array('prefix' => 'user', 'namespace' => 'User'), function() { //TODO poprawic {user_id} Route::group(array('prefix' => 'user', 'namespace' => 'User'), function() { //TODO poprawic {user_id}
Route::get('/subjects/{groupBy?}', 'UserSubjectsController@index')->name('user_subjects'); Route::get('/subjects/{groupBy?}', 'UserSubjectsController@index')->name('user_subjects');
Route::get('/classes/{groupBy?}', 'UserClassesController@index')->name('user_classes'); Route::get('/classes/{groupBy?}', 'UserClassesController@index')->name('user_classes');