Fix some form validation problems (closes #36)

This commit is contained in:
Bernd Bestel
2018-08-04 07:45:24 +02:00
parent 7eef4acd81
commit 6081b8ee67
8 changed files with 27 additions and 8 deletions

View File

@@ -36,7 +36,7 @@ else
// Load composer dependencies
require_once __DIR__ . '/vendor/autoload.php';
// Load config fils
// Load config files
require_once GROCY_DATAPATH . '/config.php';
require_once __DIR__ . '/config-dist.php'; //For not in own config defined values we use the default ones

View File

@@ -49,12 +49,20 @@ class ApiKeyAuthMiddleware extends BaseMiddleware
define('GROCY_AUTHENTICATED', false);
$response = $response->withStatus(401);
}
else
elseif ($validApiKey)
{
$user = $apiKeyService->GetUserByApiKey($request->getHeaderLine($this->ApiKeyHeaderName));
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
elseif ($validSession)
{
$user = $sessionService->GetUserBySessionKey($_COOKIE[$this->SessionCookieName]);
define('GROCY_AUTHENTICATED', true);
define('GROCY_USER_ID', $user->id);
$response = $next($request, $response);
}
}

View File

@@ -44,6 +44,7 @@ $('#battery_id').on('change', function(e)
{
Grocy.Components.BatteryCard.Refresh(batteryId);
$('#tracked_time').find('input').focus();
Grocy.FrontendHelpers.ValidateForm('batterytracking-form');
}
});

View File

@@ -43,6 +43,7 @@ $('#habit_id').on('change', function(e)
{
Grocy.Components.HabitCard.Refresh(habitId);
Grocy.Components.DateTimePicker.GetInputElement().focus();
Grocy.FrontendHelpers.ValidateForm('habittracking-form');
}
});

View File

@@ -45,12 +45,13 @@ class HabitsService extends BaseService
$habitTrackedCount = $this->Database->habits_log()->where('habit_id', $habitId)->count();
$habitLastTrackedTime = $this->Database->habits_log()->where('habit_id', $habitId)->max('tracked_time');
$doneByUserId = $this->Database->habits_log()->where('habit_id = :1 AND tracked_time = :2', $habitId, $habitLastTrackedTime)->fetch()->done_by_user_id;
if ($doneByUserId !== null && !empty($doneByUserId))
$lastHabitLogRow = $this->Database->habits_log()->where('habit_id = :1 AND tracked_time = :2', $habitId, $habitLastTrackedTime)->fetch();
$lastDoneByUser = null;
if ($lastHabitLogRow !== null && !empty($lastHabitLogRow))
{
$usersService = new UsersService();
$users = $usersService->GetUsersAsDto();
$lastDoneByUser = FindObjectInArrayByPropertyValue($users, 'id', $doneByUserId);
$lastDoneByUser = FindObjectInArrayByPropertyValue($users, 'id', $lastHabitLogRow->done_by_user_id);
}
return array(

View File

@@ -33,7 +33,13 @@ class StockService extends BaseService
$productLastUsed = $this->Database->stock_log()->where('product_id', $productId)->where('transaction_type', self::TRANSACTION_TYPE_CONSUME)->max('used_date');
$quPurchase = $this->Database->quantity_units($product->qu_id_purchase);
$quStock = $this->Database->quantity_units($product->qu_id_stock);
$lastPrice = $this->Database->stock_log()->where('product_id = :1 AND transaction_type = :2', $productId, self::TRANSACTION_TYPE_PURCHASE)->orderBy('row_created_timestamp', 'DESC')->limit(1)->fetch()->price;
$lastPrice = null;
$lastLogRow = $this->Database->stock_log()->where('product_id = :1 AND transaction_type = :2', $productId, self::TRANSACTION_TYPE_PURCHASE)->orderBy('row_created_timestamp', 'DESC')->limit(1)->fetch();
if ($lastLogRow !== null && !empty($lastLogRow))
{
$lastPrice = $lastLogRow->price;
}
return array(
'product' => $product,

View File

@@ -4,10 +4,11 @@
@php if(empty($disallowAddProductWorkflows)) { $disallowAddProductWorkflows = false; } @endphp
@php if(empty($prefillByName)) { $prefillByName = ''; } @endphp
@php if(!isset($isRequired)) { $isRequired = true; } @endphp
<div class="form-group" data-next-input-selector="{{ $nextInputSelector }}" data-disallow-add-product-workflows="{{ BoolToString($disallowAddProductWorkflows) }}" data-prefill-by-name="{{ $prefillByName }}">
<label for="product_id">{{ $L('Product') }} <i class="fas fa-barcode"></i><span id="barcode-lookup-disabled-hint" class="small text-muted d-none"> {{ $L('Barcode lookup is disabled') }}</span></label>
<select class="form-control product-combobox" id="product_id" name="product_id" required>
<select class="form-control product-combobox" id="product_id" name="product_id" @if($isRequired) required @endif>
<option value=""></option>
@foreach($products as $product)
<option data-additional-searchdata="{{ $product->barcode }}" value="{{ $product->id }}">{{ $product->name }}</option>

View File

@@ -23,7 +23,8 @@
@include('components.productpicker', array(
'products' => $products,
'nextInputSelector' => '#amount'
'nextInputSelector' => '#amount',
'isRequired' => false
))
<div class="form-group">