Battery overview
+ +
+ Charge cycles count:
+ Last charged:
+
diff --git a/controllers/LoginController.php b/controllers/LoginController.php index 592f608c..9601c730 100644 --- a/controllers/LoginController.php +++ b/controllers/LoginController.php @@ -25,7 +25,7 @@ class LoginController extends BaseController if ($postParams['username'] === HTTP_USER && $postParams['password'] === HTTP_PASSWORD) { $sessionKey = $this->SessionService->CreateSession(); - setcookie('grocy_session', $sessionKey, time()+2592000); //30 days + setcookie('grocy_session', $sessionKey, time() + 31536000); // Cookie expires in 1 year, but session validity is up to SessionService return $response->withRedirect('/'); } diff --git a/middleware/BaseMiddleware.php b/middleware/BaseMiddleware.php new file mode 100644 index 00000000..21606cf5 --- /dev/null +++ b/middleware/BaseMiddleware.php @@ -0,0 +1,12 @@ +container = $container; + } + + protected $container; +} diff --git a/middleware/CliMiddleware.php b/middleware/CliMiddleware.php index 5cc8e82f..0cf10166 100644 --- a/middleware/CliMiddleware.php +++ b/middleware/CliMiddleware.php @@ -2,14 +2,8 @@ namespace Grocy\Middleware; -class CliMiddleware +class CliMiddleware extends BaseMiddleware { - public function __construct(\Slim\Container $container) { - $this->container = $container; - } - - protected $container; - public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) { if (PHP_SAPI !== 'cli') diff --git a/middleware/JsonMiddleware.php b/middleware/JsonMiddleware.php index 57443a4c..b970ad69 100644 --- a/middleware/JsonMiddleware.php +++ b/middleware/JsonMiddleware.php @@ -2,14 +2,8 @@ namespace Grocy\Middleware; -class JsonMiddleware +class JsonMiddleware extends BaseMiddleware { - public function __construct(\Slim\Container $container) { - $this->container = $container; - } - - protected $container; - public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) { $response = $next($request, $response, $next); diff --git a/middleware/SessionAuthMiddleware.php b/middleware/SessionAuthMiddleware.php index f09cbe72..9e5e27a4 100644 --- a/middleware/SessionAuthMiddleware.php +++ b/middleware/SessionAuthMiddleware.php @@ -4,14 +4,8 @@ namespace Grocy\Middleware; use \Grocy\Services\SessionService; -class SessionAuthMiddleware +class SessionAuthMiddleware extends BaseMiddleware { - public function __construct(\Slim\Container $container) { - $this->container = $container; - } - - protected $container; - public function __invoke(\Slim\Http\Request $request, \Slim\Http\Response $response, callable $next) { $route = $request->getAttribute('route'); diff --git a/migrations/0020.sql b/migrations/0020.sql new file mode 100644 index 00000000..b3a9f92a --- /dev/null +++ b/migrations/0020.sql @@ -0,0 +1,6 @@ +CREATE TABLE sessions ( + id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, + session_key TEXT NOT NULL UNIQUE, + expires DATETIME, + row_created_timestamp DATETIME DEFAULT (datetime('now', 'localtime')) +) diff --git a/public/css/grocy.css b/public/css/grocy.css index 2cc04ec8..b0394505 100644 --- a/public/css/grocy.css +++ b/public/css/grocy.css @@ -23,7 +23,7 @@ overflow-x: hidden; overflow-y: auto; background-color: #e5e5e5; - border-right: 1px solid #d6d6d6; + border-right: 2px solid #d6d6d6; min-width: 220px; max-width: 260px; } @@ -42,12 +42,14 @@ .nav-sidebar > li > a { padding-right: 20px; padding-left: 20px; + transition: all 0.3s; } .nav-sidebar > .active > a, .nav-sidebar > .active > a:hover, .nav-sidebar > .active > a:focus { background-color: #d6d6d6; + transition: all 0.3s; } .navbar-default { @@ -73,7 +75,6 @@ color: #a7a7a7; font-size: 11px; text-align: center; - font-family: 'Arial', sans-serif; } .discrete-link { @@ -94,15 +95,15 @@ a.discrete-link:focus { } .navbar-fixed-top { - border-bottom: solid; + border-bottom: 2px solid; border-color: #d6d6d6; } .navbar-brand { font-weight: bold; - letter-spacing: -2px; + letter-spacing: -5px; font-size: 2.2em; - font-family: 'Arial', sans-serif; + } .table td.fit-content, diff --git a/public/js/extensions.js b/public/js/extensions.js new file mode 100644 index 00000000..98e64ca2 --- /dev/null +++ b/public/js/extensions.js @@ -0,0 +1,33 @@ +EmptyElementWhenMatches = function(selector, text) +{ + if ($(selector).text() === text) + { + $(selector).text(''); + } +}; + +String.prototype.contains = function(search) +{ + return this.toLowerCase().indexOf(search.toLowerCase()) !== -1; +}; + +String.prototype.isEmpty = function() +{ + return (this.length === 0 || !this.trim()); +}; + +GetUriParam = function(key) +{ + var currentUri = decodeURIComponent(window.location.search.substring(1)); + var vars = currentUri.split('&'); + + for (i = 0; i < vars.length; i++) + { + var currentParam = vars[i].split('='); + + if (currentParam[0] === key) + { + return currentParam[1] === undefined ? true : currentParam[1]; + } + } +}; diff --git a/public/js/grocy.js b/public/js/grocy.js index d24dca66..54afd320 100644 --- a/public/js/grocy.js +++ b/public/js/grocy.js @@ -1,4 +1,5 @@ var Grocy = { }; +Grocy.Components = { }; $(function() { @@ -70,42 +71,3 @@ Grocy.PostJson = function(url, jsonData, success, error) xhr.setRequestHeader('Content-type', 'application/json'); xhr.send(JSON.stringify(jsonData)); }; - -Grocy.EmptyElementWhenMatches = function(selector, text) -{ - if ($(selector).text() === text) - { - $(selector).text(''); - } -}; - -String.prototype.contains = function(search) -{ - return this.toLowerCase().indexOf(search.toLowerCase()) !== -1; -}; - -String.prototype.isEmpty = function() -{ - return (this.length === 0 || !this.trim()); -}; - -Grocy.GetUriParam = function(key) -{ - var currentUri = decodeURIComponent(window.location.search.substring(1)); - var vars = currentUri.split('&'); - - for (i = 0; i < vars.length; i++) - { - var currentParam = vars[i].split('='); - - if (currentParam[0] === key) - { - return currentParam[1] === undefined ? true : currentParam[1]; - } - } -}; - -Grocy.Wait = function(ms) -{ - return new Promise(resolve => setTimeout(resolve, ms)); -} diff --git a/public/viewjs/batterytracking.js b/public/viewjs/batterytracking.js index a488e5c7..b86a919c 100644 --- a/public/viewjs/batterytracking.js +++ b/public/viewjs/batterytracking.js @@ -39,23 +39,8 @@ $('#battery_id').on('change', function(e) if (batteryId) { - Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId, - function(batteryDetails) - { - $('#selected-battery-name').text(batteryDetails.battery.name); - $('#selected-battery-last-charged').text((batteryDetails.last_charged || 'never')); - $('#selected-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || '')); - $('#selected-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0')); - - $('#tracked_time').focus(); - - Grocy.EmptyElementWhenMatches('#selected-battery-last-charged-timeago', 'NaN years ago'); - }, - function(xhr) - { - console.error(xhr); - } - ); + Grocy.Components.BatteryCard.Refresh(batteryId); + $('#tracked_time').focus(); } }); diff --git a/public/viewjs/components/batterycard.js b/public/viewjs/components/batterycard.js new file mode 100644 index 00000000..267cd9ba --- /dev/null +++ b/public/viewjs/components/batterycard.js @@ -0,0 +1,20 @@ +Grocy.Components.BatteryCard = { }; + +Grocy.Components.BatteryCard.Refresh = function(batteryId) +{ + Grocy.FetchJson('/api/batteries/get-battery-details/' + batteryId, + function(batteryDetails) + { + $('#batterycard-battery-name').text(batteryDetails.battery.name); + $('#batterycard-battery-last-charged').text((batteryDetails.last_charged || 'never')); + $('#batterycard-battery-last-charged-timeago').text($.timeago(batteryDetails.last_charged || '')); + $('#batterycard-battery-charge-cycles-count').text((batteryDetails.charge_cycles_count || '0')); + + EmptyElementWhenMatches('#batterycard-battery-last-charged-timeago', 'NaN years ago'); + }, + function(xhr) + { + console.error(xhr); + } + ); +}; diff --git a/public/viewjs/components/habitcard.js b/public/viewjs/components/habitcard.js new file mode 100644 index 00000000..350c5c2f --- /dev/null +++ b/public/viewjs/components/habitcard.js @@ -0,0 +1,20 @@ +Grocy.Components.HabitCard = { }; + +Grocy.Components.HabitCard.Refresh = function (habitId) +{ + Grocy.FetchJson('/api/habits/get-habit-details/' + habitId, + function(habitDetails) + { + $('#habitcard-habit-name').text(habitDetails.habit.name); + $('#habitcard-habit-last-tracked').text((habitDetails.last_tracked || 'never')); + $('#habitcard-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || '')); + $('#habitcard-habit-tracked-count').text((habitDetails.tracked_count || '0')); + + EmptyElementWhenMatches('#habitcard-habit-last-tracked-timeago', 'NaN years ago'); + }, + function(xhr) + { + console.error(xhr); + } + ); +}; diff --git a/public/viewjs/components/productcard.js b/public/viewjs/components/productcard.js new file mode 100644 index 00000000..b49be651 --- /dev/null +++ b/public/viewjs/components/productcard.js @@ -0,0 +1,25 @@ +Grocy.Components.ProductCard = { }; + +Grocy.Components.ProductCard.Refresh = function(productId) +{ + Grocy.FetchJson('/api/stock/get-product-details/' + productId, + function(productDetails) + { + $('#productcard-product-name').text(productDetails.product.name); + $('#productcard-product-stock-amount').text(productDetails.stock_amount || '0'); + $('#productcard-product-stock-qu-name').text(productDetails.quantity_unit_stock.name); + $('#productcard-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name); + $('#productcard-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10)); + $('#productcard-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || '')); + $('#productcard-product-last-used').text((productDetails.last_used || 'never').substring(0, 10)); + $('#productcard-product-last-used-timeago').text($.timeago(productDetails.last_used || '')); + + EmptyElementWhenMatches('#productcard-product-last-purchased-timeago', 'NaN years ago'); + EmptyElementWhenMatches('#productcard-product-last-used-timeago', 'NaN years ago'); + }, + function(xhr) + { + console.error(xhr); + } + ); +}; diff --git a/public/viewjs/consume.js b/public/viewjs/consume.js index 1a84cd27..ae000b99 100644 --- a/public/viewjs/consume.js +++ b/public/viewjs/consume.js @@ -44,24 +44,15 @@ $('#product_id').on('change', function(e) if (productId) { + Grocy.Components.ProductCard.Refresh(productId); + Grocy.FetchJson('/api/stock/get-product-details/' + productId, function (productDetails) { - $('#selected-product-name').text(productDetails.product.name); - $('#selected-product-stock-amount').text(productDetails.stock_amount || '0'); - $('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name); - $('#selected-product-stock-qu-name2').text(productDetails.quantity_unit_stock.name); - $('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10)); - $('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || '')); - $('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10)); - $('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || '')); $('#amount').attr('max', productDetails.stock_amount); $('#consume-form').validator('update'); $('#amount_qu_unit').text(productDetails.quantity_unit_stock.name); - Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); - Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); - if ((productDetails.stock_amount || 0) === 0) { $('#product_id').val(''); diff --git a/public/viewjs/habittracking.js b/public/viewjs/habittracking.js index 135f034f..2e44208f 100644 --- a/public/viewjs/habittracking.js +++ b/public/viewjs/habittracking.js @@ -39,23 +39,8 @@ $('#habit_id').on('change', function(e) if (habitId) { - Grocy.FetchJson('/api/habits/get-habit-details/' + habitId, - function(habitDetails) - { - $('#selected-habit-name').text(habitDetails.habit.name); - $('#selected-habit-last-tracked').text((habitDetails.last_tracked || 'never')); - $('#selected-habit-last-tracked-timeago').text($.timeago(habitDetails.last_tracked || '')); - $('#selected-habit-tracked-count').text((habitDetails.tracked_count || '0')); - - $('#tracked_time').focus(); - - Grocy.EmptyElementWhenMatches('#selected-habit-last-tracked-timeago', 'NaN years ago'); - }, - function(xhr) - { - console.error(xhr); - } - ); + Grocy.Components.HabitCard.Refresh(habitId); + $('#tracked_time').focus(); } }); diff --git a/public/viewjs/inventory.js b/public/viewjs/inventory.js index 7154d968..d0e47fbc 100644 --- a/public/viewjs/inventory.js +++ b/public/viewjs/inventory.js @@ -10,7 +10,7 @@ Grocy.FetchJson('/api/stock/inventory-product/' + jsonForm.product_id + '/' + jsonForm.new_amount + '?bestbeforedate=' + $('#best_before_date').val(), function(result) { - var addBarcode = Grocy.GetUriParam('addbarcodetoselection'); + var addBarcode = GetUriParam('addbarcodetoselection'); if (addBarcode !== undefined) { var existingBarcodes = productDetails.product.barcode || ''; @@ -33,7 +33,6 @@ } toastr.success('Stock amount of ' + productDetails.product.name + ' is now ' + jsonForm.new_amount.toString() + ' ' + productDetails.quantity_unit_stock.name); - Grocy.Wait(1000); if (addBarcode !== undefined) { @@ -70,24 +69,15 @@ $('#product_id').on('change', function(e) if (productId) { + Grocy.Components.ProductCard.Refresh(productId); + Grocy.FetchJson('/api/stock/get-product-details/' + productId, function(productDetails) { - $('#selected-product-name').text(productDetails.product.name); - $('#selected-product-stock-amount').text(productDetails.stock_amount || '0'); - $('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name); - $('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name); - $('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10)); - $('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || '')); - $('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10)); - $('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || '')); $('#new_amount').attr('not-equal', productDetails.stock_amount); $('#new_amount_qu_unit').text(productDetails.quantity_unit_stock.name); $('#new_amount').focus(); - - Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); - Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); }, function(xhr) { @@ -121,7 +111,7 @@ $(function() var input = $('#product_id_text_input').val().toString(); var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first(); - if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0) + if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0) { $('#product_id').val(possibleOptionElement.val()); $('#product_id').data('combobox').refresh(); @@ -130,7 +120,7 @@ $(function() else { var optionElement = $("#product_id option:contains('" + input + "')").first(); - if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined ) + if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined ) { bootbox.dialog({ message: '' + input + ' could not be resolved to a product, how do you want to proceed?', @@ -246,7 +236,7 @@ $(function() } }); - var prefillProduct = Grocy.GetUriParam('createdproduct'); + var prefillProduct = GetUriParam('createdproduct'); if (prefillProduct !== undefined) { var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first(); @@ -264,7 +254,7 @@ $(function() } } - var addBarcode = Grocy.GetUriParam('addbarcodetoselection'); + var addBarcode = GetUriParam('addbarcodetoselection'); if (addBarcode !== undefined) { $('#addbarcodetoselection').text(addBarcode); diff --git a/public/viewjs/login.js b/public/viewjs/login.js index 08134ca3..6dd8e7c1 100644 --- a/public/viewjs/login.js +++ b/public/viewjs/login.js @@ -4,7 +4,7 @@ $('#username').focus(); - if (Grocy.GetUriParam('invalid') === 'true') + if (GetUriParam('invalid') === 'true') { $('#login-error').text('Invalid credentials, please try again.'); $('#login-error').show(); diff --git a/public/viewjs/productform.js b/public/viewjs/productform.js index 4cb46000..a39a264a 100644 --- a/public/viewjs/productform.js +++ b/public/viewjs/productform.js @@ -3,7 +3,7 @@ e.preventDefault(); var redirectDestination = '/products'; - var returnTo = Grocy.GetUriParam('returnto'); + var returnTo = GetUriParam('returnto'); if (returnTo !== undefined) { redirectDestination = returnTo + '?createdproduct=' + encodeURIComponent($('#name').val()); @@ -69,14 +69,14 @@ $(function() $('#product-form').validator(); $('#product-form').validator('validate'); - var prefillName = Grocy.GetUriParam('prefillname'); + var prefillName = GetUriParam('prefillname'); if (prefillName !== undefined) { $('#name').val(prefillName); $('#name').focus(); } - var prefillBarcode = Grocy.GetUriParam('prefillbarcode'); + var prefillBarcode = GetUriParam('prefillbarcode'); if (prefillBarcode !== undefined) { $('#barcode-taginput').tagsManager('pushTag', prefillBarcode); diff --git a/public/viewjs/purchase.js b/public/viewjs/purchase.js index 476db4b3..6d78ef75 100644 --- a/public/viewjs/purchase.js +++ b/public/viewjs/purchase.js @@ -12,7 +12,7 @@ Grocy.FetchJson('/api/stock/add-product/' + jsonForm.product_id + '/' + amount + '?bestbeforedate=' + $('#best_before_date').val(), function(result) { - var addBarcode = Grocy.GetUriParam('addbarcodetoselection'); + var addBarcode = GetUriParam('addbarcodetoselection'); if (addBarcode !== undefined) { var existingBarcodes = productDetails.product.barcode || ''; @@ -35,7 +35,6 @@ } toastr.success('Added ' + amount + ' ' + productDetails.quantity_unit_stock.name + ' of ' + productDetails.product.name + ' to stock'); - Grocy.Wait(1000); if (addBarcode !== undefined) { @@ -71,17 +70,11 @@ $('#product_id').on('change', function(e) if (productId) { + Grocy.Components.ProductCard.Refresh(productId); + Grocy.FetchJson('/api/stock/get-product-details/' + productId, function(productDetails) { - $('#selected-product-name').text(productDetails.product.name); - $('#selected-product-stock-amount').text(productDetails.stock_amount || '0'); - $('#selected-product-stock-qu-name').text(productDetails.quantity_unit_stock.name); - $('#selected-product-purchase-qu-name').text(productDetails.quantity_unit_purchase.name); - $('#selected-product-last-purchased').text((productDetails.last_purchased || 'never').substring(0, 10)); - $('#selected-product-last-purchased-timeago').text($.timeago(productDetails.last_purchased || '')); - $('#selected-product-last-used').text((productDetails.last_used || 'never').substring(0, 10)); - $('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || '')); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); if (productDetails.product.default_best_before_days.toString() !== '0') @@ -93,10 +86,7 @@ $('#product_id').on('change', function(e) else { $('#best_before_date').focus(); - } - - Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); - Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); + } }, function(xhr) { @@ -130,7 +120,7 @@ $(function() var input = $('#product_id_text_input').val().toString(); var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + input + "']").first(); - if (Grocy.GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0) + if (GetUriParam('addbarcodetoselection') === undefined && possibleOptionElement.length > 0) { $('#product_id').val(possibleOptionElement.val()); $('#product_id').data('combobox').refresh(); @@ -139,7 +129,7 @@ $(function() else { var optionElement = $("#product_id option:contains('" + input + "')").first(); - if (input.length > 0 && optionElement.length === 0 && Grocy.GetUriParam('addbarcodetoselection') === undefined ) + if (input.length > 0 && optionElement.length === 0 && GetUriParam('addbarcodetoselection') === undefined ) { bootbox.dialog({ message: '' + input + ' could not be resolved to a product, how do you want to proceed?', @@ -256,7 +246,7 @@ $(function() } }); - var prefillProduct = Grocy.GetUriParam('createdproduct'); + var prefillProduct = GetUriParam('createdproduct'); if (prefillProduct !== undefined) { var possibleOptionElement = $("#product_id option[data-additional-searchdata*='" + prefillProduct + "']").first(); @@ -274,7 +264,7 @@ $(function() } } - var addBarcode = Grocy.GetUriParam('addbarcodetoselection'); + var addBarcode = GetUriParam('addbarcodetoselection'); if (addBarcode !== undefined) { $('#addbarcodetoselection').text(addBarcode); @@ -282,7 +272,7 @@ $(function() $('#barcode-lookup-disabled-hint').removeClass('hide'); } - Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago'); + EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago'); }); $('#best_before_date-datepicker-button').on('click', function(e) @@ -314,7 +304,7 @@ $('#best_before_date').on('change', function(e) } $('#best-before-timeago').text($.timeago($('#best_before_date').val())); - Grocy.EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago'); + EmptyElementWhenMatches('#best-before-timeago', 'NaN years ago'); }); $('#best_before_date').on('keydown', function(e) diff --git a/public/viewjs/shoppinglistform.js b/public/viewjs/shoppinglistform.js index 9420c499..4d20eb62 100644 --- a/public/viewjs/shoppinglistform.js +++ b/public/viewjs/shoppinglistform.js @@ -49,8 +49,8 @@ $('#product_id').on('change', function(e) $('#selected-product-last-used-timeago').text($.timeago(productDetails.last_used || '')); $('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name); - Grocy.EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); - Grocy.EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); + EmptyElementWhenMatches('#selected-product-last-purchased-timeago', 'NaN years ago'); + EmptyElementWhenMatches('#selected-product-last-used-timeago', 'NaN years ago'); if ($('#product_id').hasClass('suppress-next-custom-validate-event')) { diff --git a/services/SessionService.php b/services/SessionService.php index e909a734..95bef42d 100644 --- a/services/SessionService.php +++ b/services/SessionService.php @@ -15,7 +15,7 @@ class SessionService extends BaseService } else { - return file_exists(__DIR__ . "/../data/sessions/$sessionKey.txt"); + return $this->Database->sessions()->where('session_key = :1 AND expires > :2', $sessionKey, time())->count() === 1; } } @@ -24,27 +24,19 @@ class SessionService extends BaseService */ public function CreateSession() { - if (!file_exists(__DIR__ . '/../data/sessions')) - { - mkdir(__DIR__ . '/../data/sessions'); - } - - $now = time(); - foreach (new \FilesystemIterator(__DIR__ . '/../data/sessions') as $file) - { - if ($now - $file->getCTime() >= 2678400) //31 days - { - unlink(__DIR__ . '/../data/sessions/' . $file->getFilename()); - } - } - $newSessionKey = uniqid() . uniqid() . uniqid(); - file_put_contents(__DIR__ . "/../data/sessions/$newSessionKey.txt", ''); + + $sessionRow = $this->Database->sessions()->createRow(array( + 'session_key' => $newSessionKey, + 'expires' => time() + 2592000 //30 days + )); + $sessionRow->save(); + return $newSessionKey; } public function RemoveSession($sessionKey) { - unlink(__DIR__ . "/../data/sessions/$sessionKey.txt"); + $this->Database->sessions()->where('session_key', $sessionKey)->delete(); } } diff --git a/views/batteries.blade.php b/views/batteries.blade.php index cd348c4f..bb7d26a1 100644 --- a/views/batteries.blade.php +++ b/views/batteries.blade.php @@ -5,7 +5,7 @@ @section('viewJsName', 'batteries') @section('content') -
- Charge cycles count:
- Last charged:
-
+ Charge cycles count:
+ Last charged:
+
+ Tracked count:
+ Last tracked:
+
+ Stock amount:
+ Last purchased:
+ Last used:
+
- Stock amount:
- Last purchased:
- Last used:
-
- Tracked count:
- Last tracked:
-
- Stock amount:
- Last purchased:
- Last used:
-
- Stock amount:
- Last purchased:
- Last used:
-