diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index e77c83e66e8b343fc36a3cbde87437cac4a45cd0..87ffffd04d5eac67860388ce252095282fb6a108 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 a19f96b3a07712a4519a02a73396c13db09e9c7c..9fa3af62433544966f7662801c2834b075e66bf3 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 5a65944a01d9b8b686640886d0740c46b92d968f..ff2f37c3b4f035b1deb4c98e514631fd5ba04c98 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 de76285d8489b86e4323fa2cac6a6d9274fb310e..10ddf084f32cadb5ca1f0b6b6754d123df027c6b 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 e4532ff28eafad6f7210287777a6441704d44ab9..a7795166c7a6a4297823a7c0db8c07aa9e5d2d6b 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; diff --git a/scss/email-recovery.scss b/scss/email-recovery.scss index facc5c2a9cfb2bce13362bbbd7dc37be2ddaa9b3..aa010b6bdfb16990e034b0c495dc6b325ceeca8a 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 93299f53173f896ec57ad60f56399ad23dfd2a38..40a4dbaec1f3740b7aff8596bc1cf8c42d4f45b9 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