fix(user): ensure email attributes are stored in lowercase for consistency and prevent case-related issues

This commit is contained in:
Andras Bacsai
2025-09-05 17:44:34 +02:00
parent 49bd0a2a01
commit 9c3345318a
3 changed files with 21 additions and 3 deletions

View File

@@ -40,7 +40,7 @@ class CreateNewUser implements CreatesNewUsers
$user = User::create([ $user = User::create([
'id' => 0, 'id' => 0,
'name' => $input['name'], 'name' => $input['name'],
'email' => strtolower($input['email']), 'email' => $input['email'],
'password' => Hash::make($input['password']), 'password' => Hash::make($input['password']),
]); ]);
$team = $user->teams()->first(); $team = $user->teams()->first();
@@ -52,7 +52,7 @@ class CreateNewUser implements CreatesNewUsers
} else { } else {
$user = User::create([ $user = User::create([
'name' => $input['name'], 'name' => $input['name'],
'email' => strtolower($input['email']), 'email' => $input['email'],
'password' => Hash::make($input['password']), 'password' => Hash::make($input['password']),
]); ]);
$team = $user->teams()->first(); $team = $user->teams()->first();

View File

@@ -78,6 +78,8 @@ class Index extends Component
'new_email' => ['required', 'email', 'unique:users,email'], 'new_email' => ['required', 'email', 'unique:users,email'],
]); ]);
$this->new_email = strtolower($this->new_email);
// Skip rate limiting in development mode // Skip rate limiting in development mode
if (! isDev()) { if (! isDev()) {
// Rate limit by current user's email (1 request per 2 minutes) // Rate limit by current user's email (1 request per 2 minutes)
@@ -90,7 +92,7 @@ class Index extends Component
} }
// Rate limit by new email address (3 requests per hour per email) // Rate limit by new email address (3 requests per hour per email)
$newEmailKey = 'email-change:email:'.md5(strtolower($this->new_email)); $newEmailKey = 'email-change:email:'.md5($this->new_email);
if (! RateLimiter::attempt($newEmailKey, 3, function () {}, 3600)) { if (! RateLimiter::attempt($newEmailKey, 3, function () {}, 3600)) {
$this->dispatch('error', 'This email address has received too many verification requests. Please try again later.'); $this->dispatch('error', 'This email address has received too many verification requests. Please try again later.');

View File

@@ -56,6 +56,22 @@ class User extends Authenticatable implements SendsEmail
'email_change_code_expires_at' => 'datetime', 'email_change_code_expires_at' => 'datetime',
]; ];
/**
* Set the email attribute to lowercase.
*/
public function setEmailAttribute($value)
{
$this->attributes['email'] = strtolower($value);
}
/**
* Set the pending_email attribute to lowercase.
*/
public function setPendingEmailAttribute($value)
{
$this->attributes['pending_email'] = $value ? strtolower($value) : null;
}
protected static function boot() protected static function boot()
{ {
parent::boot(); parent::boot();