Hello joel
you can test you post with curl
curl -d "param1=value1¶m2=value2" http://localhost:80/reminder
add debug line in red
sub send_out_mail {
use Email::Stuffer;
my( $email, $body) = @_;
debug $email, $body;
my $sender = '[email protected]';
Email::Stuffer->from($sender)
->to($email)
->subject("Reminder")
->text_body($body)
->send;
}
and change
sub find_passwd {
return({ email => '[email protected]', name => 'Name', password
=> 'password', body => 'body' })
;
}
the result seems correct ( without crash )
[7255] core @0.000110> request: POST /reminder from 127.0.0.1 in
/usr/local/share/perl5/Dancer/Handler.pm l. 56
[7255] core @0.000573> [hit #1]Trying to match 'POST /reminder' against
/^\/reminder$/ (generated from '/reminder') in
/usr/local/share/perl5/Dancer/Route.pm l. 84
[7255] core @0.000695> [hit #1] --> got 1 in
/usr/local/share/perl5/Dancer/Route.pm l. 102
[7255] core @0.001035> [hit #1]entering before hook in
/usr/local/share/perl5/Dancer/Hook.pm l. 58
[7255] debug @0.003781> [hit #1][email protected] in
/home/test/pobox/lib/pobox.pm l. 69
[7255] core @0.606941> [hit #1]response: 302 in
/usr/local/share/perl5/Dancer/Handler.pm l. 181
for my point of view, pb come from
find_passwd { }
add debug ligne to check all, before send email,
bye
Hugues
Le 26/04/2014 09:09, Joel Roth a écrit :
Hi Dancers,
During development, I've put a file with the
username/email/password on the site (generally bad practice,
I know), and have a button for sending a password reminder.
When the user posts a form with an "email" field to
the /reminder route (see below) it results in the following error,
which is issued *after* the mail is sent out:
The page 'http://localhost:3000/reminder' couldn't be
loaded. Message Corrupt
I would expect a redirect to '/reminder-has-been-sent'
Do you have any suggestions?
Kind regards,
Joel
--
post '/reminder' => sub {
my $email = params->{email};
my $result = find_passwd($email);
session user => undef;
session failed_login => undef;
if ($result)
{
send_out_mail($result->{email}, $result->{body}); # sent!
redirect '/reminder-has-been-sent'; # no redirect
}
else
{
redirect '/email-not-found';
}
};
There is a "before" clause.
before sub {
if (!session('user') and request->path_info !~
m{(login|bye|reminder|reminder-has-been-sent|email-not-found)$}) {
# Pass the original path requested along to the handler:
session requested_path => request->path_info;
redirect('/login');
}
elsif ( ! authorized( session('user'), request->path_info)
and request->path_info ne '/forbidden'){
# Pass the original path requested along to the handler:
session requested_path => request->path_info;
redirect('/forbidden');
}
};
sub find_passwd {
my $user_or_email = shift;
# we expect to be in Dancer app directory
my @entries = read_file('pass');
my $body;
my ($name, $email, $username, $password);
map { chomp } @entries;
foreach my $entry( @entries ){
($name, $email, $username, $password) = split /\s*:\s*/, $entry;
next if $user_or_email ne $username and $user_or_email ne
$email;
say "-->$name";
$body = mail_body($name, $username, $password);
last
}
return({ email => $email, name => $name, password => $password, body =>
$body })
if $body;
}
sub mail_body {
my ($name, $username, $password) = @_;
my ($first) = $name =~ /(.+?)\s*\S*$/;
#say $first;
<<FORM;
Dear $first,
This automated mail contains your login credentials for
http://example.com
Your username is $username
Your password is $password
FORM
}
sub send_out_mail {
my( $email, $body) = @_;
my $sender = '[email protected]';
Email::Stuffer->from($sender)
->to($email)
->subject("Reminder")
->text_body($body)
->send;
}
1
_______________________________________________
dancer-users mailing list
[email protected]
http://lists.preshweb.co.uk/mailman/listinfo/dancer-users