Commit 3dc6f5d7 authored by Ad Schellevis's avatar Ad Schellevis Committed by Franco Fichtner

(Captive portal) add expire voucher option, closes https://github.com/opnsense/core/issues/899

(cherry picked from commit 0fd14066)
parent 88774996
......@@ -150,4 +150,25 @@ class VoucherController extends ApiControllerBase
}
return $response;
}
/**
* expire a voucher
* @param string $provider auth provider
* @return array status
*/
public function expireVoucherAction($provider)
{
$response = array("status" => "error");
$username = $this->request->getPost('username', 'string', null);
if ($this->request->isPost() && $username != null) {
$authFactory = new AuthenticationFactory();
$auth = $authFactory->get($provider);
if ($auth != null && method_exists($auth, 'expireVoucher')) {
$auth->expireVoucher($username);
$response['status'] = 'ok';
}
}
return $response;
}
}
......@@ -307,6 +307,26 @@ class Voucher implements IAuthConnector
return $response;
}
/**
* expire voucher
* @param string $username username
*/
public function expireVoucher($username)
{
if ($this->dbHandle != null) {
$stmt = $this->dbHandle->prepare('
update vouchers
set validity = 0,
starttime = :starttime
where username = :username
');
$stmt->bindParam(':username', $username);
$starttime = time();
$stmt->bindParam(':starttime', $starttime, SQLITE3_INTEGER);
$stmt->execute();
}
}
/**
* drop expired vouchers in group
* @param $vouchergroup voucher group name
......
......@@ -249,6 +249,42 @@ POSSIBILITY OF SUCH DAMAGE.
}
});
/**
* Expire selected vouchers
*/
$("#expireVouchers").click(function(){
var voucher_provider = $('#voucher-providers').find("option:selected").val();
BootstrapDialog.show({
type:BootstrapDialog.TYPE_DANGER,
title: voucher_provider,
message: '{{ lang._('Expire all selected vouchers?') }}',
buttons: [{
icon: 'fa fa-trash-o',
label: '{{ lang._('Yes') }}',
cssClass: 'btn-primary',
action: function(dlg){
var rows =$("#grid-vouchers").bootgrid('getSelectedRows');
if (rows != undefined) {
var deferreds = [];
$.each(rows, function (key, username) {
deferreds.push(ajaxCall(url="/api/captiveportal/voucher/expireVoucher/" + voucher_provider + "/",
sendData={username:username}, null));
});
$.when.apply(null, deferreds).done(function(){
updateVoucherGroupList();
});
}
dlg.close();
}
}, {
label: 'Close',
action: function(dlg){
dlg.close();
}
}]
});
});
updateVoucherProviders();
$('.selectpicker').selectpicker('refresh');
});
......@@ -289,6 +325,11 @@ POSSIBILITY OF SUCH DAMAGE.
<div class="row">
<div class="col-sm-12">
<div class="pull-right">
<button id="expireVouchers" type="button" class="btn btn-default">
<span>{{ lang._('Expire selected vouchers') }}</span>
<span class="fa fa-trash"></span>
</button>
<button id="dropExpired" type="button" class="btn btn-default">
<span>{{ lang._('Drop expired vouchers') }}</span>
<span class="fa fa-trash"></span>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment