This repository has been archived by the owner on Jul 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PRODDEV-463] Introduce automated welcome email for new users feature
- Loading branch information
Vladyslav Solodovnyk
committed
Nov 10, 2021
1 parent
fa57180
commit 9b26a75
Showing
17 changed files
with
478 additions
and
49 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
config/install/openy_gated_content.welcome_email_settings.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
enabled: 1 | ||
email_subject: 'Welcome to Virtual Y!' | ||
email_body: | | ||
<p>Explore your favorite YMCA programs from home or on the go!</p> | ||
<p>Dear [user:display-name],</p> | ||
<p>Thanks for joining our Virtual Y community. We are excited to have you here. With Virtual Y, you can:</p> | ||
<ul> | ||
<li>check out our latest fitness content, updated weekly</li> | ||
<li>join live events to connect with other members, virtually</li> | ||
<li>save your favorite classes, instructors, and content for easy reference next time.</li> | ||
</ul> | ||
<p>See you online!</p> | ||
<p>Your YMCA team</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
openy_gated_content.test_welcome_email: | ||
route_name: openy_gated_content.test_welcome_email | ||
title: 'Test welcome email' | ||
appears_on: | ||
- openy_gated_content.welcome_email_settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
openy_gated_content.settings: | ||
title: 'Virtual YMCA Settings' | ||
route_name: openy_gated_content.settings | ||
base_route: openy_gated_content.settings | ||
openy_gated_content.welcome_email_settings: | ||
title: 'Welcome email settings' | ||
route_name: openy_gated_content.welcome_email_settings | ||
base_route: openy_gated_content.settings | ||
weight: 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php | ||
|
||
namespace Drupal\openy_gated_content\EventSubscriber; | ||
|
||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\openy_gated_content\GCUserService; | ||
use Drupal\openy_gc_auth\Event\GCUserLoginEvent; | ||
use Drupal\openy_gc_auth\GCIdentityProviderManager; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Class GCLogUserLogin Subscriber. | ||
* | ||
* @package Drupal\openy_gated_content\EventSubscriber | ||
*/ | ||
class GCUserLoginSubscriber implements EventSubscriberInterface { | ||
|
||
/** | ||
* The Gated Content User Service. | ||
* | ||
* @var \Drupal\openy_gated_content\GCUserService | ||
*/ | ||
protected $gcUserService; | ||
|
||
/** | ||
* Config factory. | ||
* | ||
* @var \Drupal\Core\Config\ConfigFactoryInterface | ||
*/ | ||
protected $configFactory; | ||
|
||
/** | ||
* The gated content authentication manager. | ||
* | ||
* @var \Drupal\openy_gc_auth\GCIdentityProviderManager | ||
*/ | ||
protected $authManager; | ||
|
||
/** | ||
* Constructs a new GCUserLoginSubscriber. | ||
* | ||
* @param \Drupal\openy_gated_content\GCUserService $gcUserService | ||
* The Gated Content User Service. | ||
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory | ||
* Config factory. | ||
* @param \Drupal\openy_gc_auth\GCIdentityProviderManager $auth_manager | ||
* The gated content authentication manager. | ||
*/ | ||
public function __construct( | ||
GCUserService $gcUserService, | ||
ConfigFactoryInterface $configFactory, | ||
GCIdentityProviderManager $auth_manager | ||
) { | ||
$this->gcUserService = $gcUserService; | ||
$this->configFactory = $configFactory; | ||
$this->authManager = $auth_manager; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function getSubscribedEvents() { | ||
return [ | ||
GCUserLoginEvent::EVENT_NAME => 'onUserLogin', | ||
]; | ||
} | ||
|
||
/** | ||
* Subscribe to the GC user login event dispatched. | ||
* | ||
* @param \Drupal\openy_gc_auth\Event\GCUserLoginEvent $event | ||
* Event object. | ||
*/ | ||
public function onUserLogin(GCUserLoginEvent $event) { | ||
if (!($event->account instanceof AccountInterface)) { | ||
return; | ||
} | ||
if ($event->account->getLastAccessedTime() > 0) { | ||
return; | ||
} | ||
$welcome_email_config = $this->configFactory->get('openy_gated_content.welcome_email_settings'); | ||
if (!$welcome_email_config->get('enabled')) { | ||
return; | ||
} | ||
$gc_auth_config = $this->configFactory->get('openy_gc_auth.settings'); | ||
$active_provider = $gc_auth_config->get('active_provider'); | ||
$plugin_definition = $this->authManager->getDefinition($active_provider, TRUE); | ||
if (!$plugin_definition) { | ||
return; | ||
} | ||
/** @var \Drupal\openy_gc_auth\GCIdentityProviderInterface $plugin_instance */ | ||
$plugin_instance = $this->authManager->createInstance($active_provider); | ||
$plugin_instance->sendWelcomeEmail($event->account); | ||
} | ||
|
||
} |
Oops, something went wrong.