mirror of
https://github.com/kevinveenbirkenbach/coding-challenge-online-shop.git
synced 2025-09-09 11:27:13 +02:00
Implemented login
This commit is contained in:
@@ -3,6 +3,10 @@ namespace controller\user;
|
||||
|
||||
use controller\AbstractDefaultController;
|
||||
use router\Router;
|
||||
use controller\AbstractController;
|
||||
use core\CoreInterface;
|
||||
use repository\user\User as UserRepository;
|
||||
use entity\user\User as UserEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -11,24 +15,50 @@ use router\Router;
|
||||
*/
|
||||
final class User extends AbstractDefaultController implements UserInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var UserRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
public function __construct(CoreInterface $core)
|
||||
{
|
||||
parent::__construct($core);
|
||||
$this->repository = new UserRepository($core);
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
$this->core->setUser(null);
|
||||
$router = new Router();
|
||||
$router->setCore($this->core);
|
||||
$router->setGet([]);
|
||||
$router->route();
|
||||
$this->route();
|
||||
}
|
||||
|
||||
public function login(): void
|
||||
{
|
||||
$this->render('user/login.html.twig');
|
||||
if ($this->post) {
|
||||
try {
|
||||
$this->loginRoutine();
|
||||
} catch (\Exception $exception) {
|
||||
$this->render('frames/exception.html.twig',['message'=>$exception->getMessage()]);
|
||||
}
|
||||
} else {
|
||||
$this->render('user/login.html.twig');
|
||||
}
|
||||
}
|
||||
|
||||
private function loginRoutine(): void
|
||||
{
|
||||
$requestedUser = new UserEntity();
|
||||
$requestedUser->setPasswordHashByPassword($this->post['password']);
|
||||
$requestedUser->setEmail($this->post['email']);
|
||||
$this->core->setUser($this->repository->getUserByMailAndHash($requestedUser));
|
||||
$this->route();
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$this->render('user/register.html.twig');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user