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
1 parent
26b46c2
commit dabbebb
Showing
30 changed files
with
1,009 additions
and
50 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Module\User\Action; | ||
|
||
use App\Module\User\Entity\User; | ||
use App\Module\User\Entity\Token; | ||
use App\Module\User\Repository\TokenRepository; | ||
use App\Module\User\Service\Login as LoginService; | ||
use App\Service\Parameters; | ||
use App\Service\View; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Yiisoft\Auth\IdentityRepositoryInterface; | ||
use Yiisoft\DataResponse\DataResponseFactoryInterface; | ||
use Yiisoft\Router\UrlGeneratorInterface; | ||
|
||
final class Confirm | ||
{ | ||
public function confirm( | ||
Parameters $app, | ||
IdentityRepositoryInterface $identityRepository, | ||
LoginService $loginService, | ||
ServerRequestInterface $request, | ||
DataResponseFactoryInterface $responseFactory, | ||
TokenRepository $tokenRepository, | ||
UrlGeneratorInterface $url, | ||
View $view | ||
): ResponseInterface { | ||
$id = (string) $request->getAttribute('id'); | ||
$code = $request->getAttribute('code'); | ||
$ip = $request->getServerParams()['REMOTE_ADDR']; | ||
$user = null; | ||
$token = null; | ||
|
||
if ($id !== null) { | ||
$user = $identityRepository->findIdentity($id); | ||
} | ||
|
||
if ($user !== null && $code !== null) { | ||
$token = $tokenRepository->findTokenByParams( | ||
(int) $user->getId(), | ||
$code, | ||
Token::TYPE_CONFIRMATION | ||
); | ||
} | ||
|
||
if ( | ||
$user === null || | ||
!$token instanceof Token || | ||
$token->isExpired($app->get('user.tokenConfirmWithin')) | ||
) { | ||
$view->addFlash( | ||
'is-danger', | ||
$app->get('user.messageHeader'), | ||
'The requested page does not exist.' | ||
); | ||
|
||
return $responseFactory | ||
->createResponse(302) | ||
->withHeader('Location', $url->generate('index')); | ||
} | ||
|
||
if ( | ||
$user !== null | ||
&& $token instanceof Token | ||
&& $loginService->isLoginConfirm($identityRepository, $id, $ip) | ||
&& !$token->isExpired($app->get('user.tokenConfirmWithin')) | ||
) { | ||
$token->delete(); | ||
|
||
/** @var User $user */ | ||
$user->updateAttributes([ | ||
'unconfirmed_email' => null, | ||
'confirmed_at' => time() | ||
]); | ||
|
||
$view->addFlash( | ||
'is-success', | ||
$app->get('user.messageHeader'), | ||
'Your user has been confirmed.' | ||
); | ||
} | ||
|
||
return $responseFactory | ||
->createResponse(302) | ||
->withHeader('Location', $url->generate('index')); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Module\User\Action; | ||
|
||
use App\Module\User\Form\Resend as ResendForm; | ||
use App\Module\User\Service\Resend as ResendService; | ||
use App\Service\Parameters; | ||
use App\Service\View; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Yiisoft\Auth\IdentityRepositoryInterface; | ||
use Yiisoft\DataResponse\DataResponseFactoryInterface; | ||
use Yiisoft\Router\UrlGeneratorInterface; | ||
|
||
final class Resend | ||
{ | ||
public function resend( | ||
Parameters $app, | ||
IdentityRepositoryInterface $identityRepository, | ||
ResendForm $resendForm, | ||
ResendService $resendService, | ||
DataResponseFactoryInterface $responseFactory, | ||
ServerRequestInterface $request, | ||
UrlGeneratorInterface $url, | ||
View $view | ||
): ResponseInterface { | ||
$body = $request->getParsedBody(); | ||
$method = $request->getMethod(); | ||
|
||
if ( | ||
$method === 'POST' | ||
&& $resendForm->load($body) | ||
&& $resendForm->validate() | ||
&& $resendService->run($resendForm, $identityRepository) | ||
) { | ||
$view->addFlash( | ||
'is-warning', | ||
$app->get('user.messageHeader'), | ||
'Please check your email to activate your username.' | ||
); | ||
|
||
return $responseFactory | ||
->createResponse(302) | ||
->withHeader('Location', $url->generate('index')); | ||
} | ||
|
||
return $view | ||
->viewPath('@user/resources/views') | ||
->renderWithLayout('/registration/resend', ['data' => $resendForm]); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Module\User\Asset; | ||
|
||
use Yiisoft\Assets\AssetBundle; | ||
use Yiisoft\Yii\Bulma\Asset\BulmaAsset; | ||
|
||
final class Resend extends AssetBundle | ||
{ | ||
public ?string $basePath = '@assets'; | ||
public ?string $baseUrl = '@assetsUrl'; | ||
public ?string $sourcePath = '@user/resources/asset/css'; | ||
|
||
public array $css = [ | ||
'resend.css', | ||
]; | ||
|
||
public array $depends = [ | ||
BulmaAsset::class | ||
]; | ||
} |
Oops, something went wrong.