public function createInwicastUserIfNotExists(User $user, $token, Mediacenter $mediacenter)
 {
     $connection = $this->connectionFactory->createConnection($mediacenter->getDatabaseParameters());
     $qb = $connection->createQueryBuilder();
     $qb->select('usr.username, usr.token')->from('mdcr_inwicast_user_tokens', 'usr')->where('usr.username = :username')->andWhere('usr.tokenapp = :platform')->setParameter("username", $user->getUsername())->setParameter("platform", $this->platformName);
     $result = $qb->execute()->fetch();
     if (!$result) {
         //$qb_insert = $connection->createQueryBuilder();
         $sql = "INSERT INTO mdcr_inwicast_user_tokens" . " (`username`, `firstname`, `lastname`, `email`, `userrole`, `token`, `tokendate`, `tokenapp`)" . " VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
         $query = $connection->prepare($sql);
         $query->bindValue(1, $user->getUsername());
         $query->bindValue(2, $user->getFirstName());
         $query->bindValue(3, $user->getLastName());
         $query->bindValue(4, $user->getMail());
         $query->bindValue(5, $user->getPlatformRole()->getName());
         $query->bindValue(6, $token);
         $query->bindValue(7, date('Y-m-d H:i:s'));
         $query->bindValue(8, $this->platformName);
         $query->execute();
     } else {
         $qb_update = $connection->createQueryBuilder();
         $qb_update->update('mdcr_inwicast_user_tokens')->set('token', '?')->set('tokendate', '?')->set('tokenapp', '?')->where('username = ?')->setParameter(0, $token)->setParameter(1, date('Y-m-d H:i:s'))->setParameter(2, $this->platformName)->setParameter(3, $user->getUsername());
         $qb_update->execute();
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * @EXT\Route(
  *     "user/{user}/infos/request",
  *     name="claro_user_infos_request",
  *     options = {"expose"=true}
  * )
  */
 public function userInfosRequestAction(User $user)
 {
     $datas = array('id' => $user->getId(), 'firstName' => $user->getFirstName(), 'lastName' => $user->getLastName(), 'username' => $user->getUsername(), 'mail' => $user->getMail(), 'phone' => $user->getPhone(), 'picture' => $user->getPicture());
     return new JsonResponse($datas, 200);
 }
 public function createRemoteUser(User $user)
 {
     $url = 'api/users.json';
     $tmppw = uniqid();
     $payload = array('profile_form_creation[username]' => $user->getUsername(), 'profile_form_creation[firstName]' => $user->getFirstName(), 'profile_form_creation[lastName]' => $user->getLastName(), 'profile_form_creation[mail]' => $user->getMail(), 'profile_form_creation[administrativeCode]' => $user->getUsername(), 'profile_form_creation[plainPassword][first]' => $tmppw, 'profile_form_creation[plainPassword][second]' => $tmppw);
     $serverOutput = $this->apiManager->url($this->targetFriend, $url, $payload, 'POST');
     $datas = json_decode($serverOutput, true);
     return $datas;
 }
Exemplo n.º 4
0
 /**
  * @param string $subject
  * @param string $body
  * @param User[] $users
  * @param User   $from
  * @param array  $extra
  * @param bool   $force
  * @param string $replyToMail
  *
  * @return bool
  */
 public function send($subject, $body, array $users, $from = null, array $extra = [], $force = false, $replyToMail = null)
 {
     if (count($users) === 0) {
         //obviously, if we're not going to send anything to anyone, it's better to stop
         return false;
     }
     if ($this->isMailerAvailable()) {
         $to = [];
         $layout = $this->contentManager->getTranslatedContent(['type' => 'claro_mail_layout']);
         $fromEmail = $this->getMailerFrom();
         $locale = count($users) === 1 ? $users[0]->getLocale() : $this->ch->getParameter('locale_language');
         if (!$locale) {
             $locale = $this->ch->getParameter('locale_language');
         }
         $usedLayout = $layout[$locale]['content'];
         $body = str_replace('%content%', $body, $usedLayout);
         $body = str_replace('%platform_name%', $this->ch->getParameter('name'), $body);
         if ($from) {
             $body = str_replace('%first_name%', $from->getFirstName(), $body);
             $body = str_replace('%last_name%', $from->getLastName(), $body);
         } else {
             $body = str_replace('%first_name%', $this->ch->getParameter('name'), $body);
             $body = str_replace('%last_name%', '', $body);
         }
         foreach ($users as $user) {
             $mail = $user->getMail();
             if ($user->isMailValidated() || $force) {
                 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
                     $to[] = $mail;
                 }
             }
         }
         if (isset($extra['to'])) {
             foreach ($extra['to'] as $mail) {
                 if (filter_var($mail, FILTER_VALIDATE_EMAIL)) {
                     $to[] = $mail;
                 }
             }
         }
         $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($fromEmail)->setReplyTo($replyToMail)->setBody($body, 'text/html');
         if ($from !== null && filter_var($from->getMail(), FILTER_VALIDATE_EMAIL)) {
             $message->setReplyTo($from->getMail());
         }
         if (count($to) > 1) {
             $message->setBcc($to);
         } else {
             $message->setTo($to);
         }
         if (isset($extra['attachment'])) {
             $message->attach(\Swift_Attachment::fromPath($extra['attachment'], 'application/octet-stream'));
         }
         return $this->mailer->send($message) ? true : false;
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @ApiDoc(
  *     description="Returns a user",
  *     views = {"user"}
  * )
  * @Get("/user/{user}/public", name="get_public_user", options={ "method_prefix" = false })
  */
 public function getPublicUserAction(User $user)
 {
     $settingsProfile = $this->facetManager->getVisiblePublicPreference();
     $publicUser = [];
     foreach ($settingsProfile as $property => $isViewable) {
         if ($isViewable || $user === $this->container->get('security.token_storage')->getToken()->getUser()) {
             switch ($property) {
                 case 'baseData':
                     $publicUser['lastName'] = $user->getLastName();
                     $publicUser['firstName'] = $user->getFirstName();
                     $publicUser['username'] = $user->getUsername();
                     $publicUser['picture'] = $user->getPicture();
                     $publicUser['description'] = $user->getAdministrativeCode();
                     break;
                 case 'email':
                     $publicUser['mail'] = $user->getMail();
                     break;
                 case 'phone':
                     $publicUser['phone'] = $user->getPhone();
                     break;
                 case 'sendMail':
                     $publicUser['mail'] = $user->getMail();
                     $publicUser['allowSendMail'] = true;
                     break;
                 case 'sendMessage':
                     $publicUser['allowSendMessage'] = true;
                     $publicUser['id'] = $user->getId();
                     break;
             }
         }
     }
     return $publicUser;
 }