aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Catalyst/Plugin/FixMyStreet/Session/RotateSession.pm
blob: 8da88721f75f985e4bd1ae5b0dd525d616dfb313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package Catalyst::Plugin::FixMyStreet::Session::RotateSession;
use Moose::Role;
use namespace::autoclean;

# After successful authentication, rotate the session ID
after set_authenticated => sub {
    my $c = shift;
    $c->change_session_id;
};

# The below is necessary otherwise the rotation fails due to the delegate
# holding on to the now-deleted old session. See
# https://rt.cpan.org/Public/Bug/Display.html?id=112679

after delete_session_data => sub {
    my ($c, $key) = @_;

    my ($field) = split(':', $key);
    if ($field eq 'session') {
        $c->_session_store_delegate->_session_row(undef);
    } elsif ($field eq 'flash') {
        $c->_session_store_delegate->_flash_row(undef);
    }
};

1;