Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.0' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanjeev Papnoi committed Apr 2, 2021
2 parents dd028f1 + 81fae6f commit 4430778
Show file tree
Hide file tree
Showing 75 changed files with 1,404 additions and 533 deletions.
119 changes: 89 additions & 30 deletions Controller/Account.php

Large diffs are not rendered by default.

34 changes: 24 additions & 10 deletions Controller/AccountXHR.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Symfony\Component\Translation\TranslatorInterface;

class AccountXHR extends Controller
{
private $eventDispatcher;
private $translator;
private $userService;

public function __construct(UserService $userService, EventDispatcherInterface $eventDispatcher, TranslatorInterface $translator)
{
$this->eventDispatcher = $eventDispatcher;
$this->translator = $translator;
$this->userService = $userService;
}

public function listAgentsXHR(Request $request)
{
if (!$this->get('user.service')->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT')) {
if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT')) {
return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
}

Expand Down Expand Up @@ -45,24 +59,24 @@ public function deleteAgent(Request $request)

if ($user) {
if($user->getAgentInstance()->getSupportRole() != "ROLE_SUPER_ADMIN") {
$this->get('user.service')->removeAgent($user);
$this->userService->removeAgent($user);

// Trigger agent delete event
$event = new GenericEvent(CoreWorkflowEvents\Agent\Delete::getId(), [
'entity' => $user,
]);

$this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute', $event);
$this->eventDispatcher->dispatch('uvdesk.automation.workflow.execute', $event);

$json['alertClass'] = 'success';
$json['alertMessage'] = $this->get('translator')->trans('Success ! Agent removed successfully.');
$json['alertMessage'] = $this->translator->trans('Success ! Agent removed successfully.');
} else {
$json['alertClass'] = 'warning';
$json['alertMessage'] = $this->get('translator')->trans("Warning ! You are allowed to remove account owner's account.");
$json['alertMessage'] = $this->translator->trans("Warning ! You are allowed to remove account owner's account.");
}
} else {
$json['alertClass'] = 'danger';
$json['alertMessage'] = $this->get('translator')->trans('Error ! Invalid user id.');
$json['alertMessage'] = $this->translator->trans('Error ! Invalid user id.');
}
}
$response = new Response(json_encode($json));
Expand All @@ -75,7 +89,7 @@ public function savedFiltersXHR(Request $request)
$json = array();

$em = $this->getDoctrine()->getManager();
$user = $this->get('user.service')->getCurrentUser();
$user = $this->userService->getCurrentUser();
$userData = $user->getAgentInstance();

if($request->getMethod() == 'POST') {
Expand All @@ -95,7 +109,7 @@ public function savedFiltersXHR(Request $request)

$json['filter'] = ['id' => $filter->getId(), 'name' => $filter->getName(), 'route' => $filter->getRoute(), 'is_default' => isset($content['is_default'])];
$json['alertClass'] = 'success';
$json['alertMessage'] = $this->get('translator')->trans('Success ! Filter has been saved successfully.');
$json['alertMessage'] = $this->translator->trans('Success ! Filter has been saved successfully.');
} elseif($request->getMethod() == 'PUT' || $request->getMethod() == 'PATCH') {
$content = $request->request->all();
$filter = $em->getRepository('UVDeskCoreFrameworkBundle:SavedFilters')->find($content['id']);
Expand All @@ -113,7 +127,7 @@ public function savedFiltersXHR(Request $request)

$json['filter'] = ['id' => $filter->getId(), 'name' => $filter->getName(), 'route' => $filter->getRoute(), 'is_default' => isset($content['is_default']) ? 1 : 0 ];
$json['alertClass'] = 'success';
$json['alertMessage'] = $this->get('translator')->trans('Success ! Filter has been updated successfully.');
$json['alertMessage'] = $this->translator->trans('Success ! Filter has been updated successfully.');
} elseif($request->getMethod() == 'DELETE') {

$id = $request->attributes->get('filterId');
Expand All @@ -128,7 +142,7 @@ public function savedFiltersXHR(Request $request)
// $em->flush();

$json['alertClass'] = 'success';
$json['alertMessage'] = $this->get('translator')->trans('Success ! Filter has been removed successfully.');
$json['alertMessage'] = $this->translator->trans('Success ! Filter has been removed successfully.');
}

$response = new Response(json_encode($json));
Expand Down
93 changes: 59 additions & 34 deletions Controller/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,39 @@
use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
use Symfony\Component\EventDispatcher\GenericEvent;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Webkul\UVDesk\CoreFrameworkBundle\Utils\TokenGenerator;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Workflow\Events as CoreWorkflowEvents;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Webkul\UVDesk\CoreFrameworkBundle\Services\ReCaptchaService;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
use Symfony\Component\Translation\TranslatorInterface;

class Authentication extends Controller
class Authentication extends AbstractController
{
private $userService;
private $recaptchaService;
private $authenticationUtils;
private $eventDispatcher;
private $translator;

public function __construct(UserService $userService, AuthenticationUtils $authenticationUtils, EventDispatcherInterface $eventDispatcher, TranslatorInterface $translator, ReCaptchaService $recaptchaService)
{
$this->userService = $userService;
$this->recaptchaService = $recaptchaService;
$this->authenticationUtils = $authenticationUtils;
$this->eventDispatcher = $eventDispatcher;
$this->translator = $translator;
}

public function login(Request $request)
{
if (null == $this->get('user.service')->getSessionUser()) {
if (null == $this->userService->getSessionUser()) {
return $this->render('@UVDeskCoreFramework//login.html.twig', [
'last_username' => $this->get('security.authentication_utils')->getLastUsername(),
'error' => $this->get('security.authentication_utils')->getLastAuthenticationError(),
'last_username' => $this->authenticationUtils->getLastUsername(),
'error' => $this->authenticationUtils->getLastAuthenticationError(),
]);
}

Expand All @@ -35,33 +55,38 @@ public function logout(Request $request)
public function forgotPassword(Request $request)
{
$entityManager = $this->getDoctrine()->getManager();
$recaptchaDetails = $this->recaptchaService->getRecaptchaDetails();
if ($request->getMethod() == 'POST') {
$user = new User();
$form = $this->createFormBuilder($user,['csrf_protection' => false])
->add('email',EmailType::class)
->getForm();

$form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
$form->handleRequest($request);

if ($form->isValid()) {
$repository = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($form->getData()->getEmail());

if (!empty($user)) {
// Trigger agent forgot password event
$event = new GenericEvent(CoreWorkflowEvents\UserForgotPassword::getId(), [
'entity' => $user,
]);

$this->get('event_dispatcher')->dispatch('uvdesk.automation.workflow.execute', $event);
$this->addFlash('success', $this->get('translator')->trans('Please check your mail for password update'));

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

} else {
$this->addFlash('warning', $this->get('translator')->trans('This email address is not registered with us'));
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();

$form->submit(['email' => $request->request->get('forgot_password_form')['email']]);
$form->handleRequest($request);

if ($form->isValid()) {
$repository = $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:User');
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($form->getData()->getEmail());

if (!empty($user)) {
// Trigger agent forgot password event
$event = new GenericEvent(CoreWorkflowEvents\UserForgotPassword::getId(), [
'entity' => $user,
]);

$this->eventDispatcher->dispatch('uvdesk.automation.workflow.execute', $event);
$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 All @@ -75,7 +100,7 @@ public function updateCredentials($email, $verificationCode, Request $request, U
$user = $entityManager->getRepository('UVDeskCoreFrameworkBundle:User')->findOneByEmail($email);

if (empty($user) || $user->getVerificationCode() != $verificationCode) {
$this->addFlash('success', $this->get('translator')->trans('You have already update password using this link if you wish to change password again click on forget password link here from login page'));
$this->addFlash('success', $this->translator->trans('You have already update password using this link if you wish to change password again click on forget password link here from login page'));

return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
}
Expand All @@ -90,11 +115,11 @@ public function updateCredentials($email, $verificationCode, Request $request, U
$entityManager->persist($user);
$entityManager->flush();

$this->addFlash('success', $this->get('translator')->trans('Your password has been successfully updated. Login using updated password'));
$this->addFlash('success', $this->translator->trans('Your password has been successfully updated. Login using updated password'));

return $this->redirect($this->generateUrl('helpdesk_knowledgebase'));
} else {
$this->addFlash('success', $this->get('translator')->trans('Please try again, The passwords do not match'));
$this->addFlash('success', $this->translator->trans('Please try again, The passwords do not match'));
}
}

Expand Down
Loading

0 comments on commit 4430778

Please sign in to comment.