diff options
Diffstat (limited to 'settings/changepassword/controller.php')
-rw-r--r-- | settings/changepassword/controller.php | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/settings/changepassword/controller.php b/settings/changepassword/controller.php index 8469ec1423a..7484d3a170a 100644 --- a/settings/changepassword/controller.php +++ b/settings/changepassword/controller.php @@ -30,6 +30,8 @@ */ namespace OC\Settings\ChangePassword; +use OC\HintException; + class Controller { public static function changePersonalPassword($args) { // Check if we are an user @@ -39,16 +41,21 @@ class Controller { $username = \OC_User::getUser(); $password = isset($_POST['personal-password']) ? $_POST['personal-password'] : null; $oldPassword = isset($_POST['oldpassword']) ? $_POST['oldpassword'] : ''; + $l = new \OC_L10n('settings'); if (!\OC_User::checkPassword($username, $oldPassword)) { - $l = new \OC_L10n('settings'); \OC_JSON::error(array("data" => array("message" => $l->t("Wrong password")) )); exit(); } - if (!is_null($password) && \OC_User::setPassword($username, $password)) { - \OC_JSON::success(); - } else { - \OC_JSON::error(); + + try { + if (!is_null($password) && \OC_User::setPassword($username, $password)) { + \OC_JSON::success(['data' => ['message' => $l->t('Saved')]]); + } else { + \OC_JSON::error(); + } + } catch (HintException $e) { + \OC_JSON::error(['data' => ['message' => $e->getHint()]]); } } @@ -144,15 +151,19 @@ class Controller { } elseif (!$result && !$recoveryEnabledForUser) { \OC_JSON::error(array("data" => array( "message" => $l->t("Unable to change password" ) ))); } else { - \OC_JSON::success(array("data" => array( "username" => $username ))); + \OC_JSON::success(array("data" => array("username" => $username, 'message' => $l->t('Saved')))); } } } else { // if encryption is disabled, proceed - if (!is_null($password) && \OC_User::setPassword($username, $password)) { - \OC_JSON::success(array('data' => array('username' => $username))); - } else { - \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); + try { + if (!is_null($password) && \OC_User::setPassword($username, $password)) { + \OC_JSON::success(array('data' => array('username' => $username, 'message' => $l->t('Saved')))); + } else { + \OC_JSON::error(array('data' => array('message' => $l->t('Unable to change password')))); + } + } catch (HintException $e) { + \OC_JSON::error(array('data' => array('message' => $e->getHint()))); } } } |