From d6a82d23270a804434e9141cec9da2d8e9cd95cb Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 23 Apr 2025 14:38:39 +0530 Subject: [PATCH 1/3] Fix recovery email logic as we removed banner; also lint --- lib/AppInfo/Application.php | 2 +- lib/Command/CreatePopularDomain.php | 2 +- .../BeforeTemplateRenderedListener.php | 14 +++---- lib/Service/DomainService.php | 40 +++++++++---------- lib/Service/RecoveryEmailService.php | 4 +- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e77c83e..87ffffd 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,6 +32,7 @@ use OCA\EmailRecovery\Listeners\BeforeUserDeletedListener; use OCA\EmailRecovery\Listeners\BeforeUserRegisteredListener; use OCA\EmailRecovery\Listeners\UserConfigChangedListener; use OCA\EmailRecovery\Notification\Notifier; +use OCA\EmailRecovery\SetupChecks\EcloudAccountsIsEnableCheck; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -39,7 +40,6 @@ use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; use OCP\Notification\IManager as INotificationManager; use OCP\User\Events\BeforeUserDeletedEvent; -use OCA\EmailRecovery\SetupChecks\EcloudAccountsIsEnableCheck; use OCP\User\Events\UserConfigChangedEvent; class Application extends App implements IBootstrap { diff --git a/lib/Command/CreatePopularDomain.php b/lib/Command/CreatePopularDomain.php index a19f96b..9fa3af6 100644 --- a/lib/Command/CreatePopularDomain.php +++ b/lib/Command/CreatePopularDomain.php @@ -6,8 +6,8 @@ namespace OCA\EmailRecovery\Command; use OCA\EmailRecovery\AppInfo\Application; use OCA\EmailRecovery\Service\DomainService; -use OCP\ILogger; use OCP\Files\IAppData; +use OCP\ILogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; diff --git a/lib/Listeners/BeforeTemplateRenderedListener.php b/lib/Listeners/BeforeTemplateRenderedListener.php index 5a65944..ff2f37c 100644 --- a/lib/Listeners/BeforeTemplateRenderedListener.php +++ b/lib/Listeners/BeforeTemplateRenderedListener.php @@ -32,13 +32,13 @@ class BeforeTemplateRenderedListener implements IEventListener { return; } if (($event->getResponse()->getRenderAs() === TemplateResponse::RENDER_AS_USER) && $event->isLoggedIn() && !empty($this->userId)) { - // $recoveryEmail = $this->recoveryEmailService->getRecoveryEmail($this->userId); - // if ($recoveryEmail === '') { - $unverifiedRecoveryEmail = $this->recoveryEmailService->getUnverifiedRecoveryEmail($this->userId); - $this->initialState->provideInitialState('unverifiedRecoveryEmail', $unverifiedRecoveryEmail); - $this->util->addStyle($this->appName, 'email-recovery'); - $this->util->addScript($this->appName, $this->appName . '-email-recovery'); - //} + $recoveryEmail = $this->recoveryEmailService->getRecoveryEmail($this->userId); + if ($recoveryEmail === '') { + $unverifiedRecoveryEmail = $this->recoveryEmailService->getUnverifiedRecoveryEmail($this->userId); + $this->initialState->provideInitialState('unverifiedRecoveryEmail', $unverifiedRecoveryEmail); + $this->util->addStyle($this->appName, 'email-recovery'); + $this->util->addScript($this->appName, $this->appName . '-email-recovery'); + } } } } diff --git a/lib/Service/DomainService.php b/lib/Service/DomainService.php index de76285..10ddf08 100644 --- a/lib/Service/DomainService.php +++ b/lib/Service/DomainService.php @@ -4,13 +4,13 @@ declare(strict_types=1); namespace OCA\EmailRecovery\Service; +use GuzzleHttp\Client; +use GuzzleHttp\Exception\RequestException; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\Files\SimpleFS\ISimpleFile; -use OCP\ILogger; -use GuzzleHttp\Client; -use GuzzleHttp\Exception\RequestException; use OCP\IL10N; +use OCP\ILogger; class DomainService { private ILogger $logger; @@ -119,26 +119,26 @@ class DomainService { /** * Get domains from a file. */ -private function getDomainsFromFile(string $filename, IL10N $l): array { - try { - // Attempt to get and read the file - $file = $this->getDomainsFile($filename); - $content = $file->getContent(); - if (empty($content)) { + private function getDomainsFromFile(string $filename, IL10N $l): array { + try { + // Attempt to get and read the file + $file = $this->getDomainsFile($filename); + $content = $file->getContent(); + if (empty($content)) { + return []; + } + // Decode JSON content + return json_decode($content, true, 512, JSON_THROW_ON_ERROR) ?? []; + } catch (NotFoundException $e) { + // File not found, treat as no domains configured + $this->logger->warning("File $filename not found. Returning an empty domain list."); return []; + } catch (\Throwable $e) { + // Other errors indicate a serious issue (e.g., unreadable file) + $this->logger->error("Error reading $filename: " . $e->getMessage()); + throw new \RuntimeException($l->t('The email could not be verified. Please try again later.')); } - // Decode JSON content - return json_decode($content, true, 512, JSON_THROW_ON_ERROR) ?? []; - } catch (NotFoundException $e) { - // File not found, treat as no domains configured - $this->logger->warning("File $filename not found. Returning an empty domain list."); - return []; - } catch (\Throwable $e) { - // Other errors indicate a serious issue (e.g., unreadable file) - $this->logger->error("Error reading $filename: " . $e->getMessage()); - throw new \RuntimeException($l->t('The email could not be verified. Please try again later.')); } -} /** * Save domains to a file. */ diff --git a/lib/Service/RecoveryEmailService.php b/lib/Service/RecoveryEmailService.php index e4532ff..a779516 100644 --- a/lib/Service/RecoveryEmailService.php +++ b/lib/Service/RecoveryEmailService.php @@ -12,6 +12,8 @@ use OCA\EmailRecovery\Exception\RecoveryEmailAlreadyFoundException; use OCA\EmailRecovery\Exception\SameRecoveryEmailAsEmailException; use OCA\EmailRecovery\Exception\TooManyVerificationAttemptsException; use OCP\Defaults; +use OCP\Http\Client\IClientService; +use OCP\ICacheFactory; use OCP\IConfig; use OCP\IL10N; use OCP\ILogger; @@ -24,8 +26,6 @@ use OCP\Mail\IEMailTemplate; use OCP\Mail\IMailer; use OCP\Security\VerificationToken\IVerificationToken; use OCP\Util; -use OCP\ICacheFactory; -use OCP\Http\Client\IClientService; class RecoveryEmailService { private ILogger $logger; -- GitLab From 27705782ee834f2c186887b93ae28d11589db5c1 Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 24 Apr 2025 22:22:28 +0530 Subject: [PATCH 2/3] Also rollback MR 84 --- scss/email-recovery.scss | 2 +- src/email-recovery.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/scss/email-recovery.scss b/scss/email-recovery.scss index facc5c2..aa010b6 100644 --- a/scss/email-recovery.scss +++ b/scss/email-recovery.scss @@ -7,7 +7,7 @@ box-sizing: border-box; justify-content: center; align-items: center; - background: var(--color-primary-element); + background: #333333; color: #ffffff; font-size: 16px; font-weight: 400; diff --git a/src/email-recovery.js b/src/email-recovery.js index 93299f5..5e42093 100644 --- a/src/email-recovery.js +++ b/src/email-recovery.js @@ -1,3 +1,4 @@ +import { generateUrl } from '@nextcloud/router' import { loadState } from '@nextcloud/initial-state' const unverifiedRecoveryEmail = loadState('email-recovery', 'unverifiedRecoveryEmail') @@ -6,9 +7,11 @@ document.addEventListener('DOMContentLoaded', function() { const newDiv = createNewDiv('recovery-email-banner') const contentDiv = document.createElement('div') contentDiv.id = 'recovery-email-banner-container' + const img = createImageElement(APPLICATION_NAME) const textNode = createTextNode(APPLICATION_NAME) const link = createLinkElement(APPLICATION_NAME) + contentDiv.appendChild(img) contentDiv.appendChild(textNode) newDiv.appendChild(contentDiv) newDiv.appendChild(link) @@ -132,6 +135,16 @@ function createNewDiv(className) { return div } +/** + * + * @param appName + */ +function createImageElement(appName) { + const img = document.createElement('img') + img.src = generateUrl('/custom_apps/' + appName + '/img/warning.svg') + return img +} + /** * * @param appName -- GitLab From 63be39ea7b09563f85682eca045dae531b6dab9e Mon Sep 17 00:00:00 2001 From: Akhil Date: Fri, 25 Apr 2025 15:23:51 +0530 Subject: [PATCH 3/3] Lint fix for javascript --- src/email-recovery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/email-recovery.js b/src/email-recovery.js index 5e42093..40a4dba 100644 --- a/src/email-recovery.js +++ b/src/email-recovery.js @@ -143,7 +143,7 @@ function createImageElement(appName) { const img = document.createElement('img') img.src = generateUrl('/custom_apps/' + appName + '/img/warning.svg') return img -} +} /** * -- GitLab