commit 6b983650b0076c57ffd5b4eb855bad7e571d74a3
Author: Filip Jani <jsem@filek.cz>
Date:   Thu Apr 11 15:19:49 2019 +0200

    Re #7216 autentikátor a úprava dockerfile

diff --git a/app/config/config.neon b/app/config/config.neon
index 5f15f22..a64ff21 100644
--- a/app/config/config.neon
+++ b/app/config/config.neon
@@ -13,3 +13,4 @@ session:
 
 services:
 	router: App\RouterFactory::createRouter
+	authenticator: Model\Authenticator
diff --git a/app/model/Authenticator.php b/app/model/Authenticator.php
new file mode 100644
index 0000000..32cfd48
--- /dev/null
+++ b/app/model/Authenticator.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Model;
+
+use Model\Repository\UserRepository;
+use Model\Repository\UserRoleRepository;
+use Nette\Security\AuthenticationException;
+use Nette\Security\IAuthenticator;
+use Nette\Security\Identity;
+
+class Authenticator implements IAuthenticator
+{
+
+    /** @var UserRepository */
+    private $userRepository;
+    /** @var UserRoleRepository */
+    private $userRoleRepository;
+
+    public function __construct(UserRepository $userRepository, UserRoleRepository $userRoleRepository)
+    {
+
+        $this->userRepository = $userRepository;
+        $this->userRoleRepository = $userRoleRepository;
+    }
+
+    /**
+     * Autentikuje uživatele
+     *
+     * @param array $credentials
+     * @return Identity
+     * @throws AuthenticationException
+     */
+    function authenticate(array $credentials)
+    {
+        list($username, $password) = $credentials;
+
+        $row = $this->userRepository->findByUsername($username);
+        if(!$row){
+            throw new AuthenticationException('Uživatel nebyl nalezen.');
+        }
+
+        $hash = md5($password);
+
+        if ($hash !== $row->{UserRepository::COLUMN_PASSWORD})
+        {
+            throw new AuthenticationException('Nesprávné heslo.');
+        }
+
+        $roles = $row->related(UserRoleRepository::TABLE_NAME, UserRoleRepository::COLUMN_USER_ID)
+            ->fetchField(UserRoleRepository::COLUMN_ROLE_ID);
+
+        return new Identity($row->{UserRepository::COLUMN_ID}, $roles);
+    }
+}
\ No newline at end of file
diff --git a/app/model/repository/UserRepository.php b/app/model/repository/UserRepository.php
index 83e395e..212f3f5 100644
--- a/app/model/repository/UserRepository.php
+++ b/app/model/repository/UserRepository.php
@@ -2,6 +2,8 @@
 
 namespace Model\Repository;
 
+use Nette\Database\Table\ActiveRow;
+
 /**
  * Repository pro práci s tabulkou `user`
  *
@@ -21,4 +23,15 @@ class UserRepository extends Repository
     const COLUMN_EMAIL = 'email';
     const COLUMN_CREATED = 'created';
     const COLUMN_UPDATED = 'updated';
+
+    /**
+     * Nalezne uživatele v DB podle uživatelského jména
+     *
+     * @param string $username
+     * @return ActiveRow|false
+     */
+    public function findByUsername(string $username): ActiveRow
+    {
+        return $this->findBy([self::COLUMN_USERNAME => $username])->fetch();
+    }
 }
\ No newline at end of file
diff --git a/docker/conf.d/apache/000-default.conf b/docker/conf.d/apache/000-default.conf
index 1bf19f7..c79a77c 100644
--- a/docker/conf.d/apache/000-default.conf
+++ b/docker/conf.d/apache/000-default.conf
@@ -6,11 +6,16 @@
 	# match this virtual host. For the default virtual host (this file) this
 	# value is not decisive as it is used as a last resort host regardless.
 	# However, you must set it for any further virtual host explicitly.
-	#ServerName www.example.com
-
+	
+	ServerName klinopis.local
 	ServerAdmin fjani@students.zcu.cz 
 	DocumentRoot /var/www/html/www
 
+	<Directory "/var/www/html/www">
+	  Order allow,deny
+	  Allow from all
+	  AllowOverride All
+	</Directory>
 	# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 	# error, crit, alert, emerg.
 	# It is also possible to configure the loglevel for particular
diff --git a/docker/dockerfile b/docker/dockerfile
index 3c1a1f1..3ffbcea 100644
--- a/docker/dockerfile
+++ b/docker/dockerfile
@@ -15,6 +15,7 @@ COPY ./conf.d/apache/000-default.conf /etc/apache2/sites-enabled
 
 ENV COMPOSER_ALLOW_SUPERUSER 1
 RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
+RUN a2enmod rewrite
 
 EXPOSE 80
 
