From b63f9f305b41e463e28cbe57cc78ce3914f5a8f9 Mon Sep 17 00:00:00 2001 From: Pious Sutherland Date: Sat, 6 Apr 2024 22:24:56 +0200 Subject: [PATCH 1/3] Remove Plusses from email to prevent reusing the same email for different accounts. --- app/Models/User.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index 5ff54f8..51e880f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -35,6 +35,23 @@ public function setPasswordAttribute($password) $this->attributes['password'] = bcrypt($password); } + public function setEmailAttribute($email) + { + // Deconstruct + $parts = explode('@', $email); + + // Find '+' + $firstPart = $parts[0]; + $plusIndex = strpos($firstPart, '+'); + + // Truncate '+' and everything after it in the username + if ($plusIndex) + $firstPart = substr($firstPart, 0, $plusIndex); + + // return (new) username@domain + return $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); + } + public function posts() { return $this->hasMany(Post::class); From eced4709a221431b8a6d48b525270ce3fd8eb534 Mon Sep 17 00:00:00 2001 From: Pious Sutherland Date: Tue, 9 Apr 2024 13:35:17 +0200 Subject: [PATCH 2/3] Update User.php --- app/Models/User.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 51e880f..1544f8a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -39,19 +39,19 @@ public function setEmailAttribute($email) { // Deconstruct $parts = explode('@', $email); - + // Find '+' $firstPart = $parts[0]; $plusIndex = strpos($firstPart, '+'); - + // Truncate '+' and everything after it in the username if ($plusIndex) $firstPart = substr($firstPart, 0, $plusIndex); - + // return (new) username@domain - return $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); + $this->email = $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); } - + public function posts() { return $this->hasMany(Post::class); From 62d8f4b8610d6f38b16698e36a22211b181630ba Mon Sep 17 00:00:00 2001 From: Pious Sutherland Date: Tue, 9 Apr 2024 13:36:26 +0200 Subject: [PATCH 3/3] Fix 'email' mistake --- app/Models/User.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 1544f8a..9b64c45 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -49,7 +49,7 @@ public function setEmailAttribute($email) $firstPart = substr($firstPart, 0, $plusIndex); // return (new) username@domain - $this->email = $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); + $this->attributes['email'] = $firstPart . '@' . (isset($parts[1]) ? $parts[1] : null); } public function posts()