Skip to content

Commit

Permalink
Prevent empty username fields from being added to requests (#590)
Browse files Browse the repository at this point in the history
  • Loading branch information
edvardsr authored Jan 24, 2025
1 parent b3c7b42 commit fe9ddfc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/Actions/CanonicalizeUsername.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ class CanonicalizeUsername
*/
public function handle($request, $next)
{
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
if ($request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
}

return $next($request);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/PasswordResetLinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function store(Request $request): Responsable
{
$request->validate([Fortify::email() => 'required|email']);

if (config('fortify.lowercase_usernames')) {
if (config('fortify.lowercase_usernames') && $request->has(Fortify::email())) {
$request->merge([
Fortify::email() => Str::lower($request->{Fortify::email()}),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/ProfileInformationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ProfileInformationController extends Controller
public function update(Request $request,
UpdatesUserProfileInformation $updater)
{
if (config('fortify.lowercase_usernames')) {
if (config('fortify.lowercase_usernames') && $request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function create(Request $request): RegisterViewResponse
public function store(Request $request,
CreatesNewUsers $creator): RegisterResponse
{
if (config('fortify.lowercase_usernames')) {
if (config('fortify.lowercase_usernames') && $request->has(Fortify::username())) {
$request->merge([
Fortify::username() => Str::lower($request->{Fortify::username()}),
]);
Expand Down

0 comments on commit fe9ddfc

Please sign in to comment.