/** * Builds registration email message * @param \User $user * @return Message */ public function buildRegistrationEmail(\User $user, \RegistrationToken $token) { $this->template->user = $user; $this->template->token = $token; $this->template->confirmLink = $this->presenter->link('//register:confirmation', array('token' => $token->getToken())); $this->template->setFile(__DIR__ . '/templates/registration.latte'); $text = $this->template->__toString(); $message = $this->prepareMessage(); $message->addTo($user->getEmail()); $message->setSubject('Mazagran registration'); $message->setBody($text); return $message; }
public function createUser($nick, $email, $password) { $user = new \User(); $hash = password_hash($password, PASSWORD_BCRYPT); $user->setNick($nick)->setEmail($email)->setPassword($hash); $this->dm->persist($user); $token = new \RegistrationToken(sha1($user->getEmail() . time())); $token->setUser($user); $this->dm->persist($token); try { $this->dm->flush($user, ['safe' => TRUE]); } catch (\MongoCursorException $e) { if (strpos($e->getMessage(), $nick) !== false) { throw new \ExistingUserException(sprintf('User with nick %s already exists ', $nick)); } elseif (strpos($e->getMessage(), $email) !== false) { throw new \ExistingUserException(sprintf('User with email %s already exists ', $email)); } } }