aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdmund von der Burg <evdb@mysociety.org>2011-03-02 16:24:40 +0000
committerEdmund von der Burg <evdb@mysociety.org>2011-03-02 16:24:40 +0000
commite2df7e1ba55faafb5d14909b973b7d4b9a46535a (patch)
tree0fb045a09fe29780526a89abaa014400c6598197
parenta5298a835ac622fcacb53167e9f51d8e6ab805d1 (diff)
Ported AuthToken to DBIx::Class
-rwxr-xr-xdb/rerun_dbic_loader.pl2
-rw-r--r--perllib/FixMyStreet/DB/Result/Token.pm84
2 files changed, 85 insertions, 1 deletions
diff --git a/db/rerun_dbic_loader.pl b/db/rerun_dbic_loader.pl
index 241a4726b..fa93165de 100755
--- a/db/rerun_dbic_loader.pl
+++ b/db/rerun_dbic_loader.pl
@@ -16,7 +16,7 @@ my @tables_to_ignore = (
'abuse', 'admin_log', 'alert', 'alert_sent',
'alert_type', 'comment', 'contacts', 'contacts_history',
'debugdate', 'flickr_imported', 'partial_user', 'problem',
- 'questionnaire', 'secret', 'textmystreet', 'token',
+ 'questionnaire', 'secret', 'textmystreet',
);
my $exclude = '^(?:' . join( '|', @tables_to_ignore ) . ')$';
diff --git a/perllib/FixMyStreet/DB/Result/Token.pm b/perllib/FixMyStreet/DB/Result/Token.pm
new file mode 100644
index 000000000..2bdd8f90b
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/Token.pm
@@ -0,0 +1,84 @@
+package FixMyStreet::DB::Result::Token;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+
+__PACKAGE__->table("token");
+__PACKAGE__->add_columns(
+ "scope",
+ { data_type => "text", is_nullable => 0 },
+ "token",
+ { data_type => "text", is_nullable => 0 },
+ "data",
+ { data_type => "bytea", is_nullable => 0 },
+ "created",
+ {
+ data_type => "timestamp",
+ default_value => \"ms_current_timestamp()",
+ is_nullable => 0,
+ },
+);
+__PACKAGE__->set_primary_key( "scope", "token" );
+
+# Created by DBIx::Class::Schema::Loader v0.07009 @ 2011-03-02 16:14:01
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UfM8itc52wy22+YsRKuxmw
+
+# Trying not to use this
+# use mySociety::DBHandle qw(dbh);
+
+use mySociety::AuthToken;
+use IO::String;
+use RABX;
+
+=head1 NAME
+
+FixMyStreet::DB::Result::Token
+
+=head2 DESCRIPTION
+
+Representation of mySociety::AuthToken in the DBIx::Class world.
+
+Mostly done so that we don't need to use mySociety::DBHandle.
+
+The 'data' value is automatically inflated and deflated in the same way that the
+AuthToken would do it. 'token' is set to a new random value by default and the
+'created' timestamp is achieved using the database function
+ms_current_timestamp.
+
+=cut
+
+__PACKAGE__->inflate_column(
+ 'data',
+ {
+ inflate => sub {
+ my $ser = shift;
+ return undef unless defined $ser;
+ my $h = new IO::String($ser);
+ return RABX::wire_rd($h);
+ },
+ deflate => sub {
+ my $data = shift;
+ my $ser = '';
+ my $h = new IO::String($ser);
+ RABX::wire_wr( $data, $h );
+ return $ser;
+ },
+ }
+);
+
+sub new {
+ my ( $class, $attrs ) = @_;
+
+ $attrs->{token} ||= mySociety::AuthToken::random_token();
+ $attrs->{created} ||= \'ms_current_timestamp()';
+
+ my $new = $class->next::method($attrs);
+ return $new;
+}
+
+1;