aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Catalyst
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-02-05 22:24:22 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-02-06 16:55:16 +0000
commitdb8898037b67265b18ffac9ef8b6696dc6d33d22 (patch)
treeb29d1aa0158319ae22b505054c6ccdc83eb9cfcf /perllib/Catalyst
parent35445b8cc7ae02acdfbfc3e2e9da15b022736906 (diff)
Add admin ability to log user out.
Diffstat (limited to 'perllib/Catalyst')
-rw-r--r--perllib/Catalyst/Plugin/FixMyStreet/Session/StoreSessions.pm23
1 files changed, 23 insertions, 0 deletions
diff --git a/perllib/Catalyst/Plugin/FixMyStreet/Session/StoreSessions.pm b/perllib/Catalyst/Plugin/FixMyStreet/Session/StoreSessions.pm
new file mode 100644
index 000000000..5e7a3cede
--- /dev/null
+++ b/perllib/Catalyst/Plugin/FixMyStreet/Session/StoreSessions.pm
@@ -0,0 +1,23 @@
+package Catalyst::Plugin::FixMyStreet::Session::StoreSessions;
+use Moose::Role;
+use namespace::autoclean;
+
+after set_authenticated => sub {
+ my $c = shift;
+ my $sessions = $c->user->get_extra_metadata('sessions');
+ push @$sessions, $c->sessionid;
+ $c->user->set_extra_metadata('sessions', $sessions);
+ $c->user->update;
+};
+
+before logout => sub {
+ my $c = shift;
+ if (my $user = $c->user) {
+ my $sessions = $user->get_extra_metadata('sessions');
+ $sessions = [ grep { $_ ne $c->sessionid } @$sessions ];
+ @$sessions ? $user->set_extra_metadata('sessions', $sessions) : $user->unset_extra_metadata('sessions');
+ $user->update;
+ }
+};
+
+__PACKAGE__;