diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-24 10:33:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-24 10:33:05 +0100 |
commit | 72ab2740e2c8c24e62b6e9d98f686498b1225b09 (patch) | |
tree | 4e0260c14afbbdcd79ebe66f09aa37d9af509157 /perllib/FixMyStreet/DB/Result/Session.pm | |
parent | da305260b4db386af9fb2c48d9055a2934069c84 (diff) | |
parent | ec4fb8fe445efd5cb584ac7021707c41a0188cdb (diff) |
Merge branch 'user-inactivity'
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Session.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Session.pm | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Session.pm b/perllib/FixMyStreet/DB/Result/Session.pm index 4713c99eb..a478c5444 100644 --- a/perllib/FixMyStreet/DB/Result/Session.pm +++ b/perllib/FixMyStreet/DB/Result/Session.pm @@ -24,5 +24,24 @@ __PACKAGE__->set_primary_key("id"); # Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:MVmCn4gLQWXTDIIaDHiVmA -# You can replace this text with custom code or comments, and it will be preserved on regeneration +use Storable; +use MIME::Base64; + +sub id_code { + my $self = shift; + my $id = $self->id; + $id =~ s/^session://; + $id =~ s/\s+$//; + return $id; +} + +sub user { + my $self = shift; + return unless $self->session_data; + my $data = Storable::thaw(MIME::Base64::decode($self->session_data)); + return unless $data->{__user}; + my $user = $self->result_source->schema->resultset("User")->find($data->{__user}{id}); + return $user; +} + 1; |