diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 55c625f..83ed862 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -35,8 +35,9 @@ protected function validator(array $data): \Illuminate\Validation\Validator /** * Create a new user instance after a valid registration. * - * @param array $data + * @param array $data * @return Account + * @throws \Throwable */ protected function create(array $data): Account { @@ -50,6 +51,35 @@ protected function create(array $data): Account return $account; } + /** + * Executes the registration logic on a validator input + * + * @param \Illuminate\Validation\Validator $validator + * @return RedirectResponse + * @throws ValidationException + * @throws \Throwable + */ + protected function runRegistrationLogic(\Illuminate\Validation\Validator $validator): RedirectResponse + { + // Validate the input + if ($validator->fails()) { + return redirect('user/register') + ->withErrors($validator) + ->withInput($validator->getData()); + } + + // Retrieve the validated input + $validated = $validator->validated(); + + // Attempt to create the account and emit the event + event(new Registered($user = $this->create($validated))); + + // Authenticate the user + Auth::guard()->login($user); + + return redirect('user/verification/notice'); + } + /** * Show the application registration form. * @@ -65,16 +95,31 @@ public function showRegistrationForm(): View * * @param Request $request * @return RedirectResponse - * @throws ValidationException + * @throws \Throwable */ - public function register(Request $request) + public function register(Request $request): RedirectResponse { - $this->validator($request->all())->validate(); + $validator = $this->validator($request->all()); + return $this->runRegistrationLogic($validator); + } - event(new Registered($user = $this->create($request->all()))); + /** + * Handle a registration request for the application. + * + * @param Request $request + * @return RedirectResponse + * @throws \Throwable + */ + public function registerFromHeader(Request $request): RedirectResponse + { + $requestData = $request->all(); + $validator = $this->validator([ + 'login' => $requestData['header-form-login'] ?? null, + 'email' => $requestData['header-form-email'] ?? null, + 'password' => $requestData['header-form-password'] ?? null, + 'tac' => $requestData['header-form-tac'] ?? null, + ]); - Auth::guard()->login($user); - - return redirect('user/verification/notice'); + return $this->runRegistrationLogic($validator); } } diff --git a/lang/en/app/register.php b/lang/en/app/register.php new file mode 100644 index 0000000..2c716a4 --- /dev/null +++ b/lang/en/app/register.php @@ -0,0 +1,31 @@ + 'Register', + 'subtitle' => 'Create an account', + + 'progress-texts.register' => 'Register', + 'progress-texts.activate-download' => 'Activate and download', + 'progress-texts.install-play' => 'Install and play', + + 'to-login' => 'or Login', + + 'form.username' => 'Username', + 'form.email' => 'Email', + 'form.password' => 'Password', + 'form.password-requirements' => 'Requirements', + 'form.terms-and-conditions' => 'I have read the [**Terms and Conditions**](:termsUrl) and the [**Privacy Policy**](:privacyUrl) and accept them.', + + 'form.password-info.header' => 'A safe password must contain', + 'form.password-info.rule-1' => 'between 5 and 16 characters', + 'form.password-info.rule-2' => 'or at least one lowercase letter', + 'form.password-info.rule-3' => 'at least one uppercase letter', + 'form.password-info.rule-4' => 'at least one digit', + 'form.password-info.rule-5' => 'at least one special character', + 'form.password-info.special-chars' => 'Allowed special characters', + + 'form.password-security' => "Your password's security level", + 'form.required' => '* is required', + + 'form.register-btn' => 'Register', +]; diff --git a/lang/ro/app/register.php b/lang/ro/app/register.php new file mode 100644 index 0000000..76fc58d --- /dev/null +++ b/lang/ro/app/register.php @@ -0,0 +1,31 @@ + 'Înregistrare', + 'subtitle' => 'Creează un cont', + + 'progress-texts.register' => 'Înregistrare', + 'progress-texts.activate-download' => 'Activează și descarcă', + 'progress-texts.install-play' => 'Instalează și joacă-te', + + 'to-login' => 'sau Autentifică-te', + + 'form.username' => 'Nume de utilizator', + 'form.email' => 'Email', + 'form.password' => 'Parola', + 'form.password-requirements' => 'Reguli parolă', + 'form.terms-and-conditions' => 'Am citit [**Termenii și Condițiile**](:termsUrl) și [**Politica de Confidențialitate**](:privacyUrl), și le accept.', + + 'form.password-info.header' => 'O parolă sigură conține', + 'form.password-info.rule-1' => 'între 5 și 16 caractere', + 'form.password-info.rule-2' => 'sau cel puțin o literă mică', + 'form.password-info.rule-3' => 'cel puțin o literă mare', + 'form.password-info.rule-4' => 'cel puțin o cifră', + 'form.password-info.rule-5' => 'cel puțin un caracter special', + 'form.password-info.special-chars' => 'Caractere speciale permise', + + 'form.password-security' => 'Nivelul de securitate al parolei tale', + 'form.required' => '* este necesar', + + 'form.register-btn' => 'Înregistrare', +]; diff --git a/resources/views/components/registration/progress.blade.php b/resources/views/components/registration/progress.blade.php index 09869f2..13481d7 100644 --- a/resources/views/components/registration/progress.blade.php +++ b/resources/views/components/registration/progress.blade.php @@ -1,8 +1,8 @@