Skip to content

Commit

Permalink
add forgot password functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Closs committed Aug 15, 2011
1 parent 55ddfac commit 71e3d6c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
32 changes: 29 additions & 3 deletions lib/Biopay.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ our $VERSION = '0.1';

my %public_paths = (
map { $_ => 1 }
qw( / /login /logout /terms /refunds /privacy ),
'/admin-login',
qw( / /login /logout /terms /refunds /privacy),
'/forgot-password', '/admin-login',
);

before sub {
Expand Down Expand Up @@ -144,7 +144,7 @@ post '/login' => sub {
get '/set-password' => sub {
my $user = param('username');
unless ($user) {
return forward "/login";
return redirect "/login";
}
my $member = Biopay::Member->By_email($user);
if ($member and !$member->password) {
Expand Down Expand Up @@ -633,4 +633,30 @@ get '/member/unpaid' => sub {
};
};

get '/forgot-password' => sub {
debug session('message');
template 'forgot-password', {message => params->{message}};
};
post '/forgot-password' => sub {
my $email = params->{email};
unless ($email) {
return forward '/forgot-password', {
message => "Please enter your email address.",
}, {method => 'GET'};
}

my $m = Biopay::Member->By_email($email);
unless ($m) {
return forward '/forgot-password', {
message => "Sorry, a member with that email address cannot "
. "be found.",
}, {method => 'GET'};
}

$m->send_set_password_email;
# Remember to save the hash
$m->save;
template 'forgot-password', { email_sent => 1 };
};

true;
1 change: 1 addition & 0 deletions lib/Biopay/Member.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ method send_billing_error_email {
}

method send_set_password_email {
delete $self->{login_hash}; # Cause it to be re-created
my $html = template 'email/set-password', {
member => $self,
}, { layout => 'email' };
Expand Down
27 changes: 27 additions & 0 deletions views/forgot-password.tt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h1>Forgot your password?</h1>
[% INCLUDE message.tt %]
[% IF email_sent %]
<p>Done! Check your email for a link to reset your password.</p>
[% ELSE %]
<p>No problem. Just enter in your email address and we will email you a link to reset it.</p>
<form action="[% host %]/forgot-password" method="POST">
<table class="forgot-password">
<tr>
<td>Email Address:</td>
<td><input id="email" type="text" name="email" size=20 /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Reset my password!" />
</td>
</table>
</form>
</p>
<script>
jQuery( function () {
$("#email").focus();
}
);
</script>
[% END %]

0 comments on commit 71e3d6c

Please sign in to comment.