-
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.
- Loading branch information
raphaelbadawi
committed
Jul 1, 2021
1 parent
999000a
commit 7ff7955
Showing
5 changed files
with
55 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
|
@@ -3,8 +3,11 @@ | |
namespace App\Controller; | ||
|
||
use App\Entity\Duck; | ||
use App\Entity\ApiToken; | ||
use Symfony\Component\Mime\Email; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Mailer\MailerInterface; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use KnpU\OAuth2ClientBundle\Client\ClientRegistry; | ||
|
@@ -51,8 +54,7 @@ public function profile(EntityManagerInterface $entityManager, ValidatorInterfac | |
$this->denyAccessUnlessGranted('ROLE_USER'); | ||
|
||
if ($request->getMethod() === 'POST') { | ||
$user = $this->getUser(); | ||
$duck = $entityManager->getRepository(Duck::class)->findOneBy(['id' => $user->getId()]); | ||
$duck = $this->getUser(); | ||
$duck->setFirstname(!empty($request->get('first_name')) ? $request->get('first_name') : $duck->getFirstname()); | ||
$duck->setLastName(!empty($request->get('last_name')) ? $request->get('last_name') : $duck->getLastName()); | ||
$duck->setDuckName(!empty($request->get('duck_name')) ? $request->get('duck_name') : $duck->getDuckName()); | ||
|
@@ -125,4 +127,25 @@ public function logout() | |
{ | ||
return $this->redirectToRoute('quacks'); | ||
} | ||
|
||
#[Route('/send_token', name: 'send_token')] | ||
public function sendToken(EntityManagerInterface $entityManager, MailerInterface $mailer): Response | ||
{ | ||
$user = $this->getUser(); | ||
foreach ($user->getApiTokens() as $token) { | ||
if ($token->isExpired()) { | ||
$entityManager->remove($token); | ||
} | ||
} | ||
|
||
$token = new ApiToken($user); | ||
$email = (new Email()) | ||
->from('[email protected]') | ||
->to('[email protected]') | ||
->subject('Your Duck Tales API token!') | ||
->html('<p>Your new API token is ' . $token->getToken() . '</p>'); | ||
|
||
$mailer->send($email); | ||
return $this->redirectToRoute('quacks'); | ||
} | ||
} |
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