diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-14 11:53:40 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-05-23 18:55:09 +0100 |
commit | 910b1b8fef7e19b102459c97fc700a117d7a12aa (patch) | |
tree | 81d163980e8beb9c6dc05773ffbe52dc0ab5a36b /perllib/FixMyStreet/DB/Result/Session.pm | |
parent | 110a80eff22e852974bc5a6f90295803ef7e0de6 (diff) |
Refactor out some session functions.
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; |