-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* IBX-3201: Added invitation email validation * IBX-3201: Refreshing invitations now also changes hash of it * IBX-3361: Increased hash expiration date to 7 days
- Loading branch information
Showing
12 changed files
with
117 additions
and
11 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
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
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
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
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
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,29 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\User\Validator\Constraints; | ||
|
||
use JMS\TranslationBundle\Model\Message; | ||
use JMS\TranslationBundle\Translation\TranslationContainerInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
|
||
/** | ||
* @Annotation | ||
*/ | ||
class EmailInvitation extends Constraint implements TranslationContainerInterface | ||
{ | ||
public string $message = 'ibexa.user.invitation.user_with_email_exists'; | ||
|
||
public static function getTranslationMessages() | ||
{ | ||
return [ | ||
Message::create('ibexa.user.invitation.user_with_email_exists', 'validators') | ||
->setDesc("The email '%email%' is already in your member list."), | ||
]; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/lib/Validator/Constraints/EmailInvitationValidator.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,40 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\User\Validator\Constraints; | ||
|
||
use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; | ||
use Ibexa\Contracts\Core\Repository\UserService; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\ConstraintValidator; | ||
|
||
class EmailInvitationValidator extends ConstraintValidator | ||
{ | ||
private UserService $userService; | ||
|
||
public function __construct(UserService $userService) | ||
{ | ||
$this->userService = $userService; | ||
} | ||
|
||
/** | ||
* Checks if the passed value is valid. | ||
* | ||
* @param string $email The value that should be validated | ||
* @param \Symfony\Component\Validator\Constraint $constraint The constraint for the validation | ||
*/ | ||
public function validate($email, Constraint $constraint) | ||
{ | ||
try { | ||
$this->userService->loadUserByEmail($email); | ||
$this->context->addViolation($constraint->message, ['%email%' => $email]); | ||
} catch (NotFoundException $exception) { | ||
// Do nothing | ||
} | ||
} | ||
} |
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