Esempio n. 1
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  * @param $type
  * @param $sendTo
  * @param $variables
  */
 public static function sendMail($controller, $type, $sendTo, $variables)
 {
     $entityManager = $controller->getEntityManager();
     /**
      * @var $templateType \Admin\Entity\TemplateType
      */
     $templateType = $entityManager->getRepository('Admin\\Entity\\TemplateType')->findOneBy(array('code' => $type));
     /**
      * @var $emailTemplate \Admin\Entity\EmailTemplates
      */
     $emailTemplate = $entityManager->getRepository('Admin\\Entity\\EmailTemplates')->findOneBy(array('type' => $templateType, 'language' => 0));
     if (!$emailTemplate) {
         throw new \Exception("Missing email template for type {$type}");
     }
     $emailTemplate->send($controller, $sendTo, $variables);
 }
Esempio n. 2
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  */
 function process($controller)
 {
     $entityManager = $controller->getEntityManager();
     $email = $this->getData()['email'];
     $user = $controller->getUser(array('email' => $email));
     if ($user) {
         $user->generateToken();
         $entityManager->persist($user);
         $entityManager->flush();
         $lang_code = $controller->params()->fromRoute('lang');
         $user->sendForgotPasswordEmail($controller, $lang_code);
         return true;
     } else {
         return false;
     }
 }
Esempio n. 3
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  * @return bool
  */
 public function validate($controller, $lang)
 {
     $entityManager = $controller->getEntityManager();
     $translator = $controller->getTranslator();
     $data = $this->getData();
     $email = $data['email'];
     $password = $data['password'];
     $user = $entityManager->getRepository('\\User\\Entity\\User')->findOneBy(array('email' => $email));
     if ($user && $user->checkPassword($password)) {
         if ($user->isActivated()) {
             $user->authenticate();
             $user->lastLogin($entityManager);
             return true;
         } else {
             if ($user->getLastLogin() == null) {
                 $msg = $translator->translate('You must confirm your email to be able to login');
                 $controller->flashMessenger()->addErrorMessage($msg);
                 $controller->redirect()->toUrl('/' . $lang . "/user/register/confirm?email=" . $email . '&type=needConfirm');
                 return false;
             } else {
                 $msg = $translator->translate('Your account has been blocked, Please contact your Admin');
                 $controller->flashMessenger()->addErrorMessage($msg);
                 $controller->redirect()->toUrl('/' . $lang . "/user/register/confirm?email=" . $email . '&type=accBlook');
                 return false;
             }
         }
     } else {
         $this->addNonElementMessage('danger', $translator->translate('Wrong username or password'));
     }
     return False;
 }
Esempio n. 4
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  */
 public function sendNewActivityMail($controller, $lang_code = 'en-US')
 {
     // initial data for email template
     //$lang_code = $controller->params()->fromRoute('lang');
     $projectLink = $controller->getBaseUrl() . '/' . $lang_code . '/admin/project/detail?id=' . $this->project->getId();
     $data = array('project' => $this->project->getData(), 'type' => $this->type, 'sender' => $this->sender->getData(), 'message' => $this->message, 'projectLink' => $projectLink);
     $emails = [];
     $emails[] = $controller->getUser(array("staff" => $this->project->getData()['pm']['id']))->getData()['email'];
     $emails[] = $controller->getUser(array("employer" => $this->project->getData()['client']['id']))->getData()['email'];
     if ($this->project->getData()['sale']) {
         $emails[] = $controller->getUser(array("staff" => $this->project->getData()['sale']['id']))->getData()['email'];
     }
     // Uncomment to remove current user from mail list to send
     // $user = $controller->getCurrentUser();
     // if(($key = array_search($user->getEmail(), $emails)) !== false) {
     //     unset($emails[$key]);
     // }
     $tpl = "ACTIVITY_NEW";
     switch ($this->type) {
         case 'accept_quote':
         case 'create_quote':
         case 'create_task':
         case 'message':
     }
     foreach ($emails as $email) {
         Mail::sendMail($controller, $tpl, $email, $data);
     }
 }
Esempio n. 5
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  * @param $userType
  */
 public function save($controller, $data, $userType, $lang_code = '')
 {
     /**
      * @var $user \User\Entity\User
      */
     $user = $this->getObject();
     $entityManager = $controller->getEntityManager();
     $data = (array) $data;
     $data['createdTime'] = new \DateTime('now');
     //$data['lastLogin'] = new \DateTime('now');
     $user->setData($data);
     $user->setGroupByName($userType, $entityManager);
     // Create password hash
     $user->encodePassword();
     $user->generateToken();
     $user->save($entityManager);
     if ($userType == 'freelancer') {
         $user->createFreelancer($controller, $data, $entityManager, $lang_code);
     } else {
         //$data['contracted'] = 0;
         $user->createEmployer($controller, $data, $entityManager, $lang_code);
     }
     //$user->sendConfirmationEmail($controller);
 }
Esempio n. 6
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  */
 public function sendForgotPasswordEmail($controller, $lang = 'en-US')
 {
     //$lang = 'en-US'
     // initial data for email template
     $forgotLink = $controller->getBaseUrl() . '/' . $lang . '/user/forgotPassword/reset?token=' . $this->token;
     $data = array('firstName' => $this->firstName, 'lastName' => $this->lastName, 'link' => $forgotLink);
     Mail::sendMail($controller, "USER_RESET", $this->email, $data);
 }
Esempio n. 7
0
 /**
  * @param \Application\Controller\AbstractActionController $controller
  * @param $sendTo
  * @param $variables
  */
 public function send($controller, $sendTo, $variables)
 {
     $this->format($variables);
     $transport = $controller->getServiceLocator()->get('mail.transport');
     $message = $this->getMailMessage();
     $message->addTo($sendTo);
     $message->addFrom($transport->mailOptions['from']);
     $transport->send($message);
 }