Skip to content

Commit 324cc10

Browse files
committed
Added dbAuth middleware
1 parent 0856c2f commit 324cc10

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ class DbAuthMiddleware extends Middleware
1717
{
1818
private $reflection;
1919
private $db;
20+
private $ordering;
2021

2122
public function __construct(Router $router, Responder $responder, array $properties, ReflectionService $reflection, GenericDB $db)
2223
{
2324
parent::__construct($router, $responder, $properties);
2425
$this->reflection = $reflection;
2526
$this->db = $db;
27+
$this->ordering = new OrderingInfo();
2628
}
2729

2830
public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
@@ -52,7 +54,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5254
$columnNames = array_map('trim', explode(',', $returnedColumns));
5355
$columnNames[] = $passwordColumnName;
5456
}
55-
$users = $this->db->selectAll($table, $columnNames, $condition, [], 0, 1);
57+
$columnOrdering = $this->ordering->getDefaultColumnOrdering($table);
58+
$users = $this->db->selectAll($table, $columnNames, $condition, $columnOrdering, 0, 1);
5659
foreach ($users as $user) {
5760
if (password_verify($password, $user[$passwordColumnName]) == 1) {
5861
if (!headers_sent()) {

src/Tqdev/PhpCrudApi/Record/RelationJoiner.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
use Tqdev\PhpCrudApi\Column\ReflectionService;
55
use Tqdev\PhpCrudApi\Column\Reflection\ReflectedTable;
66
use Tqdev\PhpCrudApi\Database\GenericDB;
7+
use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
78
use Tqdev\PhpCrudApi\Record\Condition\ColumnCondition;
89
use Tqdev\PhpCrudApi\Record\Condition\OrCondition;
9-
use Tqdev\PhpCrudApi\Middleware\Communication\VariableStore;
1010

1111
class RelationJoiner
1212
{
1313

1414
private $reflection;
15+
private $ordering;
1516
private $columns;
1617

1718
public function __construct(ReflectionService $reflection, ColumnIncluder $columns)
@@ -95,7 +96,7 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
9596
foreach ($joins->getKeys() as $t2Name) {
9697

9798
$t2 = $this->reflection->getTable($t2Name);
98-
99+
99100
$belongsTo = count($t1->getFksTo($t2->getName())) > 0;
100101
$hasMany = count($t2->getFksTo($t1->getName())) > 0;
101102
if (!$belongsTo && !$hasMany) {
@@ -113,11 +114,11 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
113114
if ($belongsTo) {
114115
$fkValues = $this->getFkEmptyValues($t1, $t2, $records);
115116
$this->addFkRecords($t2, $fkValues, $params, $db, $newRecords);
116-
}
117+
}
117118
if ($hasMany) {
118119
$pkValues = $this->getPkEmptyValues($t1, $records);
119120
$this->addPkRecords($t1, $t2, $pkValues, $params, $db, $newRecords);
120-
}
121+
}
121122
if ($hasAndBelongsToMany) {
122123
$habtmValues = $this->getHabtmEmptyValues($t1, $t2, $t3, $db, $records);
123124
$this->addFkRecords($t2, $habtmValues->fkValues, $params, $db, $newRecords);
@@ -128,11 +129,11 @@ private function addJoinsForTables(ReflectedTable $t1, PathTree $joins, array &$
128129
if ($fkValues != null) {
129130
$this->fillFkValues($t2, $newRecords, $fkValues);
130131
$this->setFkValues($t1, $t2, $records, $fkValues);
131-
}
132+
}
132133
if ($pkValues != null) {
133134
$this->fillPkValues($t1, $t2, $newRecords, $pkValues);
134135
$this->setPkValues($t1, $t2, $records, $pkValues);
135-
}
136+
}
136137
if ($habtmValues != null) {
137138
$this->fillFkValues($t2, $newRecords, $habtmValues->fkValues);
138139
$this->setHabtmValues($t1, $t2, $records, $habtmValues);

0 commit comments

Comments
 (0)