Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->addEventSubscriber(new CleanFormSubscriber());
     $builder->addEventSubscriber(new FormExitSubscriber('user.user', $options));
     $builder->add('username', 'text', array('label' => 'mautic.core.username', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'preaddon' => 'fa fa-user', 'autocomplete' => 'off')));
     $builder->add('firstName', 'text', array('label' => 'mautic.core.firstname', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control')));
     $builder->add('lastName', 'text', array('label' => 'mautic.core.lastname', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control')));
     $positions = $this->model->getLookupResults('position', null, 0, true);
     $builder->add('position', 'text', array('label' => 'mautic.core.position', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'data-options' => json_encode($positions)), 'required' => false));
     $builder->add('email', 'email', array('label' => 'mautic.core.type.email', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'preaddon' => 'fa fa-envelope')));
     $existing = !empty($options['data']) && $options['data']->getId();
     $placeholder = $existing ? $this->translator->trans('mautic.user.user.form.passwordplaceholder') : '';
     $required = $existing ? false : true;
     $builder->add('plainPassword', 'repeated', array('first_name' => 'password', 'first_options' => array('label' => 'mautic.core.password', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'placeholder' => $placeholder, 'tooltip' => 'mautic.user.user.form.help.passwordrequirements', 'preaddon' => 'fa fa-lock', 'autocomplete' => 'off'), 'required' => $required, 'error_bubbling' => false), 'second_name' => 'confirm', 'second_options' => array('label' => 'mautic.user.user.form.passwordconfirm', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control', 'placeholder' => $placeholder, 'tooltip' => 'mautic.user.user.form.help.passwordrequirements', 'preaddon' => 'fa fa-lock', 'autocomplete' => 'off'), 'required' => $required, 'error_bubbling' => false), 'type' => 'password', 'invalid_message' => 'mautic.user.user.password.mismatch', 'required' => $required, 'error_bubbling' => false));
     $builder->add('timezone', 'timezone', array('label' => 'mautic.core.timezone', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'multiple' => false, 'empty_value' => 'mautic.user.user.form.defaulttimezone'));
     $builder->add('locale', 'choice', array('choices' => $this->supportedLanguages, 'label' => 'mautic.core.language', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'multiple' => false, 'empty_value' => 'mautic.user.user.form.defaultlocale'));
     if (empty($options['in_profile'])) {
         $builder->add($builder->create('role', 'entity', array('label' => 'mautic.user.role', 'label_attr' => array('class' => 'control-label'), 'attr' => array('class' => 'form-control'), 'class' => 'MauticUserBundle:Role', 'property' => 'name', 'query_builder' => function (EntityRepository $er) {
             return $er->createQueryBuilder('r')->where('r.isPublished = true')->orderBy('r.name', 'ASC');
         })));
         $builder->add('isPublished', 'yesno_button_group');
         $builder->add('buttons', 'form_buttons');
     } else {
         $builder->add('buttons', 'form_buttons', array('save_text' => 'mautic.core.form.apply', 'apply_text' => false));
     }
     if (!empty($options["action"])) {
         $builder->setAction($options["action"]);
     }
 }
Exemplo n.º 2
0
 /**
  * UserListType constructor.
  *
  * @param UserModel $model
  */
 public function __construct(UserModel $model)
 {
     $choices = $model->getRepository()->getEntities(['filter' => ['force' => [['column' => 'u.isPublished', 'expr' => 'eq', 'value' => true]]]]);
     foreach ($choices as $choice) {
         $this->choices[$choice->getId()] = $choice->getName(true);
     }
     //sort by language
     ksort($this->choices);
 }
Exemplo n.º 3
0
 /**
  * @param MauticEvents\CommandListEvent $event
  */
 public function onBuildCommandList(MauticEvents\CommandListEvent $event)
 {
     if ($this->security->isGranted('user:users:view')) {
         $event->addCommands('mautic.user.users', $this->userModel->getCommandList());
     }
     if ($this->security->isGranted('user:roles:view')) {
         $event->addCommands('mautic.user.roles', $this->userRoleModel->getCommandList());
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  *
  * @param Request $request
  *
  * @return Response never null
  */
 public function logout(Request $request, Response $response, TokenInterface $token)
 {
     $this->userModel->setOnlineStatus('offline');
     if ($this->dispatcher->hasListeners(UserEvents::USER_LOGOUT)) {
         $event = new LogoutEvent($this->user, $request);
         $this->dispatcher->dispatch(UserEvents::USER_LOGOUT, $event);
     }
     // Clear session
     $session = $request->getSession();
     $session->clear();
     if (isset($event)) {
         $sessionItems = $event->getPostSessionItems();
         foreach ($sessionItems as $key => $value) {
             $session->set($key, $value);
         }
     }
     // Note that a logout occurred
     $session->set('post_logout', true);
 }
Exemplo n.º 5
0
 /**
  * Populates namespace, bundle, controller, and action into request to be used throughout application.
  *
  * @param FilterControllerEvent $event
  */
 public function onKernelController(FilterControllerEvent $event)
 {
     $controller = $event->getController();
     if (!is_array($controller)) {
         return;
     }
     //only affect Mautic controllers
     if ($controller[0] instanceof MauticController) {
         $request = $event->getRequest();
         //also set the request for easy access throughout controllers
         $controller[0]->setRequest($request);
         // set the factory for easy use access throughout the controllers
         // @deprecated To be removed in 3.0
         $controller[0]->setFactory($this->factory);
         // set the user as well
         $controller[0]->setUser($this->userHelper->getUser());
         // and the core parameters helper
         $controller[0]->setCoreParametersHelper($this->coreParametersHelper);
         // and the dispatcher
         $controller[0]->setDispatcher($this->dispatcher);
         // and the translator
         $controller[0]->setTranslator($this->translator);
         //run any initialize functions
         $controller[0]->initialize($event);
         //update the user's activity marker
         if (!$controller[0] instanceof InstallController && !defined('MAUTIC_ACTIVITY_CHECKED') && !defined('MAUTIC_INSTALLER')) {
             //prevent multiple updates
             $user = $this->userHelper->getUser();
             //slight delay to prevent too many updates
             //note that doctrine will return in current timezone so we do not have to worry about that
             $delay = new \DateTime();
             $delay->setTimestamp(strtotime('2 minutes ago'));
             if ($user instanceof User && $user->getLastActive() < $delay && $user->getId()) {
                 $this->userModel->getRepository()->setLastActive($user);
             }
             $session = $request->getSession();
             if ($session) {
                 $delay = new \DateTime();
                 $delay->setTimestamp(strtotime('15 minutes ago'));
                 $lastOnlineStatusCleanup = $session->get('mautic.online.status.cleanup', $delay);
                 if ($lastOnlineStatusCleanup <= $delay) {
                     $this->userModel->getRepository()->updateOnlineStatuses();
                     $session->set('mautic.online.status.cleanup', new \DateTime());
                 }
                 define('MAUTIC_ACTIVITY_CHECKED', 1);
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Add available tables and columns to the report builder lookup.
  *
  * @param ReportBuilderEvent $event
  */
 public function onReportBuilder(ReportBuilderEvent $event)
 {
     $leadContexts = ['leads', 'lead.pointlog', 'contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last'];
     if ($event->checkContext($leadContexts)) {
         $columns = ['l.id' => ['label' => 'mautic.lead.report.contact_id', 'type' => 'int', 'link' => 'mautic_contact_action'], 'i.ip_address' => ['label' => 'mautic.core.ipaddress', 'type' => 'text'], 'l.date_identified' => ['label' => 'mautic.lead.report.date_identified', 'type' => 'datetime'], 'l.points' => ['label' => 'mautic.lead.points', 'type' => 'int'], 'l.owner_id' => ['label' => 'mautic.lead.report.owner_id', 'type' => 'int', 'link' => 'mautic_user_action'], 'u.first_name' => ['label' => 'mautic.lead.report.owner_firstname', 'type' => 'string'], 'u.last_name' => ['label' => 'mautic.lead.report.owner_lastname', 'type' => 'string']];
         $leadFields = $this->fieldModel->getEntities();
         $fieldColumns = [];
         foreach ($leadFields as $f) {
             switch ($f->getType()) {
                 case 'boolean':
                     $type = 'bool';
                     break;
                 case 'date':
                     $type = 'date';
                     break;
                 case 'datetime':
                     $type = 'datetime';
                     break;
                 case 'time':
                     $type = 'time';
                     break;
                 case 'url':
                     $type = 'url';
                     break;
                 case 'email':
                     $type = 'email';
                     break;
                 case 'number':
                     $type = 'float';
                     break;
                 default:
                     $type = 'string';
                     break;
             }
             $fieldColumns['l.' . $f->getAlias()] = ['label' => $f->getLabel(), 'type' => $type];
         }
         $filters = $columns = array_merge($columns, $fieldColumns);
         // Append segment filters
         $userSegments = $this->listModel->getUserLists();
         $list = [];
         foreach ($userSegments as $segment) {
             $list[$segment['id']] = $segment['name'];
         }
         $filters['s.leadlist_id'] = ['alias' => 'segment_id', 'label' => 'mautic.core.filter.lists', 'type' => 'select', 'list' => $list, 'operators' => ['eq' => 'mautic.core.operator.equals']];
         $filters['l.owner_id'] = ['label' => 'mautic.lead.list.filter.owner', 'type' => 'select', 'list' => $this->userModel->getRepository()->getUserList('', 0)];
         $data = ['display_name' => 'mautic.lead.leads', 'columns' => $columns, 'filters' => $filters];
         $event->addTable('leads', $data, 'contacts');
         $attributionTypes = ['contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last'];
         if ($event->checkContext($attributionTypes)) {
             $context = $event->getContext();
             foreach ($attributionTypes as $attributionType) {
                 if (empty($context) || $event->checkContext($attributionType)) {
                     $type = str_replace('contact.attribution.', '', $attributionType);
                     $this->injectAttributionReportData($event, $columns, $type);
                 }
             }
         }
         if ($event->checkContext(['leads', 'lead.pointlog'])) {
             // Add shared graphs
             $event->addGraph('leads', 'line', 'mautic.lead.graph.line.leads');
             if ($event->checkContext('lead.pointlog')) {
                 $this->injectPointsReportData($event, $columns);
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Send an email to lead(s)
  *
  * @param       $email
  * @param       $users
  * @param mixed $lead
  * @param array $tokens
  * @param array $assetAttachments
  * @param bool  $saveStat
  *
  * @return mixed
  * @throws \Doctrine\ORM\ORMException
  */
 public function sendEmailToUser($email, $users, $lead = null, $tokens = [], $assetAttachments = [], $saveStat = true)
 {
     if (!($emailId = $email->getId())) {
         return false;
     }
     if (!is_array($users)) {
         $user = ['id' => $users];
         $users = [$user];
     }
     //get email settings
     $emailSettings =& $this->getEmailSettings($email, false);
     //noone to send to so bail
     if (empty($users)) {
         return false;
     }
     $mailer = $this->mailHelper->getMailer();
     $mailer->setLead($lead, true);
     $mailer->setTokens($tokens);
     $mailer->setEmail($email, false, $emailSettings[$emailId]['slots'], $assetAttachments, !$saveStat);
     $errors = [];
     foreach ($users as $user) {
         $idHash = uniqid();
         $mailer->setIdHash($idHash);
         if (!is_array($user)) {
             $id = $user;
             $user = ['id' => $id];
         } else {
             $id = $user['id'];
         }
         if (!isset($user['email'])) {
             $userEntity = $this->userModel->getEntity($id);
             $user['email'] = $userEntity->getEmail();
             $user['firstname'] = $userEntity->getFirstName();
             $user['lastname'] = $userEntity->getLastName();
         }
         if (!$mailer->setTo($user['email'], $user['firstname'] . ' ' . $user['lastname'])) {
             $errors[] = "{$user['email']}: " . $this->translator->trans('mautic.email.bounce.reason.bad_email');
         } else {
             if (!$mailer->queue(true)) {
                 $errorArray = $mailer->getErrors();
                 unset($errorArray['failures']);
                 $errors[] = "{$user['email']}: " . implode('; ', $errorArray);
             }
             if ($saveStat) {
                 $saveEntities[] = $mailer->createEmailStat(false, $user['email']);
             }
         }
     }
     //flush the message
     if (!$mailer->flushQueue()) {
         $errorArray = $mailer->getErrors();
         unset($errorArray['failures']);
         $errors[] = implode('; ', $errorArray);
     }
     if (isset($saveEntities)) {
         $this->getStatRepository()->saveEntities($saveEntities);
     }
     //save some memory
     unset($mailer);
     return $errors;
 }