Skip to content

Commit

Permalink
Merge pull request #47 from jmpsec/users-editable
Browse files Browse the repository at this point in the history
Users are editable
  • Loading branch information
javuto authored Mar 8, 2020
2 parents 09346b7 + 1507b80 commit 2373780
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
23 changes: 23 additions & 0 deletions admin/handlers-post.go
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,29 @@ func usersPOSTHandler(w http.ResponseWriter, r *http.Request) {
responseMessage = "User added successfully"
}
}
case "edit":
if u.Fullname != "" {
if err := adminUsers.ChangeFullname(u.Username, u.Fullname); err != nil {
responseMessage = "error changing fullname"
responseCode = http.StatusInternalServerError
if settingsmgr.DebugService(settings.ServiceAdmin) {
log.Printf("DebugService: %s %v", responseMessage, err)
}
} else {
responseMessage = "User updated successfully"
}
}
if u.Email != "" {
if err := adminUsers.ChangeEmail(u.Username, u.Email); err != nil {
responseMessage = "error changing email"
responseCode = http.StatusInternalServerError
if settingsmgr.DebugService(settings.ServiceAdmin) {
log.Printf("DebugService: %s %v", responseMessage, err)
}
} else {
responseMessage = "User updated successfully"
}
}
case "remove":
if u.Username == ctx[ctxUser] {
responseMessage = "Not a good idea"
Expand Down
4 changes: 1 addition & 3 deletions admin/templates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ <h4 class="modal-title">Add new setting</h4>
}, {
indicator : "<img src='/static/img/spinner.svg' />",
type : "text",
// only limit to three letters example
//pattern: "[A-Za-z]{3}",
onedit : function() { console.log('If I return false edition will be canceled'); return true;},
onedit : function() { return true;},
cancel : 'Cancel',
cssclass : 'editable-class',
cancelcssclass : 'btn btn-danger',
Expand Down
6 changes: 3 additions & 3 deletions admin/templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
text: '<i class="far fa-trash-alt"></i>',
titleAttr: 'Remove Nodes',
attr: {
'data-toggle': 'tooltip',
'data-tooltip': 'true',
'data-placement': 'bottom'
},
init: function(api, node, config) {
Expand All @@ -225,7 +225,7 @@
text: '<i class="fab fa-searchengin"></i>',
titleAttr: 'Run Query',
attr: {
'data-toggle': 'tooltip',
'data-tooltip': 'true',
'data-placement': 'bottom'
},
init: function(api, node, config) {
Expand All @@ -250,7 +250,7 @@
text: '<i class="fas fa-file-upload"></i>',
titleAttr: 'Carve File',
attr: {
'data-toggle': 'tooltip',
'data-tooltip': 'true',
'data-placement': 'bottom'
},
init: function(api, node, config) {
Expand Down
53 changes: 45 additions & 8 deletions admin/templates/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@
<th width="30%">Last UserAgent</th>
<th width="5%">Admin</th>
<th width="10%">Last Session</th>
<th width="5%"></th>
<th width="5%"></th>
<th width="10%"></th>
</tr>
</thead>
<tbody>
{{range $i, $e := $.CurrentUsers}}
<tr>
<td>{{ $e.Username }}</td>
<td>{{ $e.Email }}</td>
<td>{{ $e.Fullname }}</td>
<td>
<p id="email" data-tooltip="true" data-user="{{ $e.Username }}" class="editable-field" role="button" tabindex="0" title="Click to edit...">{{ $e.Email }}</p>
</td>
<td>
<p id="fullname" data-tooltip="true" data-user="{{ $e.Username }}" class="editable-field" role="button" tabindex="0" title="Click to edit...">{{ $e.Fullname }}</p>
</td>
<td>{{ $e.LastIPAddress }}</td>
<td>{{ $e.LastUserAgent }}</td>
<td>
Expand All @@ -70,13 +73,13 @@
<td>{{ pastTimeAgo $e.LastAccess }}</td>
<td>
{{ if $e.Admin }}
<button type="button" class="btn btn-sm btn-ghost-info" onclick="showAPIToken({{ $e.APIToken }}, {{ $e.TokenExpire }}, {{ $e.Username }});">
<button type="button" class="btn btn-sm btn-ghost-info" data-tooltip="true" data-placement="top" title="Show API Token"
onclick="showAPIToken({{ $e.APIToken }}, {{ $e.TokenExpire }}, {{ $e.Username }});">
<i class="fas fa-key"></i>
</button>
{{ end }}
</td>
<td>
<button type="button" class="btn btn-sm btn-ghost-danger" onclick="confirmDeleteUser({{ $e.Username }});">
<button type="button" class="btn btn-sm btn-ghost-danger" data-tooltip="true" data-placement="top" title="Delete User"
onclick="confirmDeleteUser({{ $e.Username }});">
<i class="far fa-trash-alt"></i>
</button>
</td>
Expand Down Expand Up @@ -184,6 +187,40 @@ <h4 class="modal-title">API Token</h4>
<script src="/static/js/login.js"></script>
<script type="text/javascript">
$(document).ready(function() {
// Editable fields
$(".editable-field").editable(function(value, settings) {
var data = {
csrftoken: $("#csrftoken").val(),
action: 'edit',
username: $(this).attr('data-user'),
};
var type_edit = $(this).attr('id');
if (type_edit === 'email') {
data.email = value;
}
if (type_edit === 'fullname') {
data.fullname = value;
}
console.log(settings);
sendPostRequest(data, window.location.pathname, '', false);
return value;
}, {
indicator : "<img src='/static/img/spinner.svg' />",
type : "text",
onedit : function() { return true;},
cancel : 'Cancel',
cssclass : 'editable-class',
cancelcssclass : 'btn btn-danger',
submitcssclass : 'btn btn-success',
maxlength : 200,
// select all text
select : true,
label : '',
showfn : function(elem) { elem.fadeIn('slow') },
submit : 'Save',
tooltip : "Click to edit...",
width : 160
});
// Enable all tooltips
$('[data-tooltip="true"]').tooltip({trigger : 'hover'});

Expand Down

0 comments on commit 2373780

Please sign in to comment.