Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cb5bf208 authored by AVINASH GUSAIN's avatar AVINASH GUSAIN
Browse files

applied suggestions

parent 8e1f24b2
Loading
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -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);
+3 −0
Original line number Diff line number Diff line
@@ -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;
+36 −6
Original line number Diff line number Diff line
@@ -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');
		}
	}
}