From 39813e961a62b738fd653ebb6773352da686dc85 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 10 Aug 2015 13:57:45 +0200 Subject: [PATCH] Show error message from CPanel API on password change failure (#1490144) --- plugins/password/drivers/cpanel.php | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/plugins/password/drivers/cpanel.php b/plugins/password/drivers/cpanel.php index 663c125ce..9446fdece 100644 --- a/plugins/password/drivers/cpanel.php +++ b/plugins/password/drivers/cpanel.php @@ -49,20 +49,16 @@ class rcube_cpanel_password $this->xmlapi->set_output('json'); $this->xmlapi->set_debug(0); - if ($this->setPassword($_SESSION['username'], $newpass)) { - return PASSWORD_SUCCESS; - } - else { - return PASSWORD_ERROR; - } + return $this->setPassword($_SESSION['username'], $newpass); } /** * Change email account password * - * Returns true on success or false on failure. - * @param string $password email account password - * @return bool + * @param string $address Email address/username + * @param string $password Email account password + * + * @return int|array Operation status */ function setPassword($address, $password) { @@ -75,13 +71,21 @@ class rcube_cpanel_password $data['password'] = $password; - $query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data); - $query = json_decode($query, true); + $query = $this->xmlapi->api2_query($this->cuser, 'Email', 'passwdpop', $data); + $query = json_decode($query, true); + $result = $query['cpanelresult']['data'][0]; + + if ($result['result'] == 1) { + return PASSWORD_SUCCESS; + } - if ($query['cpanelresult']['data'][0]['result'] == 1) { - return true; + if ($result['reason']) { + return array( + 'code' => PASSWORD_ERROR, + 'message' => $result['reason'], + ); } - return false; + return PASSWORD_ERROR; } }