]> iEval git - gruntmaster-page.git/commitdiff
Merge branch 'master' into newmc
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Feb 2015 15:43:08 +0000 (17:43 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 16 Feb 2015 15:43:08 +0000 (17:43 +0200)
1  2 
lib/Plack/App/Gruntmaster.pm

index 185017b82b38cf1abe9445621ec75367887f3507,bfc2e27049b064f09bc4d7f6e1c4d4fb5b01c8bc..0cb7aabca2fa1b0dd392b33ea74b9f0b29d61900
@@@ -16,6 -16,9 +16,9 @@@ use Web::Simple
  use Gruntmaster::Data;
  use Plack::App::Gruntmaster::HTML;
  
+ use Email::Sender::Simple qw/sendmail/;
+ use Email::Simple;
  use warnings NONFATAL => 'all';
  no warnings 'illegalproto';
  
@@@ -160,8 -163,7 +163,8 @@@ sub dispatch_request
  
                sub (/ed/:contest) {
                        forbid contest->is_running;
 -                      response ed => 'Editorial of ' . contest->name, db->problem_list(contest => $_{contest}, solution => 1);
 +                      my $pblist = db->problem_list(contest => $_{contest}, solution => 1);
 +                      response ed => 'Editorial of ' . contest->name, {%$pblist, editorial => contest->editorial};
                },
  
                sub (/login) {
  
                        purge '/log/';
                        [303, [Location => '/log/' . $newjob->id], []]
-               }
+               },
+               sub (/action/request-reset + %:username=) {
+                       return reply 'Password resets are disabled' unless $ENV{GRUNTMASTER_RESET_FROM};
+                       my $user = db->user($_{username});
+                       return reply 'No such user' unless $user;
+                       my $token = join ':', $user->make_reset_hmac;
+                       my $body = <<EOF;
+ Someone has requested a password reset for your account.
+ To reset your password, please submit the reset password form on the
+ website using the following information:
+ Username: $_{username}
+ Password: <your new password>
+ Reset token: $token
+ EOF
+                       my $email = Email::Simple->create(
+                               header => [
+                                       From    => $ENV{GRUNTMASTER_RESET_FROM},
+                                       To      => $user->email,
+                                       Subject => 'Password reset token',
+                               ],
+                               body => $body,
+                       );
+                       my $ok = 0;
+                       eval {
+                               sendmail $email;
+                               $ok = 1;
+                       };
+                       return reply 'Email sent' if $ok;
+                       reply "Failure sending email: $@";
+               },
+               sub (/action/reset + %:username=&:password=&:token=) {
+                       my $user = db->user($_{username});
+                       return reply 'No such user' unless $user;
+                       my ($token, $exp) = split ':', $_{token};
+                       return reply 'Bad reset token' unless $user->make_reset_hmac($exp) eq $token;
+                       $user->set_passphrase($_{password});
+                       reply 'Password reset successfully';
+               },
        }
  }
  
This page took 0.026891 seconds and 4 git commands to generate.