diff --git a/Changelog b/Changelog index a9f8c8870..dee703567 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-09-07 DariusIII + * Fix: Fix displaying errors on registration page * Fix: Display login errors * Chg: Update ytake/laravel-smarty to version 2.4.0 2018-09-06 DariusIII diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index e195c908c..a067dc065 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Auth; use App\Models\User; use App\Models\Settings; use App\Models\Invitation; +use Illuminate\Support\Facades\Validator; use Illuminate\Support\Str; use Illuminate\Http\Request; use Blacklight\utility\Utility; @@ -86,7 +87,7 @@ class RegisterController extends Controller $error = $userName = $password = $confirmPassword = $email = $inviteCode = $inviteCodeQuery = ''; $showRegister = 1; - $this->validate($request, [ + $validator = Validator::make($request->all(), [ 'username' => 'required|string|min:5|max:255|unique:users', 'email' => 'required|string|email|max:255|unique:users', 'password' => 'required|string|min:8|confirmed|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$/', @@ -98,12 +99,13 @@ class RegisterController extends Controller ]); } - if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_CLOSED) { - session()->flash('status', 'Registrations are currently disabled.'); - $showRegister = 0; - } elseif (Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE && (! $request->has('invitecode') || empty($request->input('invitecode')))) { - session()->flash('status', 'Registrations are currently invite only.'); - $showRegister = 0; + if ($validator->fails()) { + return $this->showRegistrationForm($validator->errors()->first()); + } + + if (Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE && (! $request->has('invitecode') || empty($request->input('invitecode')))) { + $error = 'Registrations are currently invite only.'; + return $this->showRegistrationForm($error); } if ($showRegister === 1) { @@ -134,6 +136,9 @@ class RegisterController extends Controller break; } } + if (!empty($error)) { + return $this->showRegistrationForm($error); + } $user = $this->create( [ @@ -181,16 +186,28 @@ class RegisterController extends Controller 'invitecode' => Utility::htmlfmt($inviteCode), 'invite_code_query' => Utility::htmlfmt($inviteCodeQuery), 'showregister' => $showRegister, - 'error' => $error, ] ); + + return $this->showRegistrationForm($error); } /** - * @throws \Exception + * @param string $error */ - public function showRegistrationForm() + public function showRegistrationForm($error = '') { + $showRegister = 1; + if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_CLOSED) { + $error = 'Registrations are currently disabled.'; + $showRegister = 0; + } + if ((int) Settings::settingValue('..registerstatus') === Settings::REGISTER_STATUS_INVITE) { + $error = 'Registrations are currently invite only.'; + $showRegister = 0; + } + app('smarty.view')->assign('showregister', $showRegister); + app('smarty.view')->assign('error', $error); $theme = Settings::settingValue('site.main.style'); $nocaptcha = env('NOCAPTCHA_ENABLED'); diff --git a/resources/views/themes/Gentele/register.tpl b/resources/views/themes/Gentele/register.tpl index 6c3acfd8c..d7f24455a 100755 --- a/resources/views/themes/Gentele/register.tpl +++ b/resources/views/themes/Gentele/register.tpl @@ -8,7 +8,7 @@ {if isset($sent) && $sent != ''}
A link to reset your password has been sent to your e-mail account.
{/if} - {if $showregister != "0"} + {if $showregister == 1}