This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/Core/Utils/User.php
T
Taras Machyshyn b0d1bb4486 vendor update
2013-11-19 12:52:41 +02:00

75 lines
1.2 KiB
PHP

<?php
namespace Espo\Core\Utils;
class User
{
private $entityManager;
private $config;
private $currentUser;
public function __construct(\Doctrine\ORM\EntityManager $entityManager, \Espo\Core\Utils\Config $config)
{
$this->entityManager = $entityManager;
$this->config = $config;
}
protected function getEntityManager()
{
return $this->entityManager;
}
protected function getConfig()
{
return $this->config;
}
public function getCurrentUser()
{
return $this->currentUser;
}
protected function setCurrentUser(\Espo\Entities\User $user)
{
$this->currentUser = $user;
}
public function authenticate($username, $password)
{
$user = $this->getEntityManager()->getRepository('\Espo\Entities\User')->findOneBy(array('username' => $username));
if ( $password == $user->getPassword() ) {
$this->setCurrentUser($user);
return true;
}
return false;
}
public function isAdmin(\Espo\Entities\User $user = null)
{
if (is_null($user)) {
$user = $this->getCurrentUser();
}
if ($user instanceof \Espo\Entities\User) {
$id = $user->getId();
if ( !empty($id) ) {
return $user->getIsAdmin();
}
}
return false;
}
}
?>