forked from apiato/apiato
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improve-email-verification-process'
- Loading branch information
Showing
106 changed files
with
2,803 additions
and
3,216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/Containers/AppSection/Authentication/Actions/ForgotPasswordAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Actions; | ||
|
||
use App\Containers\AppSection\Authentication\Mails\UserForgotPasswordMail; | ||
use App\Containers\AppSection\Authentication\Tasks\CreatePasswordResetTokenTask; | ||
use App\Containers\AppSection\Authentication\UI\API\Requests\ForgotPasswordRequest; | ||
use App\Containers\AppSection\User\Tasks\FindUserByEmailTask; | ||
use App\Ship\Parents\Actions\Action; | ||
use App\Ship\Parents\Exceptions\Exception; | ||
use Illuminate\Support\Facades\Mail; | ||
|
||
class ForgotPasswordAction extends Action | ||
{ | ||
public function run(ForgotPasswordRequest $request): bool | ||
{ | ||
$sanitizedData = $request->sanitizeInput([ | ||
'email', | ||
'reseturl', | ||
]); | ||
|
||
// Note: It's a good idea to DON'T say if the user email is valid or not | ||
// (to avoid brute force checking of user email existing). | ||
// so we return 'false' if an exception is thrown | ||
try { | ||
$user = app(FindUserByEmailTask::class)->run($sanitizedData['email']); | ||
} catch (Exception) { | ||
return false; | ||
} | ||
|
||
$token = app(CreatePasswordResetTokenTask::class)->run($user); | ||
|
||
Mail::send(new UserForgotPasswordMail($user, $token, $sanitizedData['reseturl'])); | ||
|
||
return true; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/Containers/AppSection/Authentication/Actions/GetAuthenticatedUserAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Actions; | ||
|
||
use App\Containers\AppSection\Authentication\UI\API\Requests\GetAuthenticatedUserRequest; | ||
use App\Ship\Parents\Actions\Action; | ||
use Illuminate\Contracts\Auth\Authenticatable; | ||
|
||
class GetAuthenticatedUserAction extends Action | ||
{ | ||
public function run(GetAuthenticatedUserRequest $request): Authenticatable | ||
{ | ||
return $request->user(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/Containers/AppSection/Authentication/Actions/SendVerificationEmailAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Actions; | ||
|
||
use App\Containers\AppSection\Authentication\Tasks\SendVerificationEmailTask; | ||
use App\Containers\AppSection\Authentication\UI\API\Requests\SendVerificationEmailRequest; | ||
use App\Ship\Parents\Actions\Action; | ||
|
||
class SendVerificationEmailAction extends Action | ||
{ | ||
public function run(SendVerificationEmailRequest $request): void | ||
{ | ||
app(SendVerificationEmailTask::class)->run($request->user()); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/Containers/AppSection/Authentication/Actions/VerifyEmailAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Actions; | ||
|
||
use App\Containers\AppSection\Authentication\UI\API\Requests\VerifyEmailRequest; | ||
use App\Ship\Parents\Actions\Action; | ||
use Illuminate\Auth\Events\Verified; | ||
|
||
class VerifyEmailAction extends Action | ||
{ | ||
public function run(VerifyEmailRequest $request): void | ||
{ | ||
if (!$request->user()->hasVerifiedEmail()) { | ||
$request->user()->markEmailAsVerified(); | ||
|
||
event(new Verified($request->user())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ns/InvalidResetPasswordTokenException.php → ...ns/InvalidResetPasswordTokenException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
20 changes: 8 additions & 12 deletions
20
...ion/User/Mails/UserForgotPasswordMail.php → ...tication/Mails/UserForgotPasswordMail.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 0 additions & 61 deletions
61
app/Containers/AppSection/Authentication/Middlewares/EnsureEmailIsVerified.php
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
app/Containers/AppSection/Authentication/Notifications/VerifyEmail.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace App\Containers\AppSection\Authentication\Notifications; | ||
|
||
use App\Ship\Parents\Models\UserModel; | ||
use App\Ship\Parents\Notifications\Notification; | ||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
|
||
class VerifyEmail extends Notification implements ShouldQueue | ||
{ | ||
use Queueable; | ||
|
||
public function via($notifiable): array | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
public function toMail(UserModel $notifiable): MailMessage | ||
{ | ||
return (new MailMessage()) | ||
->subject('Verify Email Address') | ||
->line('Please click the button below to verify your email address.') | ||
->action('Verify Email Address', $this->createUrl($notifiable)) | ||
->line('If you did not create an account, no further action is required.'); | ||
} | ||
|
||
private function createUrl(UserModel $notifiable): string | ||
{ | ||
$id = config('apiato.hash-id') ? $notifiable->getHashedKey() : $notifiable->getKey(); | ||
$hash = sha1($notifiable->getEmailForVerification()); | ||
|
||
return request('verification_url') . "/$id/$hash"; | ||
} | ||
} |
Oops, something went wrong.