|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Björn Schießle <[email protected]> |
|
4
|
|
|
* @author Christopher Schäpers <[email protected]> |
|
5
|
|
|
* @author Christoph Wurst <[email protected]> |
|
6
|
|
|
* @author Clark Tomlinson <[email protected]> |
|
7
|
|
|
* @author cmeh <[email protected]> |
|
8
|
|
|
* @author Florin Peter <[email protected]> |
|
9
|
|
|
* @author Jakob Sack <[email protected]> |
|
10
|
|
|
* @author Lukas Reschke <[email protected]> |
|
11
|
|
|
* @author Robin Appelman <[email protected]> |
|
12
|
|
|
* @author Sam Tuke <[email protected]> |
|
13
|
|
|
* @author Thomas Müller <[email protected]> |
|
14
|
|
|
* @author Ujjwal Bhardwaj <[email protected]> |
|
15
|
|
|
* @author Yarno Boelens <[email protected]> |
|
16
|
|
|
* |
|
17
|
|
|
* @copyright Copyright (c) 2018, ownCloud GmbH |
|
18
|
|
|
* @license AGPL-3.0 |
|
19
|
|
|
* |
|
20
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
21
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
22
|
|
|
* as published by the Free Software Foundation. |
|
23
|
|
|
* |
|
24
|
|
|
* This program is distributed in the hope that it will be useful, |
|
25
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
27
|
|
|
* GNU Affero General Public License for more details. |
|
28
|
|
|
* |
|
29
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
30
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
31
|
|
|
* |
|
32
|
|
|
*/ |
|
33
|
|
|
namespace OC\Settings\ChangePassword; |
|
34
|
|
|
|
|
35
|
|
|
class Controller { |
|
36
|
|
|
public static function changePersonalPassword($args) { |
|
|
|
|
|
|
37
|
|
|
// Check if we are an user |
|
38
|
|
|
\OC_JSON::callCheck(); |
|
39
|
|
|
\OC_JSON::checkLoggedIn(); |
|
40
|
|
|
|
|
41
|
|
|
$username = \OC_User::getUser(); |
|
42
|
|
|
$password = isset($_POST['personal-password']) ? $_POST['personal-password'] : null; |
|
43
|
|
|
$oldPassword = isset($_POST['oldpassword']) ? $_POST['oldpassword'] : ''; |
|
44
|
|
|
|
|
45
|
|
View Code Duplication |
if (!\OC_User::checkPassword($username, $oldPassword)) { |
|
|
|
|
|
|
46
|
|
|
$l = \OC::$server->getL10NFactory()->get('settings'); |
|
47
|
|
|
\OC_JSON::error(["data" => ["message" => $l->t("Wrong password")]]); |
|
48
|
|
|
exit(); |
|
49
|
|
|
} |
|
50
|
|
View Code Duplication |
if ($oldPassword === $password) { |
|
|
|
|
|
|
51
|
|
|
$l = \OC::$server->getL10NFactory()->get('settings'); |
|
52
|
|
|
\OC_JSON::error(["data" => ["message" => $l->t("The new password can not be the same as the previous one")]]); |
|
53
|
|
|
exit(); |
|
54
|
|
|
} |
|
55
|
|
|
try { |
|
56
|
|
|
if (!is_null($password) && \OC_User::setPassword($username, $password)) { |
|
57
|
|
|
\OC::$server->getUserSession()->updateSessionTokenPassword($password); |
|
58
|
|
|
|
|
59
|
|
|
self::sendNotificationMail($username); |
|
60
|
|
|
|
|
61
|
|
|
\OC_JSON::success(); |
|
62
|
|
|
} else { |
|
63
|
|
|
\OC_JSON::error(); |
|
64
|
|
|
} |
|
65
|
|
|
} catch (\Exception $e) { |
|
66
|
|
|
\OC_JSON::error(['data' => ['message' => $e->getMessage()]]); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
private static function sendNotificationMail($username) { |
|
71
|
|
|
$userObject = \OC::$server->getUserManager()->get($username); |
|
72
|
|
|
$email = $userObject->getEMailAddress(); |
|
73
|
|
|
$defaults = new \OC_Defaults(); |
|
74
|
|
|
$from = \OCP\Util::getDefaultEmailAddress('lostpassword-noreply'); |
|
75
|
|
|
$mailer = \OC::$server->getMailer(); |
|
76
|
|
|
$lion = \OC::$server->getL10N('lib'); |
|
77
|
|
|
|
|
78
|
|
|
if ($email !== null && $email !== '') { |
|
79
|
|
|
$tmpl = new \OC_Template('core', 'lostpassword/notify'); |
|
80
|
|
|
$msg = $tmpl->fetchPage(); |
|
81
|
|
|
|
|
82
|
|
|
try { |
|
83
|
|
|
$message = $mailer->createMessage(); |
|
84
|
|
|
$message->setTo([$email => $username]); |
|
85
|
|
|
$message->setSubject($lion->t('%s password changed successfully', [$defaults->getName()])); |
|
86
|
|
|
$message->setPlainBody($msg); |
|
|
|
|
|
|
87
|
|
|
$message->setFrom([$from => $defaults->getName()]); |
|
88
|
|
|
$mailer->send($message); |
|
89
|
|
|
} catch (\Exception $e) { |
|
90
|
|
|
throw new \Exception($lion->t( |
|
91
|
|
|
'Couldn\'t send reset email. Please contact your administrator.' |
|
92
|
|
|
)); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.