Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for pass_token in email; tests added

  • Loading branch information...
commit 486ec6d169c5662bde8fad902b138af6ea17c695 1 parent 71ce900
Zbigniew Lukasiak authored
Showing with 21 additions and 7 deletions.
  1. +5 −4 lib/WebPrototypes/ResetPass.pm
  2. +16 −3 t/main.t
View
9 lib/WebPrototypes/ResetPass.pm
@@ -47,8 +47,9 @@ sub _index {
return $self->build_reply( "User not found" );
}
else{
- $self->update_user( $user, { pass_token => random_regex( '\w{40}' ) });
- $self->_send_pass_token( $env, $user, $username, $email );
+ my $pass_token = random_regex( '\w{40}' );
+ $self->update_user( $user, { pass_token => $pass_token });
+ $self->_send_pass_token( $env, $user, $username, $email, $pass_token );
return $self->build_reply( "Email sent" );
}
}
@@ -89,7 +90,7 @@ sub _send_pass_token {
my $reset_url = URI->new( $my_server );
$reset_url->path( $env->{SCRIPT_NAME} . '/reset' );
$reset_url->query_form( name => $username, pass_token => $pass_token );
- $self->send_mail( $self->build_email( $email, $reset_url ) );
+ $self->send_mail( $self->build_email( $email, $reset_url ), $pass_token );
}
sub _reset {
@@ -185,7 +186,7 @@ These methods need to be overriden in subclass.
Should return a following tuple
$user, $user_email, $verification_token
-The C<$user> is user object - passed to the C<update_user> method
+The C<$user> is user object or user id - passed to the C<update_user> method
=item update_user ( user, params )
View
19 t/main.t
@@ -5,6 +5,10 @@ use Test::More;
use Test::WWW::Mechanize::PSGI;
use Plack::Builder;
+my $email;
+my $pass_token;
+my $password;
+
{
package My::ResetPass;
use parent 'WebPrototypes::ResetPass';
@@ -16,11 +20,15 @@ use Plack::Builder;
}
sub send_mail {
- my( $self, $email ) = @_;
- return $email;
+ my( $self, $email_ ) = @_;
+ $email = $email_;
}
- sub update_user {}
+ sub update_user {
+ my( $self, $user, $params ) = @_;
+ $pass_token = $params->{pass_token};
+ $password = $params->{password};
+ }
}
@@ -54,6 +62,9 @@ $mech->submit_form_ok( {
);
$mech->content_contains( 'Email sent', 'email sent' );
+is( scalar( $email->header( 'To' ) ), 'test@example.com', 'Confirmation email recepient' );
+like( $email->body, qr/token=$pass_token/, 'Email contains link with the right token' );
+
$mech->get_ok( '/forgotten_pass/reset?name=right_name&token=aaaa', 'reset token' );
$mech->content_contains( 'Token invalid', 'invalid reset token' );
$mech->get_ok( '/forgotten_pass/reset?name=right_name&token=a', 'reset token' );
@@ -66,4 +77,6 @@ $mech->submit_form_ok( {
'ResetPass for test'
);
+is( $password, 'new password', 'Password reset' );
+
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.