Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Don't send email to unregistered users, hide difference
Browse files Browse the repository at this point in the history
Fixes #156.
  • Loading branch information
dboehmer committed May 17, 2022
1 parent 2445620 commit fc1abb2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 36 deletions.
9 changes: 0 additions & 9 deletions lib/Coocook/Controller/Email.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ sub recovery_link : Private {
);
}

sub recovery_unregistered : Private {
my ( $self, $c, $email ) = @_;

$c->stash(
email => { to => $email },
register_url => $c->uri_for_action('/user/register'),
);
}

sub verify : Private {
my ( $self, $c, $user, $token ) = @_;

Expand Down
4 changes: 1 addition & 3 deletions lib/Coocook/Controller/User.pm
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,7 @@ sub post_recover : POST Chained('/base') PathPart('recover') Args(0) Public {

$c->visit( '/email/recovery_link', [ $user, $token ] );
}
else {
$c->visit( '/email/recovery_unregistered', [$email_fc] );
}
else { } # nothing actually happens, difference invisible

$c->messages->info("Recovery link sent");
$c->response->redirect( $c->uri_for_action('/index') );
Expand Down
13 changes: 0 additions & 13 deletions root/email_templates/recovery_unregistered.tt

This file was deleted.

20 changes: 9 additions & 11 deletions t/lib/Test/Coocook.pm
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,17 @@ sub _get_email_body {

my $emails = $self->emails;

if ( @$emails == 0 ) {
carp "no emails stored";
return;
}
{
local $Carp::Internal{'Test2::API'} = 1;
local $Carp::Internal{'Test2::Tools::Subtest'} = 1;
local $Carp::Internal{'Test::Coocook'} = 1;

my $checked = $self->{coocook_checked_email_count} || 1;
if ( @$emails == 0 ) {
carp "no emails stored";
return;
}

{
local $Carp::Internal{'Test::Coocook'} = 1;
local $Carp::Internal{'Test::Builder'} = 1;
local $Carp::Internal{'Test::More'} = 1;
my $checked = $self->{coocook_checked_email_count} || 1;

@$emails > $checked
and carp "More than 1 email stored";
Expand Down Expand Up @@ -413,8 +413,6 @@ sub request_recovery_link_ok {

$self->text_contains('Recovery link sent')
or note $self->text;

$self->get_ok_email_link_like( qr/reset_password/, $name || "click email recovery link" );
};
}

Expand Down
7 changes: 7 additions & 0 deletions t/user_lifecycle.t
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,14 @@ subtest "password recovery" => sub {

ok $user->check_password('P@ssw0rd'), "password is same as before";

$t->request_recovery_link_ok('[email protected]');
my $content_unregistered = $t->response->decoded_content;

$t->request_recovery_link_ok('[email protected]');
is $t->response->decoded_content => $content_unregistered,
"content is same for unregistered email addresses";

$t->get_ok_email_link_like(qr/reset_password/);
$t->text_contains('verified');

$t->submit_form_ok(
Expand Down Expand Up @@ -344,6 +350,7 @@ subtest "password recovery marks email address verified" => sub {
"email_verified IS NULL";

$t->request_recovery_link_ok('[email protected]');
$t->get_ok_email_link_like(qr/reset_password/);
$t->submit_form_ok( { with_fields => { map { $_ => 'sUpEr s3cUr3' } 'password', 'password2' } },
"submit password reset form" );

Expand Down

0 comments on commit fc1abb2

Please sign in to comment.