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']);
|
$all = isset($_POST['all']);
|
||||||
|
|
||||||
if (session_check() && ($id || $all)) {
|
if (session_check() && ($id || $all)) {
|
||||||
$redirect = route('settings.advanced.sessions');
|
|
||||||
|
|
||||||
// End all sessions
|
// End all sessions
|
||||||
if ($all) {
|
if ($all) {
|
||||||
CurrentSession::$user->purgeSessions();
|
CurrentSession::$user->purgeSessions();
|
||||||
$message = "Deleted all active session associated with your account!";
|
return $this->json([
|
||||||
return view('global/information', compact('message', 'redirect'));
|
'text' => 'Deleted all active session associated with your account!',
|
||||||
|
'go' => route('main.index'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the session statement
|
|
||||||
$session = new Session($id);
|
$session = new Session($id);
|
||||||
|
|
||||||
// Check if the session exists
|
// Check if the session exists
|
||||||
if ($session->id < 1 || $session->user !== CurrentSession::$user->id) {
|
if ($session->id < 1 || $session->user !== CurrentSession::$user->id) {
|
||||||
$message = "This session doesn't exist!";
|
return $this->json(['error' => "This session doesn't exist!"]);
|
||||||
return view('global/information', compact('message', 'redirect'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$session->delete();
|
$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();
|
$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>
|
<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 %}
|
{% 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 %}
|
{% block settingsContent %}
|
||||||
<table class="settings__table">
|
<table class="settings__table">
|
||||||
{% for elem in ['thead', 'tfoot'] %}
|
{% for elem in ['thead', 'tfoot'] %}
|
||||||
|
@ -23,7 +87,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for usession in sessions %}
|
{% 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">
|
<td class="settings__table-column">
|
||||||
{{ usession.ip }}
|
{{ usession.ip }}
|
||||||
</td>
|
</td>
|
||||||
|
@ -37,17 +101,11 @@
|
||||||
<time class="time-ago" datetime="{{ usession.start|date('r') }}">{{ usession.start|date(config('general.date_format')) }}</time>
|
<time class="time-ago" datetime="{{ usession.start|date('r') }}">{{ usession.start|date(config('general.date_format')) }}</time>
|
||||||
</td>
|
</td>
|
||||||
<td class="settings__table-column">
|
<td class="settings__table-column">
|
||||||
<form method="post" action="{{ route('settings.advanced.sessions') }}">
|
<button class="input__button" onclick="yuunoEndSession('{{ session_id() }}', {{ usession.id }})">Kill</button>
|
||||||
<input type="hidden" name="id" value="{{ usession.id }}">
|
|
||||||
<button class="input__button" name="session" value="{{ session_id() }}">Kill</button>
|
|
||||||
</form>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<form method="post" action="{{ route('settings.advanced.sessions') }}">
|
<button class="input__button" onclick="yuunoEndSession('{{ session_id() }}')">Kill all active sessions</button>
|
||||||
<input type="hidden" name="all" value="1">
|
|
||||||
<button class="input__button" name="session" value="{{ session_id() }}">Kill all active sessions</button>
|
|
||||||
</form>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Reference in a new issue