示例#1
0
文件: Email.php 项目: zource/zource
 public function createFromArray(AccountInterface $account, array $data)
 {
     $isPrimary = $account->getEmailAddresses()->count() === 0;
     $validationCode = $this->generateValidationCode();
     $emailAddress = new EmailEntity($account, $data['emailAddress']);
     $emailAddress->setIsPrimary($isPrimary);
     $emailAddress->setValidationCode($validationCode);
     $this->entityManager->persist($emailAddress);
     $this->entityManager->flush($emailAddress);
 }
示例#2
0
文件: Account.php 项目: zource/zource
 public function inviteAccount($data)
 {
     // Lookup the e-mail address:
     $repository = $this->entityManager->getRepository(Email::class);
     $accountEmail = $repository->findOneBy(['address' => $data['email']]);
     if ($accountEmail !== null) {
         return $accountEmail->getAccount();
     }
     $person = new Person($data['first_name'], $data['last_name']);
     $person->setMiddleName($data['middle_name']);
     $emailAddress = new EmailAddress($person, EmailAddress::TYPE_WORK, $data['email']);
     $account = new AccountEntity($person);
     $account->setStatus(AccountEntity::STATUS_INVITED);
     $accountEmail = new Email($account, $data['email']);
     $accountEmail->setValidationCode(Rand::getString(32, range('a', 'z')));
     $account->getEmailAddresses()->add($accountEmail);
     $this->entityManager->persist($person);
     $this->entityManager->persist($emailAddress);
     $this->entityManager->persist($account);
     $this->entityManager->flush();
     return $account;
 }