Moderno
This commit is contained in:
@ -16,7 +16,7 @@ class Login extends Ideal\Repository
|
||||
}
|
||||
|
||||
|
||||
public function create(?array $data = null): Define\Model
|
||||
public function create(?array $data = null): Model\Login
|
||||
{
|
||||
$map = (new Implement\Repository\MapperParser(['selector', 'token']))
|
||||
->register('user_id', (new Implement\Repository\Mapper())
|
||||
@ -29,7 +29,7 @@ class Login extends Ideal\Repository
|
||||
return $this->parseData(new Model\Login(), $data, $map);
|
||||
}
|
||||
|
||||
public function save(Define\Model $model): Define\Model
|
||||
public function save(Define\Model $model): Model\Login
|
||||
{
|
||||
$model->id = $this->saveNew(
|
||||
['user_id', 'selector', 'token', 'time', 'status'],
|
||||
@ -37,29 +37,41 @@ class Login extends Ideal\Repository
|
||||
return $model;
|
||||
}
|
||||
|
||||
public function edit(Define\Model $model, array $new_data): Define\Model
|
||||
public function edit(Define\Model $model, array $new_data): Model\Login
|
||||
{
|
||||
return $this->update($model, ['user_id', 'selector', 'token', 'time', 'status'], $new_data);
|
||||
}
|
||||
|
||||
public function fetchByUser(int $user_id): array
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `user_id` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('user_id = ?');
|
||||
return $this->fetchMany($query, [$user_id]);
|
||||
}
|
||||
public function fetchActiveByUser(int $user_id): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `user_id` = ? AND `status` = 1";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('user_id = ? AND `status` = 1');
|
||||
return $this->fetchOne($query, [$user_id]);
|
||||
}
|
||||
public function fetchBySelectorAndToken(string $selector, string $token): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `selector` = ? AND `token` = ?";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('selector = ? AND token = ?');
|
||||
return $this->fetchOne($query, [$selector, $token]);
|
||||
}
|
||||
public function fetchActiveBySelector(string $selector): Model\Login
|
||||
{
|
||||
$query = "SELECT * FROM `{$this->getTable()}` WHERE `selector` = ? AND `status` = 1";
|
||||
$query = $this->connection->getQueryBuilder()
|
||||
->select()
|
||||
->from($this->getTable())
|
||||
->where('selector = ? AND `status` = 1');
|
||||
return $this->fetchOne($query, [$selector]);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use PDOException;
|
||||
use Incoviba\Common\Implement\Exception\EmptyResult;
|
||||
use Incoviba\Repository;
|
||||
use Incoviba\Model;
|
||||
use PhpParser\Node\Expr\AssignOp\Mod;
|
||||
use function random_bytes;
|
||||
use function password_hash;
|
||||
use function setcookie;
|
||||
|
Reference in New Issue
Block a user