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

Commit beed2fd1 authored by Ronak Patel's avatar Ronak Patel
Browse files

Resolved feedbacks

parent e50dcf6d
Loading
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -13,12 +13,11 @@ class WeeklyBlacklistedDomainsJob extends TimedJob {
	private LoggerInterface $logger;
	private UserService $userService;
	private ITimeFactory $timeFactory;


	public const INTERVAL_PERIOD = 7 * 24 * 60 * 60;// Run for 7 days
	public function __construct(LoggerInterface $logger, ITimeFactory $timeFactory, UserService $userService) {
		parent::__construct($timeFactory);

		$this->setInterval(7 * 24 * 60 * 60); // Run for 7 days
		$this->setInterval(self::INTERVAL_PERIOD);
		$this->timeFactory = $timeFactory;
		$this->userService = $userService;
		$this->logger = $logger;
@@ -28,7 +27,7 @@ class WeeklyBlacklistedDomainsJob extends TimedJob {
		try {
			$this->userService->updateBlacklistedDomains();
		} catch (\Exception $e) {
			$this->logger->error('Error running blacklisted domain migration', ['exception' => $e]);
			$this->logger->logException('Error updating blacklisted domains for account creation', ['exception' => $e]);
			return;
		}
	}
+3 −2
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ declare(strict_types=1);

namespace OCA\EcloudAccounts\Command;

use OCA\EcloudAccounts\AppInfo\Application;
use OCA\EcloudAccounts\Service\UserService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
@@ -18,12 +19,12 @@ class MigrateBlacklistedDomains extends Command {
	}

	protected function configure() {
		$this->setName('ecloud-accounts:migrate-blacklisted-domains')->setDescription('Migrate blacklisted domains');
		$this->setName(Application::APP_ID.':migrate-blacklisted-domains')->setDescription('Migrate blacklisted domains');
	}

	protected function execute(InputInterface $input, OutputInterface $output): int {
		$this->userService->updateBlacklistedDomains();
		$output->writeln('Domains migrated successfully.');
		$output->writeln('Updated blacklisted domains for creation.');
		return 1;
	}
}
+10 −4
Original line number Diff line number Diff line
@@ -285,12 +285,18 @@ class UserService {
	 * @return bool True if the email domain is blacklisted, false otherwise.
	 */
	public function isBlacklistedEmail(string $email): bool {
		// Get the blacklisted domains from configuration
		$blacklistedDomainsInJson = $this->config->getAppValue(Application::APP_ID, 'blacklisted_domains');
		$blacklistedDomains = json_decode($blacklistedDomainsInJson, true);
		
		$json_data = $this->config->getAppValue(Application::APP_ID, 'blacklisted_domains');
		$blacklisted_domains = json_decode($json_data, true);
		// Split the email address into parts using explode
		$emailParts = explode('@', $email);
		
		$email_domain = strtolower(substr(strrchr($email, "@"), 1));
		if (in_array($email_domain, $blacklisted_domains)) {
		// Extract the domain part
		$emailDomain = strtolower(end($emailParts));
		
		// Check if the email domain is in the blacklisted domains array
		if (in_array($emailDomain, $blacklistedDomains)) {
			return true; // Email domain is blacklisted
		}
		return false; // Email domain is not blacklisted