]> 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 4922354cfb4061aaade9c0725f3e235b34427ec7..5c8fe856712095fffeaca0303d31a782892e0017 100644 (file)
@@ -87,6 +87,14 @@ Highschool, Undergraduate, Master, Doctorate or Other
 
 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(
@@ -112,6 +120,12 @@ __PACKAGE__->add_columns(
   { 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
@@ -219,10 +233,12 @@ __PACKAGE__->has_many(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2015-01-29 18:45:35
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:rpx697B3St+ICCSbOn4cbQ
+# 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) = @_;
@@ -247,6 +263,16 @@ sub set_passphrase {
        )->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;
 
 __END__
This page took 0.029706 seconds and 4 git commands to generate.