Exemplo n.º 1
0
 public function testUserIsDisabled()
 {
     $user = new User('*****@*****.**');
     $user->setEnabled(false);
     $this->assertFalse($user->isEnabled());
     $user->setEnabled(true);
     $this->assertTrue($user->isEnabled());
 }
Exemplo n.º 2
0
 /**
  * Constructor.
  *
  * @param mixed $email An array of users or email string
  * @param array $credentials A map of usernames with
  */
 public function __construct($email = null, array $credentials = array())
 {
     if (is_array($email)) {
         $this->constructOAuth($email, $credentials);
     } else {
         parent::__construct($email);
     }
 }
Exemplo n.º 3
0
 public function validate()
 {
     $errors = parent::validate();
     if ($this->getTwitterUsername() && strpos($this->getTwitterUsername(), '@') !== 0) {
         $errors['twitterUsername'] = '******';
     }
     return $errors;
 }
Exemplo n.º 4
0
 public function testSendConfirmationMessage()
 {
     $this->mailer->setFromAddress('*****@*****.**');
     $this->mailer->setFromName('From Name');
     $user = new User('*****@*****.**');
     $this->swiftmailer->expects($this->once())->method('send')->with($this->callback(function ($message) use($user) {
         if (!$message instanceof \Swift_Message) {
             return false;
         }
         $msg = $message->toString();
         $patterns = array('/From: From Name <*****@*****.**>/', '/To: to@example.com/', '/Hello, ' . $user->getName() . '/');
         foreach ($patterns as $pattern) {
             if (!preg_match($pattern, $msg)) {
                 echo 'Message failed to match pattern "' . $pattern . '".';
                 return false;
             }
         }
         return true;
     }));
     $this->mailer->sendConfirmationMessage($user);
 }
 public function testMigrateDown()
 {
     $username = '******';
     $isEnabled = true;
     $confirmationToken = 'toke';
     $timePasswordResetRequested = null;
     $this->migrator->up();
     $user = new User('*****@*****.**', 'password');
     $user->setUsername($username);
     $user->setEnabled($isEnabled);
     $user->setConfirmationToken($confirmationToken);
     $user->setTimePasswordResetRequested($timePasswordResetRequested);
     $this->userManager->insert($user);
     $userId = $user->getId();
     // echo implode(";\n", $this->migrator->sqlDown());
     $this->migrator->down();
     $this->assertEquals($username, $this->fetchCustomField($userId, 'username'));
     $this->assertEquals($isEnabled, $this->fetchCustomField($userId, 'su:isEnabled'));
     $this->assertEquals($confirmationToken, $this->fetchCustomField($userId, 'su:confirmationToken'));
     $this->assertEquals($timePasswordResetRequested, $this->fetchCustomField($userId, 'su:timePasswordResetRequested'));
 }
Exemplo n.º 6
0
 /**
  * Validate a user object.
  *
  * Invokes User::validate(),
  * and additionally tests that the User's email address and username (if set) are unique across all users.'.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     // TODO: Delete these, unique indexes solve this
     // Ensure email address is unique.
     $duplicates = $this->entityManager->getRepository($this->getUserClass())->findBy(array('email' => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     // Ensure username is unique.
     $duplicates = $this->entityManager->getRepository($this->getUserClass())->findBy(array('username' => $user->getRealUsername()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['username'] = '******';
         }
     }
     // If username is required, ensure it is set.
     if ($this->isUsernameRequired && !$user->getRealUsername()) {
         $errors['username'] = '******';
     }
     return $errors;
 }
Exemplo n.º 7
0
 /**
  * Validate a user object.
  *
  * Invokes User::validate(),
  * and additionally tests that the User's email address and username (if set) are unique across all users.'.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     // Ensure email address is unique.
     $duplicates = $this->findBy(array($this->getUserColumns('email') => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     // Ensure username is unique.
     $duplicates = $this->findBy(array($this->getUserColumns('username') => $user->getRealUsername()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['username'] = '******';
         }
     }
     // If username is required, ensure it is set.
     if ($this->isUsernameRequired && !$user->getRealUsername()) {
         $errors['username'] = '******';
     }
     return $errors;
 }
Exemplo n.º 8
0
 public function sendResetMessage(User $user)
 {
     $url = $this->urlGenerator->generate(self::ROUTE_RESET_PASSWORD, array('token' => $user->getConfirmationToken()), true);
     $context = array('user' => $user, 'resetUrl' => $url);
     $this->sendMessage($this->resetTemplate, $context, $this->getFromEmail(), $user->getEmail());
 }
Exemplo n.º 9
0
 /**
  * Validate a user object.
  *
  * Invokes User::validate(), and additionally tests that the User's email address isn't associated with another User.
  *
  * @param User $user
  * @return array An array of error messages, or an empty array if the User is valid.
  */
 public function validate(User $user)
 {
     $errors = $user->validate();
     $duplicates = $this->findBy(array('email' => $user->getEmail()));
     if (!empty($duplicates)) {
         foreach ($duplicates as $dup) {
             if ($user->getId() && $dup->getId() == $user->getId()) {
                 continue;
             }
             $errors['email'] = 'An account with that email address already exists.';
         }
     }
     return $errors;
 }