Skip to content

Commit

Permalink
Misc. code reformatting & bug fixes for sending emails from workflow …
Browse files Browse the repository at this point in the history
…events of type user
  • Loading branch information
Akshay Kumar committed Jan 12, 2023
1 parent 259c519 commit cdd43fb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Controller/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ public function forgotPassword(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$recaptchaDetails = $this->recaptchaService->getRecaptchaDetails();

if ($request->getMethod() == 'POST') {
if ($recaptchaDetails && $recaptchaDetails->getIsActive() == true && $this->recaptchaService->getReCaptchaResponse($request->request->get('g-recaptcha-response'))
) {
if ($recaptchaDetails && $recaptchaDetails->getIsActive() == true && $this->recaptchaService->getReCaptchaResponse($request->request->get('g-recaptcha-response'))) {
$this->addFlash('warning', $this->translator->trans("Warning ! Please select correct CAPTCHA !"));
} else {
$user = new User();
$form = $this->createFormBuilder($user,['csrf_protection' => false])
->add('email',EmailType::class)
->getForm();
->add('email',EmailType::class)
->getForm()
;

$form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
$form->handleRequest($request);
Expand All @@ -110,7 +111,6 @@ public function forgotPassword(Request $request)
$this->addFlash('success', $this->translator->trans('Please check your mail for password update'));

return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));

} else {
$this->addFlash('warning', $this->translator->trans('This email address is not registered with us'));
}
Expand Down
9 changes: 1 addition & 8 deletions Services/EmailService.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ public function processEmailContent($content, array $emailPlaceholders = [], $is

public function sendMail($subject, $content, $recipient, array $headers = [], $mailboxEmail = null, array $attachments = [], $cc = [], $bcc = [])
{
$error_check = false;
if (empty($mailboxEmail)) {
// Send email on behalf of support helpdesk
$supportEmail = $this->container->getParameter('uvdesk.support_email.id');
Expand All @@ -507,7 +506,6 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m
return;
}
} catch (\Exception $e) {
$error_check = true;
// @TODO: Log exception - Mailbox not found
return;
}
Expand All @@ -519,7 +517,6 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m
$mailer = $this->container->get('swiftmailer.mailer' . (('default' == $mailerID) ? '' : ".$mailerID"));
$mailer->getTransport()->setPassword(base64_decode($mailer->getTransport()->getPassword()));
} catch (\Exception $e) {
$error_check = true;
// @TODO: Log exception - Mailer not found
return;
}
Expand Down Expand Up @@ -588,12 +585,8 @@ public function sendMail($subject, $content, $recipient, array $headers = [], $m

return "<$messageId>";
} catch (\Exception $e) {
$error_check = true;
// @TODO: Log exception
}

if ($error_check == true) {
$this->session->getFlashBag()->add('warning', $this->container->get('translator')->trans('Warning ! Swiftmailer not working. An error has occurred while sending emails!'));
$this->session->getFlashBag()->add('warning', $this->container->get('translator')->trans('Warning! Swiftmailer not working. An error has occurred while sending emails!'));
}

return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Webkul\UVDesk\CoreFrameworkBundle\Workflow\Actions;
namespace Webkul\UVDesk\CoreFrameworkBundle\Workflow\Actions\User;

use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
use Webkul\UVDesk\AutomationBundle\Workflow\FunctionalGroup;
Expand All @@ -9,7 +9,7 @@
use Webkul\UVDesk\AutomationBundle\Workflow\Action as WorkflowAction;
use Webkul\UVDesk\CoreFrameworkBundle\Entity\EmailTemplates;
use Webkul\UVDesk\AutomationBundle\Workflow\Event;
use Webkul\UVDesk\AutomationBundle\Workflow\Events\AgentActivity;
use Webkul\UVDesk\AutomationBundle\Workflow\Events\UserActivity;
use Webkul\UVDesk\AutomationBundle\Workflow\Events\CustomerActivity;

class MailUser extends WorkflowAction
Expand Down Expand Up @@ -43,18 +43,18 @@ public static function getOptions(ContainerInterface $container)

public static function applyAction(ContainerInterface $container, Event $event, $value = null)
{
if (!$event instanceof UserActivity) {
return;
}

$user = $event->getUser();
$entityManager = $container->get('doctrine.orm.entity_manager');

if (!$event instanceof AgentActivity && !$event instanceof CustomerActivity) {
$emailTemplate = $entityManager->getRepository(EmailTemplates::class)->findOneById($value);

if (empty($user) || empty($emailTemplate)) {
// @TODO: Send default email template
return;
} else {
$user = $event->getUser();
$emailTemplate = $entityManager->getRepository(EmailTemplates::class)->findOneById($value);

if (empty($user) || empty($emailTemplate)) {
// @TODO: Send default email template
return;
}
}

$emailPlaceholders = $container->get('email.service')->getEmailPlaceholderValues($user);
Expand Down

0 comments on commit cdd43fb

Please sign in to comment.