/** * @return string */ private function getUsername() { $username = '******'; if ($this->identity) { $service = $this->container->getService('Nella\Security\CredentialsEntity'); $credentials = $service->repository->findOneByIdentity($this->identity->id); if ($credentials) { $username = $credentials->username; } } return $username; }
/** * Performs an authentication * * @param array * @return IdentityEntity * @throws \Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $service = $this->container->getService('Nella\Security\CredentialsEntity'); if (strpos($username, '@') !== FALSE) { $entity = $service->repository->findOneByEmail($username); } else { $entity = $service->repository->findOneByUsername($username); } if (empty($entity)) { throw new \Nette\Security\AuthenticationException("User with this username or email is not registered", self::IDENTITY_NOT_FOUND); } if ($entity->verifyPassword($password) == FALSE) { throw new \Nette\Security\AuthenticationException("Invalid password", self::INVALID_CREDENTIAL); } return $entity->identity; }
/** * @param \Nella\Doctrine\Container */ public function __construct(\Nella\Doctrine\Container $container) { $service = $container->getService('Nella\Security\RoleEntity'); $roles = $service->repository->findAll(); foreach ($this->defaultResources as $resource) { $this->addResource($resource); } foreach ($roles as $role) { $this->addRole($role->name); foreach ($role->permissions as $permission) { if ($permission->resource && !$this->hasResource($permission->resource)) { $this->addResource($permission->resource); } if ($permission->allow) { $this->allow($role->name, $permission->resource, $permission->privilege); } else { $this->deny($role->name, $permission->resource, $permission->privilege); } } } }
/** * @return \Nella\Models\Service */ protected function getImageService() { return $this->container->getService('Nella\Media\ImageEntity'); }
/** * @param int * @return FileEntity */ protected function getFile($id) { return $this->container->getService('Nella\Media\FileEntity')->repository->find($id); }
/** * @param \Nella\Doctrine\Container * @return IdentityEntity */ public function load(\Nella\Doctrine\Container $container) { if (!$this->loaded) { $service = $container->getService(__CLASS__); $entity = $service->repository->find($this->getId()); $entity->loaded = TRUE; return $entity; } else { return $this; } }