Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PersonifyAuthController.php to not grant access to Cancelled/Expired members (master) #279

Merged
merged 9 commits into from
Mar 1, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Drupal\openy_gc_auth_personify\Controller;

use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\Core\Routing\TrustedRedirectResponse;
use Drupal\Core\Url;
use Drupal\openy_gc_auth\Event\GCUserLogoutEvent;
use Drupal\personify\PersonifyClient;
use Drupal\personify\PersonifySSO;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -63,6 +65,13 @@ class PersonifyAuthController extends ControllerBase {
*/
protected $gcUserAuthorizer;

/**
* Event Dispatcher.
*
* @var \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
*/
protected $eventDispatcher;

/**
* PersonifyAuthController constructor.
*
Expand All @@ -78,21 +87,25 @@ class PersonifyAuthController extends ControllerBase {
* The messenger.
* @param \Drupal\openy_gc_auth\GCUserAuthorizer $gcUserAuthorizer
* The Gated User Authorizer.
* @param \Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher $eventDispatcher
* Event Dispatcher.
*/
public function __construct(
PersonifySSO $personifySSO,
PersonifyClient $personifyClient,
ConfigFactoryInterface $configFactory,
LoggerChannelFactory $loggerChannelFactory,
MessengerInterface $messenger,
GCUserAuthorizer $gcUserAuthorizer
GCUserAuthorizer $gcUserAuthorizer,
ContainerAwareEventDispatcher $eventDispatcher
) {
$this->personifySSO = $personifySSO;
$this->personifyClient = $personifyClient;
$this->configFactory = $configFactory;
$this->logger = $loggerChannelFactory->get('openy_gc_auth_personify');
$this->messenger = $messenger;
$this->gcUserAuthorizer = $gcUserAuthorizer;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand All @@ -105,7 +118,8 @@ public static function create(ContainerInterface $container) {
$container->get('config.factory'),
$container->get('logger.factory'),
$container->get('messenger'),
$container->get('openy_gc_auth.user_authorizer')
$container->get('openy_gc_auth.user_authorizer'),
$container->get('event_dispatcher')
);
}

Expand Down Expand Up @@ -135,8 +149,9 @@ public function auth(Request $request) {
]);
}
else {
user_cookie_delete('personify_authorized');
user_cookie_delete('personify_time');
$request->cookies->set('Drupal_visitor_personify_authorized', $token);
$event = new GCUserLogoutEvent();
$this->eventDispatcher->dispatch(GCUserLogoutEvent::EVENT_NAME, $event);

$path = URL::fromUserInput(
$this->configFactory->get('openy_gated_content.settings')->get('virtual_y_login_url'),
Expand Down