diff --git a/README.md b/README.md index cb3f8f939c0105292155e12ceed9022e584347dd..b6fe6bf9d092d137ab74f6a44b5872ef40d762b7 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,12 @@ ![Recovery Email Setting Image](recovery-email-setting.png) - For API endpoint authentication to work, you will have to set the environment variable `NEXTCLOUD_EMAIL_RECOVERY_APP_SECRET` on your server to some string(Recommended to set a strong password here) + +## Localization + +1. Download [translationtool](https://github.com/nextcloud/docker-ci/blob/master/translations/translationtool/translationtool.phar) from github. +2. Place it in your `$PATH` with executable permissions +3. Run it from the root of the project: `translationtool.phar create-pot-files email-recovery` +4. For html files, make sure that traslation strings are not directly assigned to an attribute. Use a tmp variable to call `t()` and then assign this variable to the attribute. +4. Commit the updated `translationfiles/templates/email-recovery.pot` +5. Translate in [Weblate](https://i18n.e.foundation/projects/ecloud/email-recovery/) diff --git a/lib/Controller/EmailRecoveryController.php b/lib/Controller/EmailRecoveryController.php index 4aafec3d579faf1a3df817582f2a367c4752549c..7b7f6db081e8dc144b027420e879c2c1ade2e34d 100644 --- a/lib/Controller/EmailRecoveryController.php +++ b/lib/Controller/EmailRecoveryController.php @@ -28,6 +28,7 @@ use OCP\AppFramework\Controller; use OCP\IRequest; use OCP\IConfig; use OCP\ILogger; +use \OCP\IL10N; use OCP\IUserSession; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Http\JSONResponse; @@ -37,70 +38,79 @@ use OCA\EmailRecovery\Exception\SameRecoveryEmailAsEmailException; class EmailRecoveryController extends Controller { - /** @var IConfig */ - private $config; + /** @var IConfig */ + private $config; - /** @var ILogger */ - private $logger; + /** @var ILogger */ + private $logger; - private $userSession; + /** @var IL10N */ + private $l; - private $recoveryEmailService; + private $userSession; - public function __construct( - string $appName, - IRequest $request, - IConfig $config, - ILogger $logger, - IUserSession $userSession, - RecoveryEmailService $recoveryEmailService - ) { - parent::__construct($appName, $request); - $this->config = $config; - $this->logger = $logger; - $this->userSession = $userSession; - $this->recoveryEmailService = $recoveryEmailService; - } + private $recoveryEmailService; - /** - * @NoAdminRequired - */ + public function __construct( + string $appName, + IRequest $request, + IConfig $config, + ILogger $logger, + IL10N $l, + IUserSession $userSession, + RecoveryEmailService $recoveryEmailService + ) + { + parent::__construct($appName, $request); + $this->config = $config; + $this->logger = $logger; + $this->l = $l; + $this->userSession = $userSession; + $this->recoveryEmailService = $recoveryEmailService; + } - public function getRecoveryEmail() - { - $response = new JSONResponse(); - $userId = $this->userSession->getUser()->getUID(); - $data = array("recoveryEmail" => $this->config->getUserValue($userId, $this->appName, 'recovery-email')); - $response->setData($data); - return $response; - } - /** - * @NoAdminRequired - */ + /** + * @NoAdminRequired + */ - public function setRecoveryEmail(string $recoveryEmail) - { - $userId = $this->userSession->getUser()->getUID(); - $response = new Response(); - try { - if ($this->recoveryEmailService->validateRecoveryEmail($userId, $recoveryEmail)) { - $this->recoveryEmailService->updateRecoveryEmail($userId, $recoveryEmail); - $response->setStatus(200); - return $response; - } - } catch (Exception $e) { - $response->setStatus(500); - if ($e instanceof InvalidRecoveryEmailException) { - $response->setStatus(400); - $response->setData(['message' => 'Invalid Recovery Email']); - } - if ($e instanceof SameRecoveryEmailAsEmailException) { - $response->setStatus(400); - $response->setData(['message' => 'Error! User email address cannot be saved as recovery email address!']); - } + public function getRecoveryEmail() + { + $response = new JSONResponse(); + $userId = $this->userSession->getUser()->getUID(); + $data = array("recoveryEmail" => $this->config->getUserValue($userId, $this->appName, 'recovery-email')); + $response->setData($data); + return $response; + } - $this->logger->error("Error setting recovery email for user $userId" . $e->getMessage()); - return $response; - } - } + /** + * @NoAdminRequired + */ + + public function setRecoveryEmail(string $recoveryEmail) + { + $userId = $this->userSession->getUser()->getUID(); + $response = new Response(); + try { + if ($this->recoveryEmailService->validateRecoveryEmail($userId, $recoveryEmail)) { + $this->recoveryEmailService->updateRecoveryEmail($userId, $recoveryEmail); + $response->setStatus(200); + return $response; + } + } catch (Exception $e) { + $response->setStatus(500); + if ($e instanceof InvalidRecoveryEmailException) { + $response->setStatus(400); + $this->l->t('Invalid Recovery Email'); + $response->setData(['message' => 'Invalid Recovery Email']); + } + if ($e instanceof SameRecoveryEmailAsEmailException) { + $response->setStatus(400); + $this->l->t('Error! User email address cannot be saved as recovery email address!'); + $response->setData(['message' => 'Error! User email address cannot be saved as recovery email address!']); + } + + $this->logger->error("Error setting recovery email for user $userId" . $e->getMessage()); + return $response; + } + } } diff --git a/src/main.html b/src/main.html index bc796e5822adaa690ff4f7b1f35efd5e9100412a..7d013cf943d3a5a712d21c7a950ee0f671c8378c 100644 --- a/src/main.html +++ b/src/main.html @@ -6,17 +6,18 @@ + {% const placeholder = t('email-recovery', 'Recovery Email') %} - + {% const value = t('email-recovery', 'Change Recovery Email') %}
{{ t("email-recovery","Changes saved") }}
diff --git a/translationfiles/templates/email-recovery.pot b/translationfiles/templates/email-recovery.pot
index 760164b25520652a0dad7cb889da86ed50e48343..3761d0ce49d8ba49d367d79b394c8fa396e88973 100644
--- a/translationfiles/templates/email-recovery.pot
+++ b/translationfiles/templates/email-recovery.pot
@@ -1,14 +1,14 @@
-# BASE TRANSLATION FILE.
-# Copyright (C) 2022 MURENA
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the Nextcloud package.
-# dev@murena.io
+# FIRST AUTHOR