/** * Create new user * * @param $email * @param $name * @param $passwd * * @return array */ public function create(string $email, string $name, string $passwd, string $salt, string $locationName, array $latlng) : User { $entityManager = $this->getEntityManager(); $model = new User(); $model->setEmail($email)->setName($name)->setPasswd(Auth::createPassword($passwd, $salt))->setSalt($salt)->setApproved(false)->setCreated(new \DateTime("now"))->setLatlng($latlng)->setLocationName($locationName); $entityManager->persist($model); $this->getElastic()->persist($model); $hash = hash('sha1', time() . '|' . $model->getId()); $model->setUserhash($hash); $entityManager->persist($model); $entityManager->flush(); return $model; }
/** * Send email after approved * * @param User $user * * @return bool * @throws \DI\NotFoundException * @throws \Exception */ public function sendSuccessEmail(User $user) { $subject = 'Greetings on ' . $this->getContainer()->get('thewulf7\\friendloc\\components\\config\\iConfig')->get('appName'); $body = $this->getTemplater()->render('email/success.twig', ['name' => $user->getName()]); $mailer = \Swift_Mailer::newInstance(\Swift_MailTransport::newInstance()); $message = \Swift_Message::newInstance($subject); $message->setFrom($this->getContainer()->get('thewulf7\\friendloc\\components\\config\\iConfig')->get('emailFrom'))->setTo([$user->getEmail() => $user->getName()])->setBody($body); $headers =& $message->getHeaders(); $headers->addIdHeader('Message-ID', md5(time()) . "@friendloc.dev"); $headers->addTextHeader('MIME-Version', '1.0'); $headers->addTextHeader('X-Mailer', 'PHP v' . phpversion()); $headers->addParameterizedHeader('Content-type', 'text/html', ['charset' => 'utf-8']); if (!$mailer->send($message, $failures)) { throw new \Exception(implode(',', $failures)); } return true; }
/** * @param InputInterface $input * @param OutputInterface $output */ public function execute(InputInterface $input, OutputInterface $output) { $email = ''; $name = ''; $helper = $this->getHelper('question'); $fields = ['email', 'name']; foreach ($fields as $field) { ${$field} = $input->getArgument($field); if (!${$field}) { $question = new Question(ucfirst($field) . ':', false); ${$field} = $helper->ask($input, $output, $question); } } $password = Auth::generatePassword(); $salt = Auth::generateSalt(); $output->writeln('Your password: '******'em')->getEntityManager(); $model = new User(); $model->setEmail($email)->setName($name)->setPasswd(Auth::createPassword($password, $salt))->setApproved(1)->setCreated(new \DateTime('now'))->setSalt($salt)->setLatlng([56, 30])->setLocationName('Saint-P'); $em->persist($model); $em->flush(); $this->elastic->persist($model); }