-
-
Save SerafimArts/58246816dc3d8e650ed5d06e5bc8cd22 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* This file is part of id.laravel.su package. | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. | |
*/ | |
declare(strict_types=1); | |
namespace App\Http\Controllers\Auth; | |
use App\Entity\User; | |
use App\Entity\UserInfo; | |
use App\Http\Requests\RegistrationEmailVerification; | |
use App\Http\Requests\RegistrationNicknameVerification; | |
use App\Http\Requests\RegistrationRequest; | |
use Illuminate\Contracts\Auth\Guard as GuardInterface; | |
use Illuminate\Contracts\Auth\PasswordBroker; | |
use Illuminate\Contracts\Auth\StatefulGuard as StatefulGuardInterface; | |
use Illuminate\Contracts\Session\Session as SessionInterface; | |
use Illuminate\Contracts\View\Factory as ViewsFactoryInterface; | |
use Illuminate\Contracts\View\View as ViewInterface; | |
use Illuminate\Http\RedirectResponse; | |
use Illuminate\Routing\Redirector; | |
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; | |
/** | |
* Class RegistrationController | |
* @package App\Http\Controllers\Auth | |
*/ | |
class RegistrationController | |
{ | |
/** | |
* @var GuardInterface|StatefulGuardInterface | |
*/ | |
private $guard; | |
/** | |
* OAuthController constructor. | |
* @param GuardInterface $guard | |
*/ | |
public function __construct(GuardInterface $guard) | |
{ | |
$this->guard = $guard; | |
} | |
/** | |
* @param ViewsFactoryInterface $views | |
* @param SessionInterface $session | |
* @return ViewInterface | |
*/ | |
public function index(ViewsFactoryInterface $views, SessionInterface $session): ViewInterface | |
{ | |
return $views->make('pages.login.registration', [ | |
'user' => $session->get('user', []), | |
]); | |
} | |
/** | |
* @param RegistrationRequest $request | |
* @param Redirector $redirect | |
* @return RedirectResponse | |
* @throws \InvalidArgumentException | |
*/ | |
public function store(RegistrationRequest $request, Redirector $redirect): RedirectResponse | |
{ | |
$user = new User($request->only('nickname', 'email')); | |
$user->password = $request->get('password'); | |
$user->save(); | |
$user->info()->save(new UserInfo()); | |
$this->guard->login($user, true); | |
return $redirect->route('home'); | |
} | |
/** | |
* @param PasswordBroker|\Illuminate\Auth\Passwords\PasswordBroker $broker | |
* @param Redirector $redirect | |
* @param string $id | |
* @param string $token | |
* @return RedirectResponse | |
* @throws UnprocessableEntityHttpException | |
* @throws \InvalidArgumentException | |
*/ | |
public function confirm(PasswordBroker $broker, Redirector $redirect, string $id, string $token): RedirectResponse | |
{ | |
/** @var User|null $user */ | |
$user = User::find((int)$id); | |
if (! $user || ! $broker->tokenExists($user, $token)) { | |
throw new UnprocessableEntityHttpException( | |
'Error while processing user verification. ' . | |
'Probably token is broken or expired.' | |
); | |
} | |
$user->confirm()->save(); | |
$broker->deleteToken($user); | |
return $redirect->route('home'); | |
} | |
/** | |
* @param RegistrationNicknameVerification $request | |
* @return bool | |
*/ | |
public function verifyNickname(RegistrationNicknameVerification $request): bool | |
{ | |
return true; | |
} | |
/** | |
* @param RegistrationEmailVerification $request | |
* @return bool | |
*/ | |
public function verifyEmail(RegistrationEmailVerification $request): bool | |
{ | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment