Commit c006d0d7 authored by Ujjwal Bhardwaj's avatar Ujjwal Bhardwaj

Handle empty email and update tests

parent 58167aee
......@@ -252,20 +252,22 @@ class LostController extends Controller {
$user = $this->userManager->get($userId);
$email = $user->getEMailAddress();
$tmpl = new \OC_Template('core', 'lostpassword/notify');
$msg = $tmpl->fetchPage();
try {
$message = $this->mailer->createMessage();
$message->setTo([$email => $userId]);
$message->setSubject($this->l10n->t('%s password changed successfully', [$this->defaults->getName()]));
$message->setPlainBody($msg);
$message->setFrom([$this->from => $this->defaults->getName()]);
$this->mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($this->l10n->t(
'Couldn\'t send reset email. Please contact your administrator.'
));
if ($email !== '') {
$tmpl = new \OC_Template('core', 'lostpassword/notify');
$msg = $tmpl->fetchPage();
try {
$message = $this->mailer->createMessage();
$message->setTo([$email => $userId]);
$message->setSubject($this->l10n->t('%s password changed successfully', [$this->defaults->getName()]));
$message->setPlainBody($msg);
$message->setFrom([$this->from => $this->defaults->getName()]);
$this->mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($this->l10n->t(
$e->getMessage()
));
}
}
}
......
......@@ -178,20 +178,22 @@ class Controller {
$mailer = \OC::$server->getMailer();
$lion = \OC::$server->getL10N('lib');
$tmpl = new \OC_Template('core', 'lostpassword/notify');
$msg = $tmpl->fetchPage();
try {
$message = $mailer->createMessage();
$message->setTo([$email => $username]);
$message->setSubject($lion->t('%s password changed successfully', [$defaults->getName()]));
$message->setPlainBody($msg);
$message->setFrom([$from => $defaults->getName()]);
$mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($lion->t(
'Couldn\'t send reset email. Please contact your administrator.'
));
if ($email !== '') {
$tmpl = new \OC_Template('core', 'lostpassword/notify');
$msg = $tmpl->fetchPage();
try {
$message = $mailer->createMessage();
$message->setTo([$email => $username]);
$message->setSubject($lion->t('%s password changed successfully', [$defaults->getName()]));
$message->setPlainBody($msg);
$message->setFrom([$from => $defaults->getName()]);
$mailer->send($message);
} catch (\Exception $e) {
throw new \Exception($lion->t(
'Couldn\'t send reset email. Please contact your administrator.'
));
}
}
}
}
......@@ -479,7 +479,7 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
->with('NewPassword')
->will($this->returnValue(true));
$this->userManager
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('get')
->with('ValidTokenUser')
->will($this->returnValue($user));
......@@ -487,6 +487,38 @@ class LostControllerTest extends \PHPUnit_Framework_TestCase {
->expects($this->once())
->method('getTime')
->will($this->returnValue(12348));
$user
->expects($this->once())
->method('getEMailAddress')
->will($this->returnValue('test@example.com'));
$message = $this->getMockBuilder('\OC\Mail\Message')
->disableOriginalConstructor()->getMock();
$message
->expects($this->at(0))
->method('setTo')
->with(['test@example.com' => 'ValidTokenUser']);
$message
->expects($this->at(1))
->method('setSubject')
->with(' password changed successfully');
$message
->expects($this->at(2))
->method('setPlainBody')
->with('Password changed successfully');
$message
->expects($this->at(3))
->method('setFrom')
->with(['lostpassword-noreply@localhost' => null]);
$this->mailer
->expects($this->at(0))
->method('createMessage')
->will($this->returnValue($message));
$this->mailer
->expects($this->at(1))
->method('send')
->with($message);
$response = $this->lostController->setPassword('TheOnlyAndOnlyOneTokenToResetThePassword', 'ValidTokenUser', 'NewPassword', true);
$expectedResponse = ['status' => 'success'];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment