-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from daniel-de-wit/feature/resend-email-verifi…
…cation Add mutation to resend email verification link
- Loading branch information
Showing
5 changed files
with
579 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 +109,7 @@ Make sure the following middleware is enabled for Lighthouse: | |
- [Logout](#logout) | ||
- [Register](#register) | ||
- [Email Verification](#email-verification) | ||
- [Resend Email Verification Link](#resend-email-verification-link) | ||
- [Forgot Password](#forgot-password) | ||
- [Reset Password](#reset-password) | ||
|
||
|
@@ -220,6 +221,22 @@ mutation VerifyEmail { | |
} | ||
``` | ||
|
||
### Resend Email Verification Link | ||
|
||
```graphql | ||
mutation ResendEmailVerification { | ||
resendEmailVerification(input: { | ||
email: "[email protected]", | ||
verification_url: { | ||
url: "https://my-front-end.com/verify-email?id=__ID__&token=__HASH__" | ||
# Signed: url: "https://my-front-end.com/verify-email?id=__ID__&token=__HASH__&expires=__EXPIRES__&signature=__SIGNATURE__" | ||
} | ||
}) { | ||
status | ||
} | ||
} | ||
``` | ||
|
||
### Forgot Password | ||
|
||
Sends a reset password notification. | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DanielDeWit\LighthouseSanctum\GraphQL\Mutations; | ||
|
||
use DanielDeWit\LighthouseSanctum\Contracts\Services\EmailVerificationServiceInterface; | ||
use DanielDeWit\LighthouseSanctum\Traits\CreatesUserProvider; | ||
use Illuminate\Auth\AuthManager; | ||
use Illuminate\Contracts\Auth\MustVerifyEmail; | ||
use Illuminate\Contracts\Config\Repository as Config; | ||
|
||
class ResendEmailVerification | ||
{ | ||
use CreatesUserProvider; | ||
|
||
protected AuthManager $authManager; | ||
protected Config $config; | ||
protected EmailVerificationServiceInterface $emailVerificationService; | ||
|
||
public function __construct( | ||
AuthManager $authManager, | ||
Config $config, | ||
EmailVerificationServiceInterface $emailVerificationService | ||
) { | ||
$this->authManager = $authManager; | ||
$this->config = $config; | ||
$this->emailVerificationService = $emailVerificationService; | ||
} | ||
|
||
/** | ||
* @param mixed $_ | ||
* @param array<string, mixed> $args | ||
* @return array<string, string> | ||
*/ | ||
public function __invoke($_, array $args): array | ||
{ | ||
$userProvider = $this->createUserProvider(); | ||
|
||
$user = $userProvider->retrieveByCredentials([ | ||
'email' => $args['email'], | ||
]); | ||
|
||
if ($user && $user instanceof MustVerifyEmail && ! $user->hasVerifiedEmail()) { | ||
if (isset($args['verification_url'])) { | ||
$this->emailVerificationService->setVerificationUrl($args['verification_url']['url']); | ||
} | ||
|
||
$user->sendEmailVerificationNotification(); | ||
} | ||
|
||
return [ | ||
'status' => 'EMAIL_SENT', | ||
]; | ||
} | ||
|
||
protected function getAuthManager(): AuthManager | ||
{ | ||
return $this->authManager; | ||
} | ||
|
||
protected function getConfig(): Config | ||
{ | ||
return $this->config; | ||
} | ||
} |
Oops, something went wrong.