]> iEval git - gruntmaster-data.git/blobdiff - lib/Gruntmaster/Data/Result/User.pm
Make the make_reset_hmac function actually useful
[gruntmaster-data.git] / lib / Gruntmaster / Data / Result / User.pm
index 4385b76554c55b5971a0891b40df28a5112f1264..5c8fe856712095fffeaca0303d31a782892e0017 100644 (file)
@@ -6,7 +6,7 @@ package Gruntmaster::Data::Result::User;
 
 =head1 NAME
 
-Gruntmaster::Data::Result::User
+Gruntmaster::Data::Result::User - List of users
 
 =cut
 
@@ -33,6 +33,8 @@ __PACKAGE__->table("users");
   data_type: 'text'
   is_nullable: 1
 
+RFC2307-encoded passphrase
+
 =head2 admin
 
   data_type: 'boolean'
@@ -44,6 +46,8 @@ __PACKAGE__->table("users");
   data_type: 'text'
   is_nullable: 1
 
+Full name of user
+
 =head2 email
 
   data_type: 'text'
@@ -69,11 +73,28 @@ __PACKAGE__->table("users");
   data_type: 'text'
   is_nullable: 1
 
+Highschool, Undergraduate, Master, Doctorate or Other
+
+=head2 country
+
+  data_type: 'text'
+  is_nullable: 1
+
 =head2 lastjob
 
   data_type: 'bigint'
   is_nullable: 1
 
+Unix time when this user last submitted a job
+
+=head2 since
+
+  data_type: 'bigint'
+  default_value: (date_part('epoch'::text, now()))::bigint
+  is_nullable: 1
+
+Unix time when this user was created
+
 =cut
 
 __PACKAGE__->add_columns(
@@ -95,8 +116,16 @@ __PACKAGE__->add_columns(
   { data_type => "text", is_nullable => 1 },
   "level",
   { data_type => "text", is_nullable => 1 },
+  "country",
+  { data_type => "text", is_nullable => 1 },
   "lastjob",
   { data_type => "bigint", is_nullable => 1 },
+  "since",
+  {
+    data_type     => "bigint",
+    default_value => \"(date_part('epoch'::text, now()))::bigint",
+    is_nullable   => 1,
+  },
 );
 
 =head1 PRIMARY KEY
@@ -113,6 +142,21 @@ __PACKAGE__->set_primary_key("id");
 
 =head1 RELATIONS
 
+=head2 contest_statuses
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::ContestStatus>
+
+=cut
+
+__PACKAGE__->has_many(
+  "contest_statuses",
+  "Gruntmaster::Data::Result::ContestStatus",
+  { "foreign.owner" => "self.id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 contests
 
 Type: has_many
@@ -158,6 +202,21 @@ __PACKAGE__->has_many(
   { cascade_copy => 0, cascade_delete => 0 },
 );
 
+=head2 problem_statuses
+
+Type: has_many
+
+Related object: L<Gruntmaster::Data::Result::ProblemStatus>
+
+=cut
+
+__PACKAGE__->has_many(
+  "problem_statuses",
+  "Gruntmaster::Data::Result::ProblemStatus",
+  { "foreign.owner" => "self.id" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 =head2 problems
 
 Type: has_many
@@ -174,8 +233,18 @@ __PACKAGE__->has_many(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07039 @ 2014-05-16 15:23:08
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Cho4zmn58Mytf2jHvgP+4g
+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-02-10 18:42:04
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L/ExLdA0pkJ1DeM+RzlDjw
+
+use Bytes::Random::Secure qw/random_bytes/;
+use Class::Method::Modifiers qw/after/;
+use Digest::SHA qw/hmac_sha1_base64/;
+
+after qw/insert update delete/ => sub {
+       my ($self) = @_;
+       Gruntmaster::Data::purge '/us/';
+       Gruntmaster::Data::purge '/us/' . $self->id;
+};
 
 use Authen::Passphrase;
 use Authen::Passphrase::BlowfishCrypt;
@@ -191,7 +260,17 @@ sub set_passphrase {
                cost => 10,
                passphrase => $pw,
                salt_random => 1,
-       )})->as_rfc2307;
+       )->as_rfc2307});
+}
+
+my $hmackey = $ENV{GRUNTMASTER_HMAC_KEY};
+
+sub make_reset_hmac {
+       my ($self, $expire) = @_;
+       $expire  //= time + 60 * 60;
+       $hmackey //= random_bytes 512;
+       my $hmac = hmac_sha1_base64 $self->id . " $expire " . $self->passphrase, $hmackey;
+       wantarray ? ($hmac, $expire) : $hmac
 }
 
 1;
This page took 0.022984 seconds and 4 git commands to generate.