Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2019-07-26 16:21:41 +0300
committerRoeland Jago Douma <roeland@famdouma.nl>2019-07-27 21:12:16 +0300
commitb6dd2ebd3909017b9a5dbe0e145d6c5041a9043c (patch)
tree63a2bdf57168cca766dfadb2d5d1608e2b6ffdf7 /core/Controller
parent1ec98af3e028f5aa8591bda26d5dac96dfd66f43 (diff)
Use proper exception in lostController
There is no need to log the expcetion of most of the stuff here. We should properly log them but an exception is excessive. This moves it to a proper exception which we can catch and then log. The other exceptions will still be fully logged. Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'core/Controller')
-rw-r--r--core/Controller/LostController.php31
1 files changed, 13 insertions, 18 deletions
diff --git a/core/Controller/LostController.php b/core/Controller/LostController.php
index 5ac0557e5d6..7947440785b 100644
--- a/core/Controller/LostController.php
+++ b/core/Controller/LostController.php
@@ -32,6 +32,7 @@
namespace OC\Core\Controller;
use OC\Authentication\TwoFactorAuth\Manager;
+use OC\Core\Exception\ResetPasswordException;
use OC\HintException;
use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse;
@@ -248,11 +249,11 @@ class LostController extends Controller {
// FIXME: use HTTP error codes
try {
$this->sendEmail($user);
- } catch (\Exception $e) {
+ } catch (ResetPasswordException $e) {
// Ignore the error since we do not want to leak this info
- $this->logger->logException($e, [
- 'level' => ILogger::WARN
- ]);
+ $this->logger->warning('Could not send password reset email: ' . $e->getMessage());
+ } catch (\Exception $e) {
+ $this->logger->logException($e);
}
$response = new JSONResponse($this->success());
@@ -312,16 +313,15 @@ class LostController extends Controller {
/**
* @param string $input
- * @throws \Exception
+ * @throws ResetPasswordException
+ * @throws \OCP\PreConditionNotMetException
*/
protected function sendEmail($input) {
$user = $this->findUserByIdOrMail($input);
$email = $user->getEMailAddress();
if (empty($email)) {
- throw new \Exception(
- $this->l10n->t('Could not send reset email because there is no email address for this username. Please contact your administrator.')
- );
+ throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input);
}
// Generate the token. It is stored encrypted in the database with the
@@ -367,26 +367,21 @@ class LostController extends Controller {
$message->useTemplate($emailTemplate);
$this->mailer->send($message);
} catch (\Exception $e) {
- throw new \Exception($this->l10n->t(
- 'Couldn\'t send reset email. Please contact your administrator.'
- ));
+ // Log the exception and continue
+ $this->logger->logException($e);
}
}
/**
* @param string $input
* @return IUser
- * @throws \InvalidArgumentException
+ * @throws ResetPasswordException
*/
protected function findUserByIdOrMail($input) {
- $userNotFound = new \InvalidArgumentException(
- $this->l10n->t('Couldn\'t send reset email. Please make sure your username is correct.')
- );
-
$user = $this->userManager->get($input);
if ($user instanceof IUser) {
if (!$user->isEnabled()) {
- throw $userNotFound;
+ throw new ResetPasswordException('User is disabled');
}
return $user;
@@ -400,6 +395,6 @@ class LostController extends Controller {
return reset($users);
}
- throw $userNotFound;
+ throw new ResetPasswordException('Could not find user');
}
}