-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#35: Ajout des champ date de création de compte et dernière activité
- Loading branch information
1 parent
d08da27
commit f7847b4
Showing
6 changed files
with
177 additions
and
82 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 |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
use App\Repository\CustomerRepository; | ||
use App\Repository\OptionsRepository; | ||
use App\Service\Services; | ||
use Doctrine\Common\Persistence\ObjectManager; | ||
use DateTime; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use function Sodium\add; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
@@ -29,6 +30,7 @@ class SecurityController extends AbstractController | |
private $utils; | ||
private $adminMail = "[email protected]"; | ||
private $options; | ||
private $manager; | ||
|
||
/** | ||
* SecurityController constructor. | ||
|
@@ -37,10 +39,12 @@ class SecurityController extends AbstractController | |
*/ | ||
public function __construct( | ||
AuthenticationUtils $utils, | ||
OptionsRepository $options | ||
OptionsRepository $options, | ||
EntityManagerInterface $manager | ||
) { | ||
$this->utils = $utils; | ||
$this->options = $options; | ||
$this->manager = $manager; | ||
} | ||
|
||
/** | ||
|
@@ -110,6 +114,10 @@ public function index( | |
); | ||
|
||
if ($this->getUser()) { | ||
($this->getUser())->setLastActivityAt(new DateTime()); | ||
$this->manager->persist($this->getUser()); | ||
$this->manager->flush(); | ||
|
||
if ($this->getUser()->getRole() == 'ROLE_USER') { | ||
return $this->redirectToRoute('user_home'); | ||
} elseif ($this->getUser()->getRole() == 'ROLE_ADMIN') { | ||
|
@@ -212,9 +220,11 @@ public function create( | |
$hash = $encoder->encodePassword($customer, $customer->getPassword()); | ||
if ($customerRepository->findAll()) { | ||
$customer->setPassword($hash) | ||
->setCreatedAt(new DateTime()) | ||
->setRole('ROLE_USER'); | ||
} else { | ||
$customer->setPassword($hash) | ||
->setCreatedAt(new DateTime()) | ||
->setRole('ROLE_ADMIN'); | ||
} | ||
|
||
|
Oops, something went wrong.