Beispiel #1
0
 /**
  * Creates new account if username is not taken yet.
  * Tries to authenticate the user
  * if username is already taken.
  * @param string $username login of the user
  * @param string $password plain text password
  * @throws \Exception
  */
 public function create($username, $password)
 {
     $account = $this->objectManager->getRepository('Application\\Entity\\Account')->findBy(array('username' => $username));
     if ($account != null) {
         return $this->authenticate($username, $password);
     }
     try {
         try {
             $account = new Account();
             $passwordHash = static::hashPassword($password);
             $email = new EMailAddress();
             $person = new Person();
             $credentials = new Credentials();
             $credentials->setOwner($person);
             $credentials->setNameFirst($username);
             $person->addCredential($credentials);
             $email->setValue($username)->setOwner($person);
             $person->addEmailAddress($email);
             $account->setUsername($username)->setPassword($passwordHash);
             $account->setPerson($person);
             $this->objectManager->persist($email);
             $this->objectManager->persist($credentials);
             $this->objectManager->persist($person);
             $this->objectManager->persist($account);
             $this->objectManager->flush();
             $success = true;
         } catch (\Exception $e) {
             throw new \Exception("Failed to write data to the database.", 500, $e);
             $success = false;
         }
         return $this->authenticate($username, $password);
     } catch (\Exception $e) {
         throw new \Exception("Failed to create an account due to unknown internal server error.", 500, $e);
     }
 }
 public function create(Person $owner, $value)
 {
     $emailAddress = new EMailAddress();
     $emailAddress->setOwner($owner);
     $emailAddress->setValue($value);
     $this->objectManager->persist($emailAddress);
     $this->objectManager->flush();
     return $emailAddress;
 }