made session manager dynamic
This commit is contained in:
parent
c4d8c62a42
commit
f00d546a0b
2 changed files with 78 additions and 17 deletions
|
@ -27,27 +27,30 @@ class AdvancedController extends Controller
|
|||
$all = isset($_POST['all']);
|
||||
|
||||
if (session_check() && ($id || $all)) {
|
||||
$redirect = route('settings.advanced.sessions');
|
||||
|
||||
// End all sessions
|
||||
if ($all) {
|
||||
CurrentSession::$user->purgeSessions();
|
||||
$message = "Deleted all active session associated with your account!";
|
||||
return view('global/information', compact('message', 'redirect'));
|
||||
return $this->json([
|
||||
'text' => 'Deleted all active session associated with your account!',
|
||||
'go' => route('main.index'),
|
||||
]);
|
||||
}
|
||||
|
||||
// Create the session statement
|
||||
$session = new Session($id);
|
||||
|
||||
// Check if the session exists
|
||||
if ($session->id < 1 || $session->user !== CurrentSession::$user->id) {
|
||||
$message = "This session doesn't exist!";
|
||||
return view('global/information', compact('message', 'redirect'));
|
||||
return $this->json(['error' => "This session doesn't exist!"]);
|
||||
}
|
||||
|
||||
$session->delete();
|
||||
|
||||
return redirect($redirect);
|
||||
$result = ['error' => null];
|
||||
if ($session->id === CurrentSession::$session->id) {
|
||||
$result['go'] = route('main.index');
|
||||
}
|
||||
|
||||
return $this->json($result);
|
||||
}
|
||||
|
||||
$sessions = CurrentSession::$user->sessions();
|
||||
|
|
|
@ -8,6 +8,70 @@
|
|||
<p>If you get logged out after clicking one you've most likely killed your current session, to make it easier to avoid this from happening your current session is highlighted.</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
function yuunoEndSession(csrf, id) {
|
||||
var confirm = new Sakura.Dialogue;
|
||||
|
||||
confirm.SetType(Sakura.DialogueType.ConfirmNegative);
|
||||
confirm.Title = "Session Manager";
|
||||
confirm.Text = !id ? "You are about to end every active login to your account. Are you sure?" : "Are you sure you want to end this session?";
|
||||
|
||||
confirm.AddCallback(Sakura.DialogueButton.No, function () {
|
||||
this.Close();
|
||||
});
|
||||
|
||||
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
|
||||
var ajax = new Sakura.AJAX,
|
||||
formData = new FormData;
|
||||
|
||||
formData.append('session', csrf);
|
||||
|
||||
if (id) {
|
||||
formData.append('id', id);
|
||||
} else {
|
||||
formData.append('all', true);
|
||||
}
|
||||
|
||||
ajax.SetUrl("{{ route('settings.advanced.sessions') }}");
|
||||
ajax.SetFormData(formData);
|
||||
|
||||
ajax.AddCallback(200, function () {
|
||||
var result = ajax.JSON();
|
||||
confirm.Close();
|
||||
|
||||
if (result.error || result.text) {
|
||||
var error = new Sakura.Dialogue;
|
||||
error.Title = "Session Manager";
|
||||
error.Text = result.error || result.text;
|
||||
error.SetType(Sakura.DialogueType.Info);
|
||||
|
||||
error.AddCallback(Sakura.DialogueButton.Ok, function () {
|
||||
this.Close();
|
||||
|
||||
if (result.go) {
|
||||
window.location.assign(result.go);
|
||||
}
|
||||
});
|
||||
|
||||
error.Display();
|
||||
} else if (result.go) {
|
||||
window.location.assign(result.go);
|
||||
}
|
||||
|
||||
if (!result.error && id) {
|
||||
Sakura.DOM.Remove(Sakura.DOM.ID('session-' + id));
|
||||
}
|
||||
});
|
||||
|
||||
ajax.Start(Sakura.HTTPMethod.POST);
|
||||
});
|
||||
|
||||
confirm.Display();
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block settingsContent %}
|
||||
<table class="settings__table">
|
||||
{% for elem in ['thead', 'tfoot'] %}
|
||||
|
@ -23,7 +87,7 @@
|
|||
{% endfor %}
|
||||
<tbody>
|
||||
{% for usession in sessions %}
|
||||
<tr class="settings__table-row {% if usession.id == active %}settings__table-row--current{% endif %}">
|
||||
<tr class="settings__table-row {% if usession.id == active %}settings__table-row--current{% endif %}" id="session-{{ usession.id }}">
|
||||
<td class="settings__table-column">
|
||||
{{ usession.ip }}
|
||||
</td>
|
||||
|
@ -37,17 +101,11 @@
|
|||
<time class="time-ago" datetime="{{ usession.start|date('r') }}">{{ usession.start|date(config('general.date_format')) }}</time>
|
||||
</td>
|
||||
<td class="settings__table-column">
|
||||
<form method="post" action="{{ route('settings.advanced.sessions') }}">
|
||||
<input type="hidden" name="id" value="{{ usession.id }}">
|
||||
<button class="input__button" name="session" value="{{ session_id() }}">Kill</button>
|
||||
</form>
|
||||
<button class="input__button" onclick="yuunoEndSession('{{ session_id() }}', {{ usession.id }})">Kill</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<form method="post" action="{{ route('settings.advanced.sessions') }}">
|
||||
<input type="hidden" name="all" value="1">
|
||||
<button class="input__button" name="session" value="{{ session_id() }}">Kill all active sessions</button>
|
||||
</form>
|
||||
<button class="input__button" onclick="yuunoEndSession('{{ session_id() }}')">Kill all active sessions</button>
|
||||
{% endblock %}
|
||||
|
|
Reference in a new issue