public function signup(\ClassCentral\SiteBundle\Entity\User $user, $emailVerification = true) { $em = $this->container->get('doctrine')->getManager(); $templating = $this->container->get('templating'); $mailgun = $this->container->get('mailgun'); $verifyTokenService = $this->container->get('verification_token'); $userSession = $this->container->get('user_session'); $user->setEmail(strtolower($user->getEmail())); // Normalize the email $password = $user->getPassword(); $user->setPassword($user->getHashedPassword($password)); // If the email has subscriptions to different newsletters, transfer it over to this user $emailEntity = $em->getRepository('ClassCentralSiteBundle:Email')->findOneByEmail($user->getEmail()); if ($emailEntity) { foreach ($emailEntity->getNewsletters() as $newsletter) { $user->addNewsletter($newsletter); } } $em->persist($user); $em->flush(); // Create user prefrences for the user $this->initPreferences($user); // Login the user $this->login($user); // Create a successfull signup notification $userSession->notifyUser(UserSession::FLASH_TYPE_SUCCESS, 'Account successfully created', "You can now build your own library of courses by adding them to <a href='/user/courses''>My Courses</a>", 30); // Send a welcome email but not in the test environment if ($this->container->getParameter('kernel.environment') != 'test') { $name = $user->getName() ? ucwords($user->getName()) : ""; $html = $templating->renderResponse('ClassCentralSiteBundle:Mail:welcome.html.twig', array('name' => $name, 'loginToken' => $this->getLoginToken($user), 'baseUrl' => $this->container->getParameter('baseurl'), 'utm' => array('medium' => Mailgun::UTM_MEDIUM, 'campaign' => 'new_user_welcome', 'source' => Mailgun::UTM_SOURCE_PRODUCT)))->getContent(); $mailgunResponse = $mailgun->sendIntroEmail($user->getEmail(), "'Dhawal Shah'<*****@*****.**>", "Welcome to Class Central, what else can you learn?", $html); if ($emailVerification) { // Send an email for verification $value = array('verify' => 1, 'email' => $user->getEmail()); $tokenEntity = $verifyTokenService->create($value, \ClassCentral\SiteBundle\Entity\VerificationToken::EXPIRY_1_YEAR); $html = $templating->renderResponse('ClassCentralSiteBundle:Mail:confirm.email.html.twig', array('token' => $tokenEntity->getToken()))->getContent(); $mailgunResponse = $mailgun->sendSimpleText($user->getEmail(), "*****@*****.**", "Please confirm your email", $html); // Send user a notification about this email $userSession->notifyUser(UserSession::FLASH_TYPE_NOTICE, 'Confirm your email address', "A confirmation email has been sent to <b>{$user->getEmail()}</b>. Click on the confirmation link in the email to activate your account", 60); } } return $user; }