2014-08-30 18:11:32 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Dao;
|
|
|
|
|
|
|
|
class UserDao extends AbstractDao implements ICrudDao
|
|
|
|
{
|
2014-09-03 19:07:53 +02:00
|
|
|
public function __construct(
|
|
|
|
\Szurubooru\DatabaseConnection $databaseConnection)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
|
|
|
parent::__construct($databaseConnection, 'users', '\Szurubooru\Entities\User');
|
|
|
|
}
|
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
public function findByName($userName)
|
2014-08-30 18:11:32 +02:00
|
|
|
{
|
|
|
|
$arrayEntity = $this->collection->findOne(['name' => $userName]);
|
|
|
|
return $this->entityConverter->toEntity($arrayEntity);
|
|
|
|
}
|
2014-09-01 19:43:49 +02:00
|
|
|
|
2014-09-13 23:58:13 +02:00
|
|
|
public function findByEmail($userEmail, $allowUnconfirmed = false)
|
2014-09-08 13:06:32 +02:00
|
|
|
{
|
|
|
|
$arrayEntity = $this->collection->findOne(['email' => $userEmail]);
|
|
|
|
if (!$arrayEntity and $allowUnconfirmed)
|
|
|
|
$arrayEntity = $this->collection->findOne(['emailUnconfirmed' => $userEmail]);
|
|
|
|
return $this->entityConverter->toEntity($arrayEntity);
|
|
|
|
}
|
|
|
|
|
2014-09-01 19:43:49 +02:00
|
|
|
public function hasAnyUsers()
|
|
|
|
{
|
|
|
|
return (bool) $this->collection->findOne();
|
|
|
|
}
|
2014-09-05 13:50:51 +02:00
|
|
|
|
|
|
|
public function deleteByName($userName)
|
|
|
|
{
|
|
|
|
$this->collection->remove(['name' => $userName]);
|
|
|
|
$tokens = $this->db->selectCollection('tokens');
|
|
|
|
$tokens->remove(['additionalData' => $userName]);
|
|
|
|
}
|
2014-08-30 18:11:32 +02:00
|
|
|
}
|