mirror of https://github.com/gophish/gophish
Merge pull request #320 from rcutmore/web-group-editing
Validate target input on web front endpull/322/head
commit
ca43a57767
|
@ -94,14 +94,11 @@ function edit(idx) {
|
|||
},
|
||||
done: function(e, data) {
|
||||
$.each(data.result, function(i, record) {
|
||||
targets.DataTable()
|
||||
.row.add([
|
||||
escapeHtml(record.first_name),
|
||||
escapeHtml(record.last_name),
|
||||
escapeHtml(record.email),
|
||||
escapeHtml(record.position),
|
||||
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
||||
]).draw()
|
||||
addTarget(
|
||||
record.first_name,
|
||||
record.last_name,
|
||||
record.email,
|
||||
record.position);
|
||||
});
|
||||
}
|
||||
})
|
||||
|
@ -117,6 +114,35 @@ function deleteGroup(idx) {
|
|||
}
|
||||
}
|
||||
|
||||
function addTarget(firstNameInput, lastNameInput, emailInput, positionInput) {
|
||||
// Create new data row.
|
||||
var email = escapeHtml(emailInput).toLowerCase();
|
||||
var newRow = [
|
||||
escapeHtml(firstNameInput),
|
||||
escapeHtml(lastNameInput),
|
||||
email,
|
||||
escapeHtml(positionInput),
|
||||
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
||||
];
|
||||
|
||||
// Check table to see if email already exists.
|
||||
var targetsTable = targets.DataTable();
|
||||
var existingRowIndex = targetsTable
|
||||
.column(2, {order: "index"}) // Email column has index of 2
|
||||
.data()
|
||||
.indexOf(email);
|
||||
|
||||
// Update or add new row as necessary.
|
||||
if (existingRowIndex >= 0) {
|
||||
targetsTable
|
||||
.row(existingRowIndex, {order: "index"})
|
||||
.data(newRow);
|
||||
} else {
|
||||
targetsTable.row.add(newRow);
|
||||
}
|
||||
targetsTable.draw();
|
||||
}
|
||||
|
||||
function load() {
|
||||
$("#groupTable").hide()
|
||||
$("#emptyMessage").hide()
|
||||
|
@ -168,30 +194,28 @@ function load() {
|
|||
|
||||
$(document).ready(function() {
|
||||
load()
|
||||
// Setup the event listeners
|
||||
// Handle manual additions
|
||||
// Setup the event listeners
|
||||
// Handle manual additions
|
||||
$("#targetForm").submit(function() {
|
||||
targets.DataTable()
|
||||
.row.add([
|
||||
escapeHtml($("#firstName").val()),
|
||||
escapeHtml($("#lastName").val()),
|
||||
escapeHtml($("#email").val()),
|
||||
escapeHtml($("#position").val()),
|
||||
'<span style="cursor:pointer;"><i class="fa fa-trash-o"></i></span>'
|
||||
])
|
||||
.draw()
|
||||
$("#targetForm>div>input").val('')
|
||||
$("#firstName").focus()
|
||||
return false
|
||||
})
|
||||
// Handle Deletion
|
||||
addTarget(
|
||||
$("#firstName").val(),
|
||||
$("#lastName").val(),
|
||||
$("#email").val(),
|
||||
$("#position").val());
|
||||
|
||||
// Reset user input.
|
||||
$("#targetForm>div>input").val('');
|
||||
$("#firstName").focus();
|
||||
return false;
|
||||
});
|
||||
// Handle Deletion
|
||||
$("#targetsTable").on("click", "span>i.fa-trash-o", function() {
|
||||
targets.DataTable()
|
||||
.row($(this).parents('tr'))
|
||||
.remove()
|
||||
.draw();
|
||||
})
|
||||
});
|
||||
$("#modal").on("hide.bs.modal", function() {
|
||||
dismiss()
|
||||
})
|
||||
})
|
||||
dismiss();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue