From 219a436284bd67eecfc65d1f28509d61500ad19b Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 14:03:46 +0530 Subject: [PATCH 01/24] newsletter subscription --- lib/Service/UserService.php | 15 +++++++++++++++ src/Signup.vue | 2 ++ 2 files changed, 17 insertions(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index dbda65c4..463da274 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -448,4 +448,19 @@ class UserService { throw new Exception('Error adding username ' . $username . ' to common data store'); } } + + /** + * Newsletter signup, + * perform call to newsletter app api to signup the user + * + * @param $userEmail string + * @param $listIds array + * @param $userLanguage string + * @return mixed response of the external endpoint + */ + public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage) { + + + return null; + } } diff --git a/src/Signup.vue b/src/Signup.vue index bfb682ea..038ad03f 100644 --- a/src/Signup.vue +++ b/src/Signup.vue @@ -74,6 +74,8 @@ export default { password: this.formData.password, recoveryEmail: this.formData.email, language: this.formData.selectedLanguage, + newsletter_eos: this.formData.newsletter_eos, + newsletter_product: this.formData.newsletter_product, } this.submitForm(data) } -- GitLab From 02f327255f025c854a9ee75562a85f446bf40814 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 14:08:23 +0530 Subject: [PATCH 02/24] newsletter checkdata post --- lib/Controller/AccountController.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 8f9c849b..f021a1d6 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -86,10 +86,12 @@ class AccountController extends Controller { * @param string $username User's username * @param string $password User's password * @param string $language User's language preference + * @param bool $newsletter_eos Users's subscribe to eos newsletter + * @param bool $newsletter_product Users's subscribe to murena product newsletter * * @return \OCP\AppFramework\Http\DataResponse */ - public function create(string $displayname = '', string $recoveryEmail = '', string $username = '', string $password = '', string $language = ''): DataResponse { + public function create(string $displayname = '', string $recoveryEmail = '', string $username = '', string $password = '', string $language = '', bool $newsletter_eos = false, bool $newsletter_product = false): DataResponse { $response = new DataResponse(); -- GitLab From 3deb416f2a505b89e92d87701305cb3f2af88954 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 14:50:51 +0530 Subject: [PATCH 03/24] newsletter checkdata post --- lib/Controller/AccountController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index f021a1d6..258b33b7 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -127,12 +127,26 @@ class AccountController extends Controller { $userEmail = $username.'@'.$mainDomain; $newUserEntry = $this->userService->registerUser($displayname, $recoveryEmail, $username, $userEmail, $password); - $this->userService->setAccountDataLocally($username, $userEmail, $newUserEntry['quota']); $this->userService->createHMEAlias($username, $userEmail); $this->userService->createNewDomainAlias($username, $userEmail); $this->userService->setTOS($username, true); $this->userService->setUserLanguage($username, $language); + if ($newsletter_eos || $newsletter_product) { + $list_ids = []; + + if ($newsletter_eos) { + $list_ids[] = $this->config->getSystemValue('newsletter_eos_list_id'); + } + + if ($newsletter_product) { + $list_ids[] = $this->config->getSystemValue('newsletter_product_list_id'); + } + + if (!empty($list_ids)) { + $this->userService->newsletterSignup($userEmail, $list_ids, $language); + } + } if($recoveryEmail !== '') { $this->userService->setUnverifiedRecoveryEmail($username, $recoveryEmail); -- GitLab From 3c7c302679a6d3860cf787986033d54bc4f0e2e9 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 15:07:48 +0530 Subject: [PATCH 04/24] newsletter checkdata post --- lib/Service/UserService.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 463da274..f2960f41 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -459,8 +459,25 @@ class UserService { * @return mixed response of the external endpoint */ public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage) { + $newsletterApiUrl = $this->apiConfig['newsletter_base_url']; + + if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { + return; + } + $endpoint = '/api/signup'; + $url = $newsletterApiUrl . $endpoint ; + + $params = [ + 'userEmail' => $userEmail, + 'listIds' => $listIds, + 'userLanguage' => $userLanguage + ]; + + $this->curl->post($url, $params, $headers); - return null; + if ($this->curl->getLastStatusCode() !== 200) { + throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); + } } } -- GitLab From fa2f6f72676f30608253412bb6e9822db4c2da4f Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 15:36:19 +0530 Subject: [PATCH 05/24] newsletter checkdata post --- lib/Controller/AccountController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 258b33b7..87950f1c 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -20,6 +20,7 @@ use OCP\ISession; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; +use OCP\IConfig; class AccountController extends Controller { protected $appName; @@ -30,6 +31,8 @@ class AccountController extends Controller { private $session; private $userSession; private $urlGenerator; + /** @var IConfig */ + private $config; private const SESSION_USERNAME_CHECK = 'username_check_passed'; private const CAPTCHA_VERIFIED_CHECK = 'captcha_verified'; @@ -41,7 +44,8 @@ class AccountController extends Controller { IFactory $l10nFactory, IUserSession $userSession, IURLGenerator $urlGenerator, - ISession $session + ISession $session, + IConfig $config ) { parent::__construct($AppName, $request); $this->appName = $AppName; @@ -50,6 +54,7 @@ class AccountController extends Controller { $this->l10nFactory = $l10nFactory; $this->session = $session; $this->userSession = $userSession; + $this->config = $config; $this->urlGenerator = $urlGenerator; } -- GitLab From ddad1474c3996e42a9a2290a07037691e7d3ca8a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 15:38:05 +0530 Subject: [PATCH 06/24] newsletter checkdata post --- lib/Controller/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 87950f1c..a4cf946b 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -15,12 +15,12 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; use OCP\IRequest; use OCP\ISession; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\L10N\IFactory; -use OCP\IConfig; class AccountController extends Controller { protected $appName; -- GitLab From a41231e9a422c3d94ee201c6fa16b0607a1a9de9 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 15:52:22 +0530 Subject: [PATCH 07/24] newsletter checkdata post --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index f2960f41..d790fa87 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -459,7 +459,7 @@ class UserService { * @return mixed response of the external endpoint */ public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage) { - $newsletterApiUrl = $this->apiConfig['newsletter_base_url']; + $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { return; -- GitLab From 6eeb6d5dce7cd4ec9d26f6202a93071df4324c5c Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 15:58:31 +0530 Subject: [PATCH 08/24] newsletter checkdata post --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index d790fa87..3b3123b5 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -474,7 +474,7 @@ class UserService { 'userLanguage' => $userLanguage ]; - $this->curl->post($url, $params, $headers); + $this->curl->post($url, $params); if ($this->curl->getLastStatusCode() !== 200) { throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); -- GitLab From c646eaef4cbef8e201e6aa5b3824bb89278abc33 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 16:21:00 +0530 Subject: [PATCH 09/24] fix header --- lib/Service/UserService.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 3b3123b5..e79a2c2d 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -473,8 +473,12 @@ class UserService { 'listIds' => $listIds, 'userLanguage' => $userLanguage ]; - - $this->curl->post($url, $params); + $params_string = json_encode($params); + $headers = [ + 'Content-Type: application/json', + 'Content-Length: ' . strlen($params_string) + ]; + $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); -- GitLab From 2bfd2777076666fdf8f8e96648af7d2fb4dac4f3 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 16:27:36 +0530 Subject: [PATCH 10/24] fix header --- lib/Service/CurlService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index d3b132d5..fa859256 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -104,7 +104,6 @@ class CurlService { if ($errno = curl_errno($ch)) { - var_dump($errno); $errorMessage = curl_strerror($errno); throw new Exception("Curl error $errno - $errorMessage"); } -- GitLab From 5687298f3a51e33df78eb7127b86b93490347861 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 16:52:55 +0530 Subject: [PATCH 11/24] fix parm --- lib/Service/UserService.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e79a2c2d..34c23483 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -469,9 +469,9 @@ class UserService { $url = $newsletterApiUrl . $endpoint ; $params = [ - 'userEmail' => $userEmail, - 'listIds' => $listIds, - 'userLanguage' => $userLanguage + 'email' => $userEmail, + 'list_ids' => $listIds, + 'contact_language' => $userLanguage ]; $params_string = json_encode($params); $headers = [ -- GitLab From d9280aa5a61082382fb0e11a78c623e2f7868ab8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Wed, 20 Dec 2023 17:13:50 +0530 Subject: [PATCH 12/24] fix json encode --- lib/Service/CurlService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index fa859256..8836994f 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -82,6 +82,10 @@ class CurlService { break; case 'POST': $options[CURLOPT_POST] = true; + $jsonContent = in_array('Content-Type: application/json', $headers); + if ($jsonContent) { + $params = json_encode($params); + } $options[CURLOPT_POSTFIELDS] = $params; break; case 'DELETE': -- GitLab From b8a36d1a9320a2c54c67302f140f172d280e18b3 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 21 Dec 2023 10:17:01 +0530 Subject: [PATCH 13/24] applied suggestions --- lib/Controller/AccountController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index a4cf946b..d7c7461f 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -32,7 +32,7 @@ class AccountController extends Controller { private $userSession; private $urlGenerator; /** @var IConfig */ - private $config; + private IConfig $config; private const SESSION_USERNAME_CHECK = 'username_check_passed'; private const CAPTCHA_VERIFIED_CHECK = 'captcha_verified'; @@ -139,13 +139,13 @@ class AccountController extends Controller { $this->userService->setUserLanguage($username, $language); if ($newsletter_eos || $newsletter_product) { $list_ids = []; - + $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); if ($newsletter_eos) { - $list_ids[] = $this->config->getSystemValue('newsletter_eos_list_id'); + $list_ids[] = $newsletterListIds['eos']; } if ($newsletter_product) { - $list_ids[] = $this->config->getSystemValue('newsletter_product_list_id'); + $list_ids[] = $newsletterListIds['product']; } if (!empty($list_ids)) { -- GitLab From afccebade554a0786a5a97d3ff73c1e5260dbf5a Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 21 Dec 2023 10:18:34 +0530 Subject: [PATCH 14/24] applied suggestions --- lib/Controller/AccountController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index d7c7461f..30d6e97e 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -139,7 +139,7 @@ class AccountController extends Controller { $this->userService->setUserLanguage($username, $language); if ($newsletter_eos || $newsletter_product) { $list_ids = []; - $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); + $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); if ($newsletter_eos) { $list_ids[] = $newsletterListIds['eos']; } -- GitLab From 09f6f7f5b9f34f00792e9d7a3e2469396509746a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Dec 2023 04:47:19 +0000 Subject: [PATCH 15/24] applied suggestion --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 34c23483..e9ea4165 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -458,7 +458,7 @@ class UserService { * @param $userLanguage string * @return mixed response of the external endpoint */ - public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage) { + public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage): void{ $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { -- GitLab From 9a5e073cad9bd8037a47475451dd6e69a468cbfa Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 22 Dec 2023 04:47:31 +0000 Subject: [PATCH 16/24] Apply 1 suggestion(s) to 1 file(s) --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e9ea4165..251d16fa 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -481,7 +481,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); + $this->logger->error('Error adding email ' . $userEmail . ' to newsletter app'); } } } -- GitLab From 7b27f502c842a70e949fec8ebe31db67d652b148 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 10:23:07 +0530 Subject: [PATCH 17/24] fix formatting --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 251d16fa..f3f09b70 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -458,7 +458,7 @@ class UserService { * @param $userLanguage string * @return mixed response of the external endpoint */ - public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage): void{ + public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage): void { $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { -- GitLab From 8e1f24b219a37b1628fd4b35f059e3cf28975f95 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 21:12:57 +0530 Subject: [PATCH 18/24] camelcase --- lib/Controller/AccountController.php | 12 ++++++------ src/Signup.vue | 8 ++++---- src/signup/RegistrationForm.vue | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 30d6e97e..ef0a034e 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -91,12 +91,12 @@ class AccountController extends Controller { * @param string $username User's username * @param string $password User's password * @param string $language User's language preference - * @param bool $newsletter_eos Users's subscribe to eos newsletter - * @param bool $newsletter_product Users's subscribe to murena product newsletter + * @param bool $newsletterEos Users's subscribe to eos newsletter + * @param bool $newsletterProduct Users's subscribe to murena product newsletter * * @return \OCP\AppFramework\Http\DataResponse */ - public function create(string $displayname = '', string $recoveryEmail = '', string $username = '', string $password = '', string $language = '', bool $newsletter_eos = false, bool $newsletter_product = false): DataResponse { + public function create(string $displayname = '', string $recoveryEmail = '', string $username = '', string $password = '', string $language = '', bool $newsletterEos = false, bool $newsletterProduct = false): DataResponse { $response = new DataResponse(); @@ -137,14 +137,14 @@ class AccountController extends Controller { $this->userService->createNewDomainAlias($username, $userEmail); $this->userService->setTOS($username, true); $this->userService->setUserLanguage($username, $language); - if ($newsletter_eos || $newsletter_product) { + if ($newsletterEos || $newsletterProduct) { $list_ids = []; $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); - if ($newsletter_eos) { + if ($newsletterEos) { $list_ids[] = $newsletterListIds['eos']; } - if ($newsletter_product) { + if ($newsletterProduct) { $list_ids[] = $newsletterListIds['product']; } diff --git a/src/Signup.vue b/src/Signup.vue index 038ad03f..8be5e5cf 100644 --- a/src/Signup.vue +++ b/src/Signup.vue @@ -40,8 +40,8 @@ export default { captchaInput: '', email: '', accepttns: false, - newsletter_eos: false, - newsletter_product: false, + newsletterEos: false, + newsletterProduct: false, selectedLanguage: 'en', }, appName: APPLICATION_NAME, @@ -74,8 +74,8 @@ export default { password: this.formData.password, recoveryEmail: this.formData.email, language: this.formData.selectedLanguage, - newsletter_eos: this.formData.newsletter_eos, - newsletter_product: this.formData.newsletter_product, + newsletterEos: this.formData.newsletterEos, + newsletterProduct: this.formData.newsletterProduct, } this.submitForm(data) } diff --git a/src/signup/RegistrationForm.vue b/src/signup/RegistrationForm.vue index ff81f3d7..5ce865c9 100644 --- a/src/signup/RegistrationForm.vue +++ b/src/signup/RegistrationForm.vue @@ -125,7 +125,7 @@
@@ -139,7 +139,7 @@
-- GitLab From cb5bf208788415a37bcaf599399291026e7dc4a8 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 21:45:48 +0530 Subject: [PATCH 19/24] applied suggestions --- lib/Controller/AccountController.php | 16 +---------- lib/Service/CurlService.php | 3 ++ lib/Service/UserService.php | 42 ++++++++++++++++++++++++---- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index ef0a034e..71617cda 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -137,21 +137,7 @@ class AccountController extends Controller { $this->userService->createNewDomainAlias($username, $userEmail); $this->userService->setTOS($username, true); $this->userService->setUserLanguage($username, $language); - if ($newsletterEos || $newsletterProduct) { - $list_ids = []; - $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); - if ($newsletterEos) { - $list_ids[] = $newsletterListIds['eos']; - } - - if ($newsletterProduct) { - $list_ids[] = $newsletterListIds['product']; - } - - if (!empty($list_ids)) { - $this->userService->newsletterSignup($userEmail, $list_ids, $language); - } - } + $this->userService->setNewsletterSignup($newsletterEos, $newsletterProduct, $userEmail, $language); if($recoveryEmail !== '') { $this->userService->setUnverifiedRecoveryEmail($username, $recoveryEmail); diff --git a/lib/Service/CurlService.php b/lib/Service/CurlService.php index 8836994f..9cf95068 100644 --- a/lib/Service/CurlService.php +++ b/lib/Service/CurlService.php @@ -85,6 +85,9 @@ class CurlService { $jsonContent = in_array('Content-Type: application/json', $headers); if ($jsonContent) { $params = json_encode($params); + if (json_last_error() !== JSON_ERROR_NONE) { + throw new Exception('JSON encoding failed: ' . json_last_error_msg()); + } } $options[CURLOPT_POSTFIELDS] = $params; break; diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index f3f09b70..68b26ae6 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -448,17 +448,47 @@ class UserService { throw new Exception('Error adding username ' . $username . ' to common data store'); } } - /** * Newsletter signup, * perform call to newsletter app api to signup the user * - * @param $userEmail string - * @param $listIds array - * @param $userLanguage string + * @param bool $newsletterEos + * @param bool $newsletterProduct + * @param string $userEmail + * @param string $language + * @return void + */ + public function setNewsletterSignup(bool $newsletterEos, bool $newsletterProduct, string $userEmail, string $language): void { + if ($newsletterEos || $newsletterProduct) { + $listIds = []; + $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); + if ($newsletterEos) { + $listIds[] = $newsletterListIds['eos']; + } + + if ($newsletterProduct) { + $listIds[] = $newsletterListIds['product']; + } + + if (!empty($listIds)) { + try { + $this->signupForNewsletter($userEmail, $listIds, $language); + } catch (Exception $e) { + $this->logger->error('Signup for newsletter failed: ' . $e->getMessage()); + } + } + } + } + /** + * Signup for newsletter, + * perform call to newsletter app api to signup the user + * + * @param string $userEmail + * @param Array $listIds + * @param string $userLanguage * @return mixed response of the external endpoint */ - public function newsletterSignup(string $userEmail, array $listIds, string $userLanguage): void { + public function signupForNewsletter(string $userEmail, array $listIds, string $userLanguage): void { $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { @@ -481,7 +511,7 @@ class UserService { $this->curl->post($url, $params, $headers); if ($this->curl->getLastStatusCode() !== 200) { - $this->logger->error('Error adding email ' . $userEmail . ' to newsletter app'); + throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); } } } -- GitLab From ec0510924c1ba6aa3efee991c5ba14d3a7d50453 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 21:56:31 +0530 Subject: [PATCH 20/24] newsletter service added --- lib/Controller/AccountController.php | 6 ++- lib/Service/NewsLetterService.php | 73 ++++++++++++++++++++++++++++ lib/Service/UserService.php | 66 ------------------------- 3 files changed, 78 insertions(+), 67 deletions(-) create mode 100644 lib/Service/NewsLetterService.php diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 71617cda..88cb74b6 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -9,6 +9,7 @@ namespace OCA\EcloudAccounts\Controller; use Exception; use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Service\CaptchaService; +use OCA\EcloudAccounts\Service\NewsLetterService; use OCA\EcloudAccounts\Service\UserService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; @@ -26,6 +27,7 @@ class AccountController extends Controller { protected $appName; protected $request; private $userService; + private $newsletterService; private $captchaService; protected $l10nFactory; private $session; @@ -40,6 +42,7 @@ class AccountController extends Controller { $AppName, IRequest $request, UserService $userService, + NewsLetterService $newsletterService, CaptchaService $captchaService, IFactory $l10nFactory, IUserSession $userSession, @@ -50,6 +53,7 @@ class AccountController extends Controller { parent::__construct($AppName, $request); $this->appName = $AppName; $this->userService = $userService; + $this->newsletterService = $newsletterService; $this->captchaService = $captchaService; $this->l10nFactory = $l10nFactory; $this->session = $session; @@ -137,7 +141,7 @@ class AccountController extends Controller { $this->userService->createNewDomainAlias($username, $userEmail); $this->userService->setTOS($username, true); $this->userService->setUserLanguage($username, $language); - $this->userService->setNewsletterSignup($newsletterEos, $newsletterProduct, $userEmail, $language); + $this->newsletterService->setNewsletterSignup($newsletterEos, $newsletterProduct, $userEmail, $language); if($recoveryEmail !== '') { $this->userService->setUnverifiedRecoveryEmail($username, $recoveryEmail); diff --git a/lib/Service/NewsLetterService.php b/lib/Service/NewsLetterService.php new file mode 100644 index 00000000..5d08f0ca --- /dev/null +++ b/lib/Service/NewsLetterService.php @@ -0,0 +1,73 @@ +userManager = $userManager; + $this->config = $config; + $this->curl = $curlService; + $this->logger = $logger; + } + + public function setNewsletterSignup(bool $newsletterEos, bool $newsletterProduct, string $userEmail, string $language): void { + if ($newsletterEos || $newsletterProduct) { + $listIds = []; + $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); + if ($newsletterEos) { + $listIds[] = $newsletterListIds['eos']; + } + + if ($newsletterProduct) { + $listIds[] = $newsletterListIds['product']; + } + + if (!empty($listIds)) { + try { + $this->signupForNewsletter($userEmail, $listIds, $language); + } catch (Exception $e) { + $this->logger->error('Signup for newsletter failed: ' . $e->getMessage()); + } + } + } + } + + private function signupForNewsletter(string $userEmail, array $listIds, string $userLanguage): void { + $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); + + if (empty($newsletterApiUrl)) { + return; + } + + $endpoint = '/api/signup'; + $url = $newsletterApiUrl . $endpoint; + + $params = [ + 'email' => $userEmail, + 'list_ids' => $listIds, + 'contact_language' => $userLanguage + ]; + $params_string = json_encode($params); + $headers = [ + 'Content-Type: application/json', + 'Content-Length: ' . strlen($params_string) + ]; + $this->curl->post($url, $params, $headers); + + if ($this->curl->getLastStatusCode() !== 200) { + throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); + } + } +} diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 68b26ae6..dbda65c4 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -448,70 +448,4 @@ class UserService { throw new Exception('Error adding username ' . $username . ' to common data store'); } } - /** - * Newsletter signup, - * perform call to newsletter app api to signup the user - * - * @param bool $newsletterEos - * @param bool $newsletterProduct - * @param string $userEmail - * @param string $language - * @return void - */ - public function setNewsletterSignup(bool $newsletterEos, bool $newsletterProduct, string $userEmail, string $language): void { - if ($newsletterEos || $newsletterProduct) { - $listIds = []; - $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); - if ($newsletterEos) { - $listIds[] = $newsletterListIds['eos']; - } - - if ($newsletterProduct) { - $listIds[] = $newsletterListIds['product']; - } - - if (!empty($listIds)) { - try { - $this->signupForNewsletter($userEmail, $listIds, $language); - } catch (Exception $e) { - $this->logger->error('Signup for newsletter failed: ' . $e->getMessage()); - } - } - } - } - /** - * Signup for newsletter, - * perform call to newsletter app api to signup the user - * - * @param string $userEmail - * @param Array $listIds - * @param string $userLanguage - * @return mixed response of the external endpoint - */ - public function signupForNewsletter(string $userEmail, array $listIds, string $userLanguage): void { - $newsletterApiUrl = $this->config->getSystemValue('newsletter_base_url', ''); - - if (!isset($newsletterApiUrl) || empty($newsletterApiUrl)) { - return; - } - - $endpoint = '/api/signup'; - $url = $newsletterApiUrl . $endpoint ; - - $params = [ - 'email' => $userEmail, - 'list_ids' => $listIds, - 'contact_language' => $userLanguage - ]; - $params_string = json_encode($params); - $headers = [ - 'Content-Type: application/json', - 'Content-Length: ' . strlen($params_string) - ]; - $this->curl->post($url, $params, $headers); - - if ($this->curl->getLastStatusCode() !== 200) { - throw new Exception('Error adding email ' . $userEmail . ' to newsletter app'); - } - } } -- GitLab From 4e25395923a776616eb65fb62b6afa5dba1b1c47 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 22:08:43 +0530 Subject: [PATCH 21/24] newsletter service added --- lib/Service/NewsLetterService.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/Service/NewsLetterService.php b/lib/Service/NewsLetterService.php index 5d08f0ca..effad8e6 100644 --- a/lib/Service/NewsLetterService.php +++ b/lib/Service/NewsLetterService.php @@ -10,9 +10,13 @@ use OCP\ILogger; use OCP\IUserManager; class NewsLetterService { + /** @var IUserManager */ private $userManager; + /** @var IConfig */ private $config; + /** @var CurlService */ private $curl; + /** @var ILogger */ private $logger; public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger) { -- GitLab From d0b3a8936bf7cb79c01f84d3a13d55e94b830674 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Fri, 22 Dec 2023 22:09:32 +0530 Subject: [PATCH 22/24] newsletter service added --- lib/Service/NewsLetterService.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/Service/NewsLetterService.php b/lib/Service/NewsLetterService.php index effad8e6..5062c710 100644 --- a/lib/Service/NewsLetterService.php +++ b/lib/Service/NewsLetterService.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Service; +require __DIR__ . '/../../vendor/autoload.php'; + use Exception; use OCP\IConfig; use OCP\ILogger; -- GitLab From cdce37175e5211c9a94849a3185667f007060a64 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 26 Dec 2023 15:33:20 +0530 Subject: [PATCH 23/24] moved try block up --- lib/Service/NewsLetterService.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/Service/NewsLetterService.php b/lib/Service/NewsLetterService.php index 5062c710..70409f50 100644 --- a/lib/Service/NewsLetterService.php +++ b/lib/Service/NewsLetterService.php @@ -29,24 +29,25 @@ class NewsLetterService { } public function setNewsletterSignup(bool $newsletterEos, bool $newsletterProduct, string $userEmail, string $language): void { - if ($newsletterEos || $newsletterProduct) { - $listIds = []; - $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); - if ($newsletterEos) { - $listIds[] = $newsletterListIds['eos']; - } - - if ($newsletterProduct) { - $listIds[] = $newsletterListIds['product']; - } + try { + if ($newsletterEos || $newsletterProduct) { + $listIds = []; + if ($newsletterEos) { + $listIds[] = $newsletterListIds['eos']; + } - if (!empty($listIds)) { - try { + if ($newsletterProduct) { + $listIds[] = $newsletterListIds['product']; + } + + if (!empty($listIds)) { + $this->signupForNewsletter($userEmail, $listIds, $language); - } catch (Exception $e) { - $this->logger->error('Signup for newsletter failed: ' . $e->getMessage()); + } } + } catch (Exception $e) { + $this->logger->error('Signup for newsletter failed: ' . $e->getMessage()); } } -- GitLab From f3f7cf5158bba8087675dd0215f127e3c61ad924 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Tue, 26 Dec 2023 16:02:37 +0530 Subject: [PATCH 24/24] fix config --- lib/Service/NewsLetterService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/NewsLetterService.php b/lib/Service/NewsLetterService.php index 70409f50..110861c6 100644 --- a/lib/Service/NewsLetterService.php +++ b/lib/Service/NewsLetterService.php @@ -32,6 +32,7 @@ class NewsLetterService { try { if ($newsletterEos || $newsletterProduct) { $listIds = []; + $newsletterListIds = $this->config->getSystemValue('newsletter_list_ids'); if ($newsletterEos) { $listIds[] = $newsletterListIds['eos']; } -- GitLab