mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 12:18:43 +09:00
Add verification before permitting password change (#839)
Verify current password before allowing staff or clients to change password (#541). API Endpoints Changed /api/admin/profile/change_password Required fields: current_password - Current admin user password. new_password - New admin user password. confirm_password - New admin user password confirmation. /api/client/profile/change_password Required fields: current_password - Current client user password. new_password - New client user password. confirm_password - New client user password confirmation. Affected Theme Files mod_client_profile.html.twig mod_staff_profile.html.twig
This commit is contained in:
5 files changed
+85
-68
No files matched your search
@@ -19,7 +19,7 @@
|
||||
<div class="tabbable tabs-left">
|
||||
<ul class="nav nav-tabs">
|
||||
<li class="active"><a href="#tab1" data-toggle="tab">{{ 'Details'|trans }}</a></li>
|
||||
<li class=""><a href="#tab2" data-toggle="tab">{{ 'Change Password'|trans }}</a></li>
|
||||
<li class=""><a href="#tab-password" data-toggle="tab">{{ 'Change Password'|trans }}</a></li>
|
||||
<li class=""><a href="#tab3" data-toggle="tab">{{ 'API key'|trans }}</a></li>
|
||||
<li class=""><a href="#tab4" data-toggle="tab">{{ 'Currency'|trans }}</a></li>
|
||||
</ul>
|
||||
@@ -206,33 +206,36 @@
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab2">
|
||||
<div class="tab-pane" id="tab-password">
|
||||
<header>
|
||||
<h1>{{ 'New password'|trans }}</h1>
|
||||
<h1>{{ 'Change Password'|trans }}</h1>
|
||||
<p>{{ 'Please enter new password two times in order avoid mistypes'|trans }}</p>
|
||||
</header>
|
||||
<form method="post" action="" id="change-password" class="form-horizontal">
|
||||
<form method="post" action="{{ 'api/client/profile/change_password'|link }}" class="form-horizontal api-form" data-api-msg="{{ 'Password Changed'|trans }}">
|
||||
<input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
|
||||
<fieldset>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="input">{{ 'Password'|trans }}</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password" value="" required="required">
|
||||
<p class="help-block"></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="input">{{ 'Password confirm'|trans }}</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="password_confirm" value="" required="required">
|
||||
<p class="help-block"></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-alt btn-large btn-primary" type="submit">{{ 'Update password'|trans }}</button>
|
||||
</div> </fieldset>
|
||||
</form> </div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="current_password">{{ 'Current Password'|trans }}</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="current_password" id="current_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="new_password">{{ 'New Password'|trans }}</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="new_password" id="new_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="confirm_password">{{ 'Confirm Password'|trans }}</label>
|
||||
<div class="controls">
|
||||
<input type="password" name="confirm_password" id="confirm_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button class="btn btn-alt btn-large btn-primary" type="submit">{{ 'Change Password'|trans }}</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane" id="tab3">
|
||||
<header>
|
||||
<h1>{{ 'API key'|trans }}</h1>
|
||||
@@ -278,19 +281,7 @@
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(function() {
|
||||
$('#change-password').bind('submit', function(event) {
|
||||
bb.post(
|
||||
'client/profile/change_password',
|
||||
$(this).serialize(),
|
||||
function(result) {
|
||||
bb.msg('Password was changed');
|
||||
}
|
||||
);
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
$(function() {
|
||||
$('#change-api-key').submit(function(event) {
|
||||
bb.post(
|
||||
'client/profile/api_key_reset',
|
||||
|
||||
@@ -97,8 +97,9 @@ class Admin extends \Api_Abstract
|
||||
/**
|
||||
* Change password for currently logged in staff member.
|
||||
*
|
||||
* @param string $password - new password
|
||||
* @param string $password_confirm - repeat new password
|
||||
* @param string $current_password - staff member current password
|
||||
* @param string $new_password - staff member new password
|
||||
* @param string $confirm_password - staff member new password confirmation
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
@@ -106,20 +107,25 @@ class Admin extends \Api_Abstract
|
||||
*/
|
||||
public function change_password($data)
|
||||
{
|
||||
if (!isset($data['password'])) {
|
||||
throw new \Exception('Password required');
|
||||
}
|
||||
$required = [
|
||||
'current_password' => 'Current password required',
|
||||
'new_password' => 'New password required',
|
||||
'confirm_password' => 'New password confirmation required',
|
||||
];
|
||||
$validator = $this->di['validator'];
|
||||
$validator->checkRequiredParamsForArray($required, $data);
|
||||
$validator->isPasswordStrong($data['new_password']);
|
||||
|
||||
if (!isset($data['password_confirm'])) {
|
||||
throw new \Exception('Password confirmation required');
|
||||
}
|
||||
|
||||
if ($data['password'] != $data['password_confirm']) {
|
||||
if ($data['new_password'] != $data['confirm_password']) {
|
||||
throw new \Exception('Passwords do not match');
|
||||
}
|
||||
|
||||
$this->di['validator']->isPasswordStrong($data['password']);
|
||||
$staff = $this->getIdentity();
|
||||
|
||||
return $this->getService()->changeAdminPassword($this->getIdentity(), $data['password']);
|
||||
if(!$this->di['password']->verify($data['current_password'], $staff->pass)) {
|
||||
throw new \Exception('Current password incorrect');
|
||||
}
|
||||
|
||||
return $this->getService()->changeAdminPassword($staff, $data['new_password']);
|
||||
}
|
||||
}
|
||||
@@ -99,22 +99,38 @@ class Client extends \Api_Abstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Change client area password.
|
||||
* Change password for currently logged in client.
|
||||
*
|
||||
* @param string $current_password - client current password
|
||||
* @param string $new_password - client new password
|
||||
* @param string $confirm_password - client new password confirmation
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @throws Exception
|
||||
*
|
||||
*/
|
||||
public function change_password($data)
|
||||
{
|
||||
$required = [
|
||||
'password' => 'Password required',
|
||||
'password_confirm' => 'Password confirmation required',
|
||||
'current_password' => 'Current password required',
|
||||
'new_password' => 'New password required',
|
||||
'confirm_password' => 'New password confirmation required',
|
||||
];
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
$this->di['validator']->isPasswordStrong($data['password']);
|
||||
$this->di['validator']->isPasswordStrong($data['new_password']);
|
||||
|
||||
if ($data['password'] != $data['password_confirm']) {
|
||||
throw new \Box_Exception('Passwords do not match.');
|
||||
if ($data['new_password'] != $data['confirm_password']) {
|
||||
throw new \Exception('Passwords do not match');
|
||||
}
|
||||
|
||||
return $this->getService()->changeClientPassword($this->getIdentity(), $data['password']);
|
||||
$client = $this->getIdentity();
|
||||
|
||||
if(!$this->di['password']->verify($data['current_password'], $client->pass)) {
|
||||
throw new \Exception('Current password incorrect');
|
||||
}
|
||||
|
||||
return $this->getService()->changeClientPassword($client, $data['new_password']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -198,16 +198,14 @@ class Service implements InjectionAwareInterface
|
||||
return $client->api_token;
|
||||
}
|
||||
|
||||
public function changeClientPassword(\Model_Client $client, $password)
|
||||
public function changeClientPassword(\Model_Client $client, $new_password)
|
||||
{
|
||||
$event_params = [];
|
||||
$event_params['password'] = $password;
|
||||
$event_params['password'] = $new_password;
|
||||
$event_params['id'] = $client->id;
|
||||
$this->di['events_manager']->fire(['event' => 'onBeforeClientProfilePasswordChange', 'params' => $event_params]);
|
||||
|
||||
$this->di['validator']->isPasswordStrong($password);
|
||||
|
||||
$client->pass = $this->di['password']->hashIt($password);
|
||||
$client->pass = $this->di['password']->hashIt($new_password);
|
||||
$this->di['db']->store($client);
|
||||
|
||||
$this->di['events_manager']->fire(['event' => 'onAfterClientProfilePasswordChange', 'params' => ['id' => $client->id]]);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<a class="nav-link active" href="#tab-profile" data-bs-toggle="tab">{{ 'Profile'|trans }}</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" href="#tab-password" data-bs-toggle="tab">{{ 'Change password'|trans }}</a>
|
||||
<a class="nav-link" href="#tab-password" data-bs-toggle="tab">{{ 'Change Password'|trans }}</a>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<a class="nav-link" href="#tab-api" data-bs-toggle="tab">{{ 'API'|trans }}</a>
|
||||
@@ -57,22 +57,28 @@
|
||||
|
||||
<div class="tab-pane fade" id="tab-password" role="tabpanel">
|
||||
<div class="card-body">
|
||||
<form method="post" action="{{ 'api/admin/profile/change_password'|link }}" class="api-form" data-api-msg="{{ 'Password changed'|trans }}">
|
||||
<form method="post" action="{{ 'api/admin/profile/change_password'|link }}" class="api-form" data-api-msg="{{ 'Password Changed'|trans }}">
|
||||
<input type="hidden" name="CSRFToken" value="{{ CSRFToken }}"/>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Password'|trans }}</label>
|
||||
<label for="current_password" class="col-3 col-form-label">{{ 'Current Password'|trans }}</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="password" name="password" required>
|
||||
<input class="form-control" type="password" name="current_password" id="current_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label class="form-label col-3 col-form-label">{{ 'Password confirm'|trans }}</label>
|
||||
<label for="new_password" class="col-3 col-form-label">{{ 'New Password'|trans }}</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="password" name="password_confirm" required>
|
||||
<input class="form-control" type="password" name="new_password" id="new_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3 row">
|
||||
<label for="confirm_password" class="col-3 col-form-label">{{ 'Confirm Password'|trans }}</label>
|
||||
<div class="col">
|
||||
<input class="form-control" type="password" name="confirm_password" id="confirm_password" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="{{ 'Change password'|trans }}" class="btn btn-primary w-100">
|
||||
<input type="submit" value="{{ 'Change Password'|trans }}" class="btn btn-primary w-100">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user