Commit 58167aee authored by Ujjwal Bhardwaj's avatar Ujjwal Bhardwaj

Send password change notification

parent 6ff91682
......@@ -234,9 +234,41 @@ class LostController extends Controller {
return $this->error($e->getMessage());
}
try {
$this->sendNotificationMail($userId);
} catch (\Exception $e){
return $this->error($e->getMessage());
}
return $this->success();
}
/**
* @param string $userId
* @throws \Exception
*/
protected function sendNotificationMail($userId) {
$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.'
));
}
}
/**
* @param string $user
* @throws \Exception
......
<?php
echo $l->t('Password changed successfully');
......@@ -11,6 +11,7 @@
* @author Robin Appelman <icewind@owncloud.com>
* @author Sam Tuke <mail@samtuke.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Ujjwal Bhardwaj <ujjwalb1996@gmail.com>
* @author Yarno Boelens <yarnoboelens@gmail.com>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
......@@ -53,6 +54,9 @@ class Controller {
}
if (!is_null($password) && \OC_User::setPassword($username, $password)) {
\OC::$server->getUserSession()->updateSessionTokenPassword($password);
self::sendNotificationMail($username);
\OC_JSON::success();
} else {
\OC_JSON::error();
......@@ -151,16 +155,43 @@ class Controller {
} elseif (!$result && !$recoveryEnabledForUser) {
\OC_JSON::error(["data" => ["message" => $l->t("Unable to change password" )]]);
} else {
self::sendNotificationMail($username);
\OC_JSON::success(["data" => ["username" => $username]]);
}
}
} else { // if encryption is disabled, proceed
if (!is_null($password) && \OC_User::setPassword($username, $password)) {
self::sendNotificationMail($username);
\OC_JSON::success(['data' => ['username' => $username]]);
} else {
\OC_JSON::error(['data' => ['message' => $l->t('Unable to change password')]]);
}
}
}
private static function sendNotificationMail($username) {
$userObject = \OC::$server->getUserManager()->get($username);
$email = $userObject->getEMailAddress();
$defaults = new \OC_Defaults();
$from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply');
$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.'
));
}
}
}
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