/** * Registers the given user and starts the registration process. * <b>Note that any entity associated with the user object * must be stored beforehand in the database.</b> * * @param User $user The user to store * @throws UserNotSavedException Thrown if a problem occurred during saving of the user */ public function registerUser(User &$user) { $expirationDate = new DateTime(); $expirationDate->add(new DateInterval('PT48H')); $token = hash('sha256', sprintf('%s%s%s', $user->getFirstName(), $user->getLastName(), $expirationDate->format('Y-m-d H:i:s'))); $registration = new Registration(); $registration->setUser($user); $registration->setExpirationDate($expirationDate); $registration->setToken($token); $settingsRepo = $this->entityManager->getRepository(EntityNames::SETTING); $websiteName = $settingsRepo->findOneBy(array('name' => 'website_name')); $websiteEmail = $settingsRepo->findOneBy(array('name' => 'website_email')); $websiteReplyToEmail = $settingsRepo->findOneBy(array('name' => 'website_reply_to_email')); $websiteUrl = $settingsRepo->findOneBy(array('name' => 'website_url')); $registrationLink = $this->getRegistrationLink($token, $websiteUrl->getValue()); $this->entityManager->persist($registration); $mail = new RegistrationMail($user, $websiteName->getValue(), $websiteEmail->getValue(), $websiteUrl->getValue(), $websiteReplyToEmail->getValue(), $websiteName->getValue(), $registrationLink); try { $this->mailer->send($mail); $this->entityManager->flush(); } catch (Exception $e) { throw new RegistrationMailNotSentException($e->getMessage()); } }
public function update(Registration $registration) { $this->setUser($registration->getUser()); $this->setExpirationDate($registration->getExpirationDate()); $this->setToken($registration->getToken()); }