Example #1
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'order_id' => []];
     $params = array_merge($default, $params);
     $order_id = $params['order_id'];
     $users = [];
     try {
         $repository = $this->app['EM']->getRepository('Phraseanet:OrderElement');
         $results = $repository->findBy(['orderId' => $order_id]);
         $base_ids = [];
         foreach ($results as $result) {
             $base_ids[] = $result->getBaseId();
         }
         $base_ids = array_unique($base_ids);
         $query = new User_Query($this->app);
         $users = $query->on_base_ids($base_ids)->who_have_right(['order_master'])->execute()->get_results();
     } catch (\Exception $e) {
     }
     if (count($users) == 0) {
         return;
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id_dom = $dom_xml->createElement('usr_id');
     $order_id_dom = $dom_xml->createElement('order_id');
     $usr_id_dom->appendChild($dom_xml->createTextNode($params['usr_id']));
     $order_id_dom->appendChild($dom_xml->createTextNode($order_id));
     $root->appendChild($usr_id_dom);
     $root->appendChild($order_id_dom);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($orderInitiator = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($users as $user) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($user->getId())) {
             $readyToSend = false;
             try {
                 $receiver = Receiver::fromUser($user);
                 $readyToSend = true;
             } catch (\Exception $e) {
                 continue;
             }
             if ($readyToSend) {
                 $mail = MailInfoNewOrder::create($this->app, $receiver);
                 $mail->setUser($orderInitiator);
                 $this->app['notification.deliverer']->deliver($mail);
                 $mailed = true;
             }
         }
         $this->broker->notify($user->getId(), __CLASS__, $datas, $mailed);
     }
     return;
 }
Example #2
0
 /**
  * @covers Alchemy\Phrasea\Notification\Receiver::fromUser
  */
 public function testFromUserFailed()
 {
     $user = $this->createUserMock();
     $user->expects($this->any())->method('getDisplayName')->will($this->returnValue($this->name));
     $user->expects($this->any())->method('getEmail')->will($this->returnValue('wrong user'));
     try {
         Receiver::fromUser($user);
         $this->fail('Should have raised an exception');
     } catch (InvalidArgumentException $e) {
     }
 }
