forked from ecamp/ecamp3
-
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.
In case the first email is lost, you can now send again an activation key, which now may arrive at your email. closes ecamp#4670
- Loading branch information
Showing
17 changed files
with
704 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\DTO; | ||
|
||
use ApiPlatform\Metadata\ApiProperty; | ||
use ApiPlatform\Metadata\ApiResource; | ||
use ApiPlatform\Metadata\Post; | ||
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation; | ||
use App\InputFilter; | ||
use App\State\ResendActivationProcessor; | ||
use Symfony\Component\Serializer\Annotation\Groups; | ||
|
||
#[ApiResource( | ||
operations: [ | ||
new Post( | ||
processor: ResendActivationProcessor::class, | ||
uriTemplate: '/resend_activation{._format}', | ||
security: 'true', | ||
status: 204, | ||
output: false, | ||
denormalizationContext: ['groups' => ['create']], | ||
openapi: new OpenApiOperation(summary: 'Request activation email again', description: 'Activation email will be sent to the given email again.') | ||
), | ||
], | ||
routePrefix: '/auth' | ||
)] | ||
class UserActivation { | ||
#[InputFilter\Trim] | ||
#[ApiProperty(readable: false, writable: true)] | ||
#[Groups(['create'])] | ||
public ?string $email = null; | ||
|
||
#[ApiProperty(readable: false, writable: true)] | ||
#[Groups(['create'])] | ||
public ?string $recaptchaToken = null; | ||
} |
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,59 @@ | ||
<?php | ||
|
||
namespace App\State; | ||
|
||
use ApiPlatform\Metadata\Operation; | ||
use ApiPlatform\State\ProcessorInterface; | ||
use App\DTO\UserActivation; | ||
use App\Entity\User; | ||
use App\Repository\UserRepository; | ||
use App\Security\ReCaptcha\ReCaptchaWrapper; | ||
use App\Service\MailService; | ||
use App\Util\IdGenerator; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\NonUniqueResultException; | ||
use Doctrine\ORM\NoResultException; | ||
use Symfony\Component\HttpKernel\Exception\HttpException; | ||
|
||
/** | ||
* @implements ProcessorInterface<UserActivation,null> | ||
*/ | ||
readonly class ResendActivationProcessor implements ProcessorInterface { | ||
public function __construct( | ||
private ReCaptchaWrapper $reCaptcha, | ||
private EntityManagerInterface $em, | ||
private UserRepository $userRepository, | ||
private MailService $mailService, | ||
) {} | ||
|
||
/** | ||
* @param UserActivation $data | ||
* | ||
* @throws NoResultException | ||
* @throws NonUniqueResultException | ||
*/ | ||
public function process($data, Operation $operation, array $uriVariables = [], array $context = []): null { | ||
$resp = $this->reCaptcha->verify($data->recaptchaToken); | ||
if (!$resp->isSuccess()) { | ||
throw new HttpException(422, 'ReCaptcha failed'); | ||
} | ||
|
||
$user = $this->userRepository->loadUserByIdentifier($data->email); | ||
|
||
if (null == $user) { | ||
return null; | ||
} | ||
|
||
if (User::STATE_REGISTERED !== $user->state) { | ||
return null; | ||
} | ||
|
||
$user->activationKey = IdGenerator::generateRandomHexString(64); | ||
$user->activationKeyHash = md5($user->activationKey); | ||
$this->em->flush(); | ||
|
||
$this->mailService->sendUserActivationMail($user, $user->activationKey); | ||
|
||
return null; | ||
} | ||
} |
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 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 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
Oops, something went wrong.