aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/DBIx/Class/FixMyStreet/EncodedColumn.pm
blob: 82e6e591e706d511eefb76133a4292db93a8b3f3 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package DBIx::Class::FixMyStreet::EncodedColumn;

use strict;
use warnings;

use base qw/DBIx::Class::EncodedColumn/;

# mySociety override to allow direct setting without double encryption
sub set_column {
  my $self = shift;
  if ($_[0] eq 'password') {
    my $cobrand = $self->result_source->schema->cobrand;
    if ($cobrand && $cobrand->moniker eq 'tfl') {
      if (defined $_[1]) {
        if (defined $_[2]) {
          $self->set_extra_metadata(tfl_password => $_[1]);
        } else {
          my $encoder = $self->_column_encoders->{password};
          $self->set_extra_metadata(tfl_password => $encoder->($_[1]));
        }
      }
      return $self->get_extra_metadata('tfl_password');
    }
  }
  return DBIx::Class::Row::set_column($self, @_) unless defined $_[1] and not defined $_[2];
  $self->next::method(@_);
}

1;

__END__;

=head1 NAME

DBIx::Class::FixMyStreet::EncodedColumn - Automatically encode columns

=head1 SYNOPSIS

The same as DBIx::Class::EncodedColumn, but adding an extra optional second
argument to set_column to allow skipping encryption (so if we hold an
already-hashed password, we can set it directly).

In your application code:

   $row->password('plaintext');
   $row->password('hashed-password', 1);

=head1 EXTENDED METHODS

The following L<DBIx::Class::Row> methods are extended by this module:

=over 4

=item B<set_column> - Encode values whenever column is set.

=back

=head1 SEE ALSO

L<DBIx::Class::EncodedColumn>, L<DBIx::Class>

=cut