コード例 #1
0
 public function it_does_not_permit_mismatched_emails(User $user6)
 {
     $user6->getId()->willReturn(1);
     $user6->getEmail()->willReturn('*****@*****.**');
     $this->shouldThrow(MismatchedEmailsException::class)->during('create', [$user6, '*****@*****.**', 'alphabet']);
 }
コード例 #2
0
 /**
  * Very similar to create, except that it won't log the user in.  This was created to satisfy circumstances where
  * you are creating users from an admin panel for example.  This function is also used by create.
  *
  * @param User   $user
  * @param string $username
  * @param string $password
  *
  * @return AuthenticationRecordInterface
  * @throws EmailUsernameTakenException
  * @throws MismatchedEmailsException
  * @throws PersistedUserRequiredException
  * @throws UsernameTakenException
  */
 public function registerAuthenticationRecord(User $user, string $username, string $password) : AuthenticationRecordInterface
 {
     if (!$user->getId()) {
         throw new PersistedUserRequiredException("Your user must have an ID before you can create auth records with it");
     }
     if ($this->authenticationProvider->findByUsername($username)) {
         throw new UsernameTakenException();
     }
     if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
         if ($user->getEmail() != $username) {
             throw new MismatchedEmailsException();
         }
         if ($emailUser = $this->userProvider->findByEmail($username)) {
             if ($emailUser != $user) {
                 throw new EmailUsernameTakenException();
             }
         }
     }
     $hash = password_hash($password, PASSWORD_DEFAULT);
     $auth = $this->authenticationProvider->create($user->getId(), $username, $hash, KeyFactory::generateEncryptionKey()->getRawKeyMaterial());
     $this->authenticationProvider->save($auth);
     return $auth;
 }