-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
event subscriber to check online users
- Loading branch information
Showing
7 changed files
with
68 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\EventSubscriber; | ||
|
||
use App\Entity\User; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | ||
use Symfony\Component\Security\Core\Security; | ||
use Symfony\Component\HttpKernel\Event\RequestEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
|
||
class UserLastConnectionSubscriber implements EventSubscriberInterface | ||
{ | ||
private $security; | ||
private $entityManager; | ||
|
||
public function __construct(Security $security, EntityManagerInterface $entityManager) | ||
{ | ||
$this->security = $security; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
{ | ||
return [ | ||
KernelEvents::REQUEST => 'onKernelRequest' | ||
]; | ||
} | ||
|
||
public function onKernelRequest(RequestEvent $event) | ||
{ | ||
$user = $this->security->getUser(); | ||
|
||
if ($user instanceof User) { | ||
$user->setLastConnection(new \DateTime()); | ||
$this->entityManager->persist($user); | ||
$this->entityManager->flush(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,23 @@ | ||
{% extends 'base.html.twig' %} | ||
|
||
{% block title %}Register{% endblock %} | ||
{% block title %}Register | ||
{% endblock %} | ||
|
||
{% block body %} | ||
{% for flash_error in app.flashes('verify_email_error') %} | ||
<div class="alert alert-danger" role="alert">{{ flash_error }}</div> | ||
{% endfor %} | ||
{% for flash_error in app.flashes('verify_email_error') %} | ||
<div class="alert alert-danger" role="alert">{{ flash_error }}</div> | ||
{% endfor %} | ||
|
||
<h1>Register</h1> | ||
<h1>Register</h1> | ||
|
||
{{ form_start(registrationForm) }} | ||
{{ form_row(registrationForm.email) }} | ||
{{ form_row(registrationForm.plainPassword, { | ||
{{ form_start(registrationForm) }} | ||
{{ form_row(registrationForm.email) }} | ||
{{ form_row(registrationForm.username) }} | ||
{{ form_row(registrationForm.plainPassword, { | ||
label: 'Password' | ||
}) }} | ||
{{ form_row(registrationForm.agreeTerms) }} | ||
{{ form_row(registrationForm.agreeTerms) }} | ||
|
||
<button type="submit" class="btn">Register</button> | ||
{{ form_end(registrationForm) }} | ||
<button type="submit" class="btn">Register</button> | ||
{{ form_end(registrationForm) }} | ||
{% endblock %} |