Example #3
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$entry)
 {
     $params = ['entry_id' => $entry->getId(), 'notify_email' => $params['notify_email']];
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $entry_id = $dom_xml->createElement('entry_id');
     $entry_id->appendChild($dom_xml->createTextNode($params['entry_id']));
     $root->appendChild($entry_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $Query = new \User_Query($this->app);
     $Query->include_phantoms(true)->include_invite(false)->include_templates(false)->email_not_null(true);
     if ($entry->getFeed()->getCollection($this->app)) {
         $Query->on_base_ids([$entry->getFeed()->getCollection($this->app)->get_base_id()]);
     }
     $start = 0;
     $perLoop = 100;
     $from = ['email' => $entry->getAuthorEmail(), 'name' => $entry->getAuthorName()];
     do {
         $results = $Query->limit($start, $perLoop)->execute()->get_results();
         foreach ($results as $user_to_notif) {
             $mailed = false;
             if ($params['notify_email'] && $this->shouldSendNotificationFor($user_to_notif->getId())) {
                 $readyToSend = false;
                 try {
                     $token = $this->app['tokens']->getUrlToken(\random::TYPE_FEED_ENTRY, $user_to_notif->getId(), null, $entry->getId());
                     $url = $this->app->url('lightbox', ['LOG' => $token]);
                     $receiver = Receiver::fromUser($user_to_notif);
                     $readyToSend = true;
                 } catch (\Exception $e) {
                 }
                 if ($readyToSend) {
                     $mail = MailInfoNewPublication::create($this->app, $receiver);
                     $mail->setButtonUrl($url);
                     $mail->setAuthor($entry->getAuthorName());
                     $mail->setTitle($entry->getTitle());
                     $this->app['notification.deliverer']->deliver($mail);
                     $mailed = true;
                 }
             }
             $this->broker->notify($user_to_notif->getId(), __CLASS__, $datas, $mailed);
         }
         $start += $perLoop;
     } while (count($results) > 0);
     return true;
 }
Example #4
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'message' => '', 'ssel_id' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $message = $dom_xml->createElement('message');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $message->appendChild($dom_xml->createTextNode($params['message']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($message);
     $root->appendChild($ssel_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $basket = $this->app['EM']->getRepository('Phraseanet:Basket')->find($params['ssel_id']);
             $title = $basket->getName();
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']);
             $mail->setButtonUrl($params['url']);
             $mail->setDuration($params['duration']);
             $mail->setTitle($title);
             $mail->setUser($user_from);
             $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
 /**
  *
  * @param  string  $event
  * @param  Array   $params
  * @param  Array   $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'ssel_id' => '', 'n' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $n = $dom_xml->createElement('n');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $n->appendChild($dom_xml->createTextNode($params['n']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($ssel_id);
     $root->appendChild($n);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $repository = $this->app['EM']->getRepository('Phraseanet:Basket');
             $basket = $repository->find($params['ssel_id']);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $url = $this->app->url('lightbox_compare', ['basket' => $basket->getId(), 'LOG' => $this->app['tokens']->getUrlToken(\random::TYPE_VIEW, $user_to->getId(), null, $basket->getId())]);
             $mail = MailInfoOrderDelivered::create($this->app, $receiver, $emitter, null);
             $mail->setButtonUrl($url);
             $mail->setBasket($basket);
             $mail->setDeliverer($user_from);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
 private function notifyUser(User $user, $datas)
 {
     $mailed = false;
     if ($this->shouldSendNotificationFor($user, 'eventsmanager_notify_uploadquarantine')) {
         $readyToSend = false;
         try {
             $receiver = Receiver::fromUser($user);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoRecordQuarantined::create($this->app, $receiver);
             $this->deliver($mail);
             $mailed = true;
         }
     }
     $this->app['events-manager']->notify($user->getId(), 'eventsmanager_notify_uploadquarantine', $datas, $mailed);
 }
Example #7
0
 public function onDeny(OrderDeliveryEvent $event)
 {
     $params = ['from' => $event->getAdmin()->getId(), 'to' => $event->getOrder()->getUser()->getId(), 'n' => $event->getQuantity()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($event->getOrder()->getUser(), 'eventsmanager_notify_ordernotdelivered')) {
         $user_from = $event->getAdmin();
         $user_to = $event->getOrder()->getUser();
         $receiver = Receiver::fromUser($user_to);
         $emitter = Emitter::fromUser($user_from);
         $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
         $mail->setQuantity($params['n']);
         $mail->setDeliverer($user_from);
         $this->app['notification.deliverer']->deliver($mail);
         $mailed = true;
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_ordernotdelivered', $datas, $mailed);
 }
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => null, 'reason' => '', 'account_id' => null, 'base_id' => null, 'record_id' => null];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $reason = $dom_xml->createElement('reason');
     $account_id = $dom_xml->createElement('account_id');
     $sbas_id = $dom_xml->createElement('sbas_id');
     $record_id = $dom_xml->createElement('record_id');
     $reason->appendChild($dom_xml->createTextNode($params['reason']));
     $account_id->appendChild($dom_xml->createTextNode($params['account_id']));
     $sbas_id->appendChild($dom_xml->createTextNode($params['sbas_id']));
     $record_id->appendChild($dom_xml->createTextNode($params['record_id']));
     $root->appendChild($reason);
     $root->appendChild($account_id);
     $root->appendChild($sbas_id);
     $root->appendChild($record_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['usr_id'])) {
         $readyToSend = false;
         try {
             $user = $this->app['manipulator.user']->getRepository()->find($params['usr_id']);
             $account = Bridge_Account::load_account($this->app, $params['account_id']);
             $receiver = Receiver::fromUser($user);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             /** ADD MAIL TEST */
             $mail = MailInfoBridgeUploadFailed::create($this->app, $receiver);
             $mail->setAdapter($account->get_api()->get_connector()->get_name());
             $mail->setReason($params['reason']);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     $this->broker->notify($params['usr_id'], __CLASS__, $datas, $mailed);
     return;
 }
Example #9
0
 public function onPush(PushEvent $event)
 {
     $params = ['from' => $event->getBasket()->getPusher()->getId(), 'to' => $event->getBasket()->getUser()->getId(), 'message' => $event->getMessage(), 'ssel_id' => $event->getBasket()->getId()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($event->getBasket()->getUser(), 'eventsmanager_notify_push')) {
         $basket = $event->getBasket();
         $user_from = $event->getBasket()->getPusher();
         $user_to = $event->getBasket()->getUser();
         $receiver = Receiver::fromUser($user_to);
         $emitter = Emitter::fromUser($user_from);
         $mail = MailInfoPushReceived::create($this->app, $receiver, $emitter, $params['message'], $event->getUrl());
         $mail->setBasket($basket);
         $mail->setPusher($user_from);
         $this->app['notification.deliverer']->deliver($mail, $event->hasReceipt());
         $mailed = true;
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_push', $datas, $mailed);
 }
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'n' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $n = $dom_xml->createElement('n');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $n->appendChild($dom_xml->createTextNode($params['n']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($n);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoOrderCancelled::create($this->app, $receiver, $emitter);
             $mail->setQuantity($params['n']);
             $mail->setDeliverer($user_from);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
 public function onCreate(FeedEntryEvent $event)
 {
     $entry = $event->getFeedEntry();
     $params = ['entry_id' => $entry->getId(), 'notify_email' => $event->hasEmailNotification()];
     $this->app['manipulator.webhook-event']->create(WebhookEvent::NEW_FEED_ENTRY, WebhookEvent::FEED_ENTRY_TYPE, array_merge(array('feed_id' => $entry->getFeed()->getId()), $params));
     $datas = json_encode($params);
     $Query = $this->app['phraseanet.user-query'];
     $Query->include_phantoms(true)->include_invite(false)->include_templates(false)->email_not_null(true);
     if ($entry->getFeed()->getCollection($this->app)) {
         $Query->on_base_ids([$entry->getFeed()->getCollection($this->app)->get_base_id()]);
     }
     $start = 0;
     $perLoop = 100;
     do {
         $results = $Query->limit($start, $perLoop)->execute()->get_results();
         foreach ($results as $user_to_notif) {
             $mailed = false;
             if ($params['notify_email'] && $this->shouldSendNotificationFor($user_to_notif, 'eventsmanager_notify_feed')) {
                 $readyToSend = false;
                 try {
                     $token = $this->app['manipulator.token']->createFeedEntryToken($user_to_notif, $entry);
                     $url = $this->app->url('lightbox', ['LOG' => $token->getValue()]);
                     $receiver = Receiver::fromUser($user_to_notif);
                     $readyToSend = true;
                 } catch (\Exception $e) {
                 }
                 if ($readyToSend) {
                     $mail = MailInfoNewPublication::create($this->app, $receiver);
                     $mail->setButtonUrl($url);
                     $mail->setAuthor($entry->getAuthorName());
                     $mail->setTitle($entry->getTitle());
                     $this->app['notification.deliverer']->deliver($mail);
                     $mailed = true;
                 }
             }
             $this->app['events-manager']->notify($user_to_notif->getId(), 'eventsmanager_notify_feed', $datas, $mailed);
         }
         $start += $perLoop;
     } while (count($results) > 0);
 }
Example #12
0
 public function onUploadFailure(BridgeUploadFailureEvent $event)
 {
     $account = $event->getElement()->get_account();
     $user = $account->get_user();
     $params = ['usr_id' => $user->getId(), 'reason' => $event->getReason(), 'account_id' => $account->get_id(), 'sbas_id' => $event->getElement()->get_record()->get_sbas_id(), 'record_id' => $event->getElement()->get_record()->get_record_id()];
     $datas = json_encode($params);
     $mailed = false;
     if ($this->shouldSendNotificationFor($user, 'eventsmanager_notify_bridgeuploadfail')) {
         try {
             $receiver = Receiver::fromUser($user);
             $readyToSend = true;
         } catch (\Exception $e) {
             $readyToSend = false;
         }
         if ($readyToSend) {
             $mail = MailInfoBridgeUploadFailed::create($this->app, $receiver);
             $mail->setAdapter($account->get_api()->get_connector()->get_name());
             $mail->setReason($params['reason']);
             $this->deliver($mail);
             $mailed = true;
         }
     }
     $this->app['events-manager']->notify($params['usr_id'], 'eventsmanager_notify_bridgeuploadfail', $datas, $mailed);
 }
 public function onRemind(ValidationEvent $event)
 {
     $params = ['from' => $event->getBasket()->getValidation()->getInitiator()->getId(), 'to' => $event->getParticipant()->getUser()->getId(), 'ssel_id' => $event->getBasket()->getId(), 'url' => $event->getUrl()];
     $datas = json_encode($params);
     $mailed = false;
     $user_from = $event->getBasket()->getValidation()->getInitiator();
     $user_to = $event->getParticipant()->getUser();
     if ($this->shouldSendNotificationFor($event->getParticipant()->getUser(), 'eventsmanager_notify_validationreminder')) {
         $readyToSend = false;
         try {
             $basket = $event->getBasket();
             $title = $basket->getName();
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoValidationReminder::create($this->app, $receiver, $emitter);
             $mail->setButtonUrl($params['url']);
             $mail->setTitle($title);
             $this->deliver($mail);
             $mailed = true;
         }
     }
     return $this->app['events-manager']->notify($params['to'], 'eventsmanager_notify_validationreminder', $datas, $mailed);
 }
Example #14
0
 /**
  * Validation of email address
  *
  * @param  Request $request The current request
  * @return RedirectResponse
  */
 public function registerConfirm(Request $request)
 {
     if (null === ($code = $request->query->get('code'))) {
         $this->app->addFlash('error', $this->app->trans('Invalid unlock link.'));
         return $this->app->redirectPath('homepage');
     }
     if (null === ($token = $this->getTokenRepository()->findValidToken($code))) {
         $this->app->addFlash('error', $this->app->trans('Invalid unlock link.'));
         return $this->app->redirectPath('homepage');
     }
     $user = $token->getUser();
     if (!$user->isMailLocked()) {
         $this->app->addFlash('info', $this->app->trans('Account is already unlocked, you can login.'));
         return $this->app->redirectPath('homepage');
     }
     $tokenManipulator = $this->getTokenManipulator();
     $tokenManipulator->delete($token);
     $user->setMailLocked(false);
     try {
         $receiver = Receiver::fromUser($user);
     } catch (InvalidArgumentException $e) {
         $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.'));
         return $this->app->redirectPath('homepage');
     }
     $tokenManipulator->delete($token);
     if (count($this->getAclForUser($user)->get_granted_base()) > 0) {
         $mail = MailSuccessEmailConfirmationRegistered::create($this->app, $receiver);
         $this->deliver($mail);
         $this->app->addFlash('success', $this->app->trans('Account has been unlocked, you can now login.'));
     } else {
         $mail = MailSuccessEmailConfirmationUnregistered::create($this->app, $receiver);
         $this->deliver($mail);
         $this->app->addFlash('info', $this->app->trans('Account has been unlocked, you still have to wait for admin approval.'));
     }
     return $this->app->redirectPath('homepage');
 }
Example #15
0
 /**
  * Submit the new password
  *
  * @param  Application      $app     A Silex application where the controller is mounted on
  * @param  Request          $request The current request
  * @return RedirectResponse
  */
 public function forgotPassword(PhraseaApplication $app, Request $request)
 {
     $form = $app->form(new PhraseaForgotPasswordForm());
     try {
         if ('POST' === $request->getMethod()) {
             $form->bind($request);
             if ($form->isValid()) {
                 $data = $form->getData();
                 if (null === ($user = $app['manipulator.user']->getRepository()->findByEmail($data['email']))) {
                     throw new FormProcessingException(_('phraseanet::erreur: Le compte n\'a pas ete trouve'));
                 }
                 try {
                     $receiver = Receiver::fromUser($user);
                 } catch (InvalidArgumentException $e) {
                     throw new FormProcessingException($app->trans('Invalid email address'));
                 }
                 $token = $app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $user->getId(), new \DateTime('+1 day'));
                 if (!$token) {
                     return $app->abort(500, 'Unable to generate a token');
                 }
                 $url = $app->url('login_renew_password', ['token' => $token], true);
                 $mail = MailRequestPasswordUpdate::create($app, $receiver);
                 $mail->setLogin($user->getLogin());
                 $mail->setButtonUrl($url);
                 $app['notification.deliverer']->deliver($mail);
                 $app->addFlash('info', $app->trans('phraseanet:: Un email vient de vous etre envoye'));
                 return $app->redirectPath('login_forgot_password');
             }
         }
     } catch (FormProcessingException $e) {
         $app->addFlash('error', $e->getMessage());
     }
     return $app['twig']->render('login/forgot-password.html.twig', array_merge(self::getDefaultTemplateVariables($app), ['form' => $form->createView()]));
 }
Example #16
0
 /**
  *
  * @param User $to
  * @param User $registeredUser
  *
  * @return boolean
  */
 public function mail(User $to, User $registeredUser)
 {
     $body = '';
     $body .= sprintf("Login : %s\n", $registeredUser->getLogin());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur nom'), $registeredUser->getFirstName());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur prenom'), $registeredUser->getLastName());
     $body .= sprintf("%s : %s\n", _('admin::compte-utilisateur email'), $registeredUser->getEmail());
     $body .= sprintf("%s/%s\n", $registeredUser->get_job(), $registeredUser->getCompany());
     $readyToSend = false;
     try {
         $receiver = Receiver::fromUser($to);
         $readyToSend = true;
     } catch (\Exception $e) {
     }
     if ($readyToSend) {
         $mail = MailInfoSomebodyAutoregistered::create($this->app, $receiver, null, $body);
         $this->app['notification.deliverer']->deliver($mail);
     }
     return true;
 }
Example #17
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'registrations' => []];
     $params = array_merge($default, $params);
     $base_ids = $params['registrations'];
     if (count($base_ids) == 0) {
         return;
     }
     $mailColl = [];
     try {
         $rs = $this->app['EM.native-query']->getAdminsOfBases(array_keys($base_ids));
         foreach ($rs as $row) {
             $user = $row[0];
             if (!isset($mailColl[$user->getId()])) {
                 $mailColl[$user->getId()] = [];
             }
             $mailColl[$user->getId()][] = $row['base_id'];
         }
     } catch (\Exception $e) {
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id = $dom_xml->createElement('usr_id');
     $base_ids = $dom_xml->createElement('base_ids');
     $usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
     foreach ($params['registrations'] as $base_id => $is_ok) {
         $base_id_node = $dom_xml->createElement('base_id');
         $base_id_node->appendChild($dom_xml->createTextNode($base_id));
         $base_ids->appendChild($base_id_node);
     }
     $root->appendChild($usr_id);
     $root->appendChild($base_ids);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($registeredUser = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($mailColl as $usr_id => $base_ids) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($usr_id)) {
             $readyToSend = false;
             try {
                 $admin_user = $this->app['manipulator.user']->getRepository()->find($usr_id);
                 $receiver = Receiver::fromUser($admin_user);
                 $readyToSend = true;
             } catch (\Exception $e) {
                 continue;
             }
             if ($readyToSend) {
                 $mail = MailInfoUserRegistered::create($this->app, $receiver);
                 $mail->setRegisteredUser($registeredUser);
                 $this->app['notification.deliverer']->deliver($mail);
                 $mailed = true;
             }
         }
         $this->broker->notify($usr_id, __CLASS__, $datas, $mailed);
     }
     return;
 }
Example #18
0
 /**
  * @param User $user
  * @param bool $notifyUser
  * @return string
  */
 private function requestPasswordResetTokenByUser(User $user, $notifyUser = true)
 {
     $receiver = Receiver::fromUser($user);
     $token = $this->tokenManipulator->createResetPasswordToken($user);
     if ($notifyUser) {
         $url = $this->urlGenerator->generate('login_renew_password', ['token' => $token->getValue()], true);
         $mail = MailRequestPasswordUpdate::create($this->application, $receiver);
         $mail->setLogin($user->getLogin());
         $mail->setButtonUrl($url);
         $mail->setExpiration(new \DateTime('+1 day'));
         $this->mailer->deliver($mail);
     }
     return $token->getValue();
 }
Example #19
0
 public function create_newuser()
 {
     $email = $this->request->get('value');
     if (!\Swift_Validate::email($email)) {
         throw new \Exception_InvalidArgument('Invalid mail address');
     }
     if (null === ($createdUser = $this->app['repo.users']->findByEmail($email))) {
         $sendCredentials = !!$this->request->get('send_credentials', false);
         $validateMail = !!$this->request->get('validate_mail', false);
         $createdUser = $this->app['manipulator.user']->createUser($email, $this->app['random.medium']->generateString(128), $email);
         $receiver = null;
         try {
             $receiver = Receiver::fromUser($createdUser);
         } catch (InvalidArgumentException $e) {
         }
         if ($sendCredentials && $receiver) {
             $urlToken = $this->app['manipulator.token']->createResetPasswordToken($createdUser);
             $url = $this->app->url('login_renew_password', ['token' => $urlToken->getValue()]);
             $mail = MailRequestPasswordSetup::create($this->app, $receiver, null, '', $url);
             $mail->setLogin($createdUser->getLogin());
             $this->app['notification.deliverer']->deliver($mail);
         }
         if ($validateMail && $receiver) {
             $createdUser->setMailLocked(true);
             $token = $this->app['manipulator.token']->createAccountUnlockToken($createdUser);
             $url = $this->app->url('login_register_confirm', ['code' => $token]);
             $mail = MailRequestEmailConfirmation::create($this->app, $receiver, null, '', $url, $token->getExpiration());
             $this->app['notification.deliverer']->deliver($mail);
         }
     }
     $this->usr_id = $createdUser->getId();
     return $createdUser;
 }
Example #20
0
 /**
  * Reset Email
  *
  * @param  Application      $app
  * @param  Request          $request
  * @return RedirectResponse
  */
 public function resetEmail(PhraseaApplication $app, Request $request)
 {
     if (null === ($password = $request->request->get('form_password')) || null === ($email = $request->request->get('form_email')) || null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
         $app->abort(400, $app->trans('Could not perform request, please contact an administrator.'));
     }
     $user = $app['authentication']->getUser();
     if (!$app['auth.password-encoder']->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
         $app->addFlash('error', $app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
         return $app->redirectPath('account_reset_email');
     }
     if (!\Swift_Validate::email($email)) {
         $app->addFlash('error', $app->trans('forms::l\'email semble invalide'));
         return $app->redirectPath('account_reset_email');
     }
     if ($email !== $emailConfirm) {
         $app->addFlash('error', $app->trans('forms::les emails ne correspondent pas'));
         return $app->redirectPath('account_reset_email');
     }
     $date = new \DateTime('1 day');
     $token = $app['tokens']->getUrlToken(\random::TYPE_EMAIL, $app['authentication']->getUser()->getId(), $date, $app['authentication']->getUser()->getEmail());
     $url = $app->url('account_reset_email', ['token' => $token]);
     try {
         $receiver = Receiver::fromUser($app['authentication']->getUser());
     } catch (InvalidArgumentException $e) {
         $app->addFlash('error', $app->trans('phraseanet::erreur: echec du serveur de mail'));
         return $app->redirectPath('account_reset_email');
     }
     $mail = MailRequestEmailUpdate::create($app, $receiver, null);
     $mail->setButtonUrl($url);
     $mail->setExpiration($date);
     $app['notification.deliverer']->deliver($mail);
     $app->addFlash('info', $app->trans('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer'));
     return $app->redirectPath('account');
 }
 /**
  * Reset Email
  *
  * @param  Request $request
  * @return RedirectResponse
  */
 public function resetEmail(Request $request)
 {
     if (null === ($password = $request->request->get('form_password')) || null === ($email = $request->request->get('form_email')) || null === ($emailConfirm = $request->request->get('form_email_confirm'))) {
         throw new BadRequestHttpException($this->app->trans('Could not perform request, please contact an administrator.'));
     }
     $user = $this->getAuthenticatedUser();
     if (!$this->getPasswordEncoder()->isPasswordValid($user->getPassword(), $password, $user->getNonce())) {
         $this->app->addFlash('error', $this->app->trans('admin::compte-utilisateur:ftp: Le mot de passe est errone'));
         return $this->app->redirectPath('account_reset_email');
     }
     if (!\Swift_Validate::email($email)) {
         $this->app->addFlash('error', $this->app->trans('forms::l\'email semble invalide'));
         return $this->app->redirectPath('account_reset_email');
     }
     if ($email !== $emailConfirm) {
         $this->app->addFlash('error', $this->app->trans('forms::les emails ne correspondent pas'));
         return $this->app->redirectPath('account_reset_email');
     }
     $token = $this->getTokenManipulator()->createResetEmailToken($user, $email);
     $url = $this->app->url('account_reset_email', ['token' => $token->getValue()]);
     try {
         $receiver = Receiver::fromUser($user);
     } catch (InvalidArgumentException $e) {
         $this->app->addFlash('error', $this->app->trans('phraseanet::erreur: echec du serveur de mail'));
         return $this->app->redirectPath('account_reset_email');
     }
     $mail = MailRequestEmailUpdate::create($this->app, $receiver, null);
     $mail->setButtonUrl($url);
     $mail->setExpiration($token->getExpiration());
     $this->deliver($mail);
     $this->app->addFlash('info', $this->app->trans('admin::compte-utilisateur un email de confirmation vient de vous etre envoye. Veuillez suivre les instructions contenue pour continuer'));
     return $this->app->redirectPath('account');
 }
Example #22
0
 public function create_newuser()
 {
     $email = $this->request->get('value');
     if (!\Swift_Validate::email($email)) {
         throw new \Exception_InvalidArgument('Invalid mail address');
     }
     if (null === ($createdUser = $this->app['manipulator.user']->getRepository()->findByEmail($email))) {
         $sendCredentials = !!$this->request->get('send_credentials', false);
         $validateMail = !!$this->request->get('validate_mail', false);
         $createdUser = $this->app['manipulator.user']->createUser($email, \random::generatePassword(16), $email);
         $receiver = null;
         try {
             $receiver = Receiver::fromUser($createdUser);
         } catch (InvalidArgumentException $e) {
         }
         if ($sendCredentials) {
             $urlToken = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->getId());
             if ($receiver && false !== $urlToken) {
                 $url = $this->app->url('login_renew_password', ['token' => $urlToken]);
                 $mail = MailRequestPasswordSetup::create($this->app, $receiver, null, '', $url);
                 $mail->setLogin($createdUser->getLogin());
                 $this->app['notification.deliverer']->deliver($mail);
             }
         }
         if ($validateMail) {
             $createdUser->setMailLocked(true);
             if ($receiver) {
                 $expire = new \DateTime('+3 days');
                 $token = $this->app['tokens']->getUrlToken(\random::TYPE_PASSWORD, $createdUser->getId(), $expire, $createdUser->getEmail());
                 $url = $this->app->url('login_register_confirm', ['code' => $token]);
                 $mail = MailRequestEmailConfirmation::create($this->app, $receiver, null, '', $url, $expire);
                 $this->app['notification.deliverer']->deliver($mail);
             }
         }
     }
     $this->usr_id = $createdUser->getId();
     return $createdUser;
 }
 /**
  * Notifiy an user using the specified datas
  *
  * @param User   $user
  * @param string $datas
  */
 private function notifyUser(User $user, $datas)
 {
     $mailed = false;
     if ($this->shouldSendNotificationFor($user->getId())) {
         $readyToSend = false;
         try {
             $receiver = Receiver::fromUser($user);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoRecordQuarantined::create($this->app, $receiver);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     $this->broker->notify($user->getId(), __CLASS__, $datas, $mailed);
 }