summaryrefslogtreecommitdiffstats
path: root/settings
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2016-06-30 15:06:40 +0200
committerGitHub <noreply@github.com>2016-06-30 15:06:40 +0200
commit29929c97285adca090ee927cb3fd5ef8b52e451b (patch)
tree952aad8612cd6f3945778316d02df7d7d4ae07b0 /settings
parent723cf78169e7dc7138dedf70fa694b202060d8f5 (diff)
parent27059107f869c6a5758569c1e24f34f8543b245e (diff)
downloadnextcloud-server-29929c97285adca090ee927cb3fd5ef8b52e451b.tar.gz
nextcloud-server-29929c97285adca090ee927cb3fd5ef8b52e451b.zip
Merge pull request #240 from nextcloud/password_policy_events_stable9
[stable9] add events to check passwords with the password policy app
Diffstat (limited to 'settings')
-rw-r--r--settings/changepassword/controller.php31
-rw-r--r--settings/js/personal.js30
-rw-r--r--settings/templates/personal.php3
3 files changed, 41 insertions, 23 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())));
}
}
}
diff --git a/settings/js/personal.js b/settings/js/personal.js
index 93820c49ff7..74f61af0bb6 100644
--- a/settings/js/personal.js
+++ b/settings/js/personal.js
@@ -185,6 +185,7 @@ $(document).ready(function () {
$('#pass2').showPassword().keyup();
}
$("#passwordbutton").click(function () {
+ OC.msg.startSaving('#password-error-msg');
var isIE8or9 = $('html').hasClass('lte9');
// FIXME - TODO - once support for IE8 and IE9 is dropped
// for IE8 and IE9 this will check additionally if the typed in password
@@ -201,25 +202,32 @@ $(document).ready(function () {
if (data.status === "success") {
$('#pass1').val('');
$('#pass2').val('').change();
- // Hide a possible errormsg and show successmsg
- $('#password-changed').removeClass('hidden').addClass('inlineblock');
- $('#password-error').removeClass('inlineblock').addClass('hidden');
+ OC.msg.finishedSaving('#password-error-msg', data);
} else {
if (typeof(data.data) !== "undefined") {
- $('#password-error').text(data.data.message);
+ OC.msg.finishedSaving('#password-error-msg', data);
} else {
- $('#password-error').text(t('Unable to change password'));
+ OC.msg.finishedSaving('#password-error-msg',
+ {
+ 'status' : 'error',
+ 'data' : {
+ 'message' : t('core', 'Unable to change password')
+ }
+ }
+ );
}
- // Hide a possible successmsg and show errormsg
- $('#password-changed').removeClass('inlineblock').addClass('hidden');
- $('#password-error').removeClass('hidden').addClass('inlineblock');
}
});
return false;
} else {
- // Hide a possible successmsg and show errormsg
- $('#password-changed').removeClass('inlineblock').addClass('hidden');
- $('#password-error').removeClass('hidden').addClass('inlineblock');
+ OC.msg.finishedSaving('#password-error-msg',
+ {
+ 'status' : 'error',
+ 'data' : {
+ 'message' : t('core', 'Unable to change password')
+ }
+ }
+ );
return false;
}
diff --git a/settings/templates/personal.php b/settings/templates/personal.php
index ee79ac2392b..0e1d59b010a 100644
--- a/settings/templates/personal.php
+++ b/settings/templates/personal.php
@@ -118,8 +118,7 @@ if($_['passwordChangeSupported']) {
?>
<form id="passwordform" class="section">
<h2 class="inlineblock"><?php p($l->t('Password'));?></h2>
- <div class="hidden icon-checkmark" id="password-changed"></div>
- <div class="hidden" id="password-error"><?php p($l->t('Unable to change your password'));?></div>
+ <div id="password-error-msg" class="msg success inlineblock" style="display: none;">Saved</div>
<br>
<label for="pass1" class="onlyInIE8"><?php echo $l->t('Current password');?>: </label>
<input type="password" id="pass1" name="oldpassword"