예제 #1
0
 public function __construct(User $user, DTOBuilderFactoryInterface $dtoBuilderFactory)
 {
     $this->entity = $user;
     $this->dtoBuilderFactory = $dtoBuilderFactory;
     $this->entityDTO = $this->getEntityDTO();
     $this->setId();
     $this->setTime();
     $this->entityDTO->externalId = $this->entity->getExternalId();
     $this->entityDTO->email = $this->entity->getEmail();
     $this->entityDTO->firstName = $this->entity->getFirstName();
     $this->entityDTO->lastName = $this->entity->getLastName();
     $this->entityDTO->totalLogins = $this->entity->getTotalLogins();
     $this->entityDTO->lastLogin = $this->entity->getLastLogin();
     $this->entityDTO->status = $this->dtoBuilderFactory->getUserStatusTypeDTOBuilder($this->entity->getStatus())->build();
 }
예제 #2
0
 /**
  * @param User $user
  * @param string $token
  * @param string $userAgent
  * @param string $ip4
  * @return self
  */
 public static function createResetPasswordToken(User $user, $token, $userAgent, $ip4)
 {
     $expires = new DateTime('+1 hour');
     $userToken = new self($user, UserTokenType::internal(), $token, $userAgent, $ip4, $expires);
     $userToken->raise(new ResetPasswordEvent($user->getId(), $user->getEmail(), $user->getFullName(), $token));
     return $userToken;
 }
예제 #3
0
 public function testSetPasswordRaisesEvent()
 {
     $user = new User();
     $user->setEmail('*****@*****.**');
     $user->setPassword('Password1');
     $this->assertSame(0, count($user->releaseEvents()));
     $user->setPassword('NewPassword123');
     /** @var PasswordChangedEvent $event */
     $event = $user->releaseEvents()[0];
     $this->assertTrue($event instanceof PasswordChangedEvent);
     $this->assertSame($user->getId(), $event->getUserId());
     $this->assertSame($user->getEmail(), $event->getEmail());
     $this->assertSame($user->getFullName(), $event->getFullName());
 }
 /**
  * @param User $user
  * @param string $password
  * @throws UserPasswordValidationException
  */
 public function assertPasswordValid(User $user, $password)
 {
     if (strlen($password) < 8) {
         throw new UserPasswordValidationException('Password must be at least 8 characters');
     }
     if ($user->verifyPassword($password)) {
         throw new UserPasswordValidationException('Invalid password');
     }
     $tooSimilarValues = [$user->getFirstName(), $user->getLastName(), $user->getFullName(), $user->getEmail()];
     foreach ($tooSimilarValues as $text) {
         if ($this->isTooSimilar($password, $text)) {
             throw new UserPasswordValidationException('Password is too similar to your name or email');
         }
     }
 }