move mailing to sendmail helper
This commit is contained in:
parent
68718860e2
commit
4787dbae15
3 changed files with 44 additions and 14 deletions
|
@ -12,6 +12,7 @@ use List::Util qw(first);
|
|||
use List::MoreUtils qw(after_incl before_incl);
|
||||
use Travel::Status::DE::IRIS;
|
||||
use Travel::Status::DE::IRIS::Stations;
|
||||
use Travelynx::Helper::Sendmail;
|
||||
|
||||
our $VERSION = qx{git describe --dirty} || 'experimental';
|
||||
|
||||
|
@ -492,6 +493,8 @@ qq{select * from pending_mails where email = ? and num_tries > 1;}
|
|||
},
|
||||
);
|
||||
|
||||
$self->helper(sendmail => sub { state $sendmail = Travelynx::Helper::Sendmail->new; });
|
||||
|
||||
$self->helper(
|
||||
'get_departures' => sub {
|
||||
my ( $self, $station, $lookbehind ) = @_;
|
||||
|
|
|
@ -2,9 +2,6 @@ package Travelynx::Controller::Account;
|
|||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use Crypt::Eksblowfish::Bcrypt qw(bcrypt en_base64);
|
||||
use Encode qw(decode encode);
|
||||
use Email::Sender::Simple qw(try_to_sendmail);
|
||||
use Email::Simple;
|
||||
use UUID::Tiny qw(:std);
|
||||
|
||||
sub hash_password {
|
||||
|
@ -143,17 +140,7 @@ sub register {
|
|||
$body .= " * Verwendeter Browser gemäß User Agent: ${ua}\n\n\n";
|
||||
$body .= "Impressum: ${imprint_url}\n";
|
||||
|
||||
my $reg_mail = Email::Simple->create(
|
||||
header => [
|
||||
To => $email,
|
||||
From => 'Travelynx <travelynx@finalrewind.org>',
|
||||
Subject => 'Registrierung bei travelynx',
|
||||
'Content-Type' => 'text/plain; charset=UTF-8',
|
||||
],
|
||||
body => encode( 'utf-8', $body ),
|
||||
);
|
||||
|
||||
my $success = try_to_sendmail($reg_mail);
|
||||
my $success = $self->sendmail->custom($email, 'Registrierung bei travelynx', $body);
|
||||
if ($success) {
|
||||
$self->app->dbh->commit;
|
||||
$self->render( 'login', from => 'register' );
|
||||
|
|
40
lib/Travelynx/Helper/Sendmail.pm
Normal file
40
lib/Travelynx/Helper/Sendmail.pm
Normal file
|
@ -0,0 +1,40 @@
|
|||
package Travelynx::Helper::Sendmail;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use 5.020;
|
||||
|
||||
use Encode qw(encode);
|
||||
use Email::Sender::Simple qw(try_to_sendmail);
|
||||
use Email::Simple;
|
||||
|
||||
sub new {
|
||||
my ($class) = @_;
|
||||
|
||||
return bless({}, $class);
|
||||
}
|
||||
|
||||
sub custom {
|
||||
my ($self, $to, $subject, $body) = @_;
|
||||
|
||||
my $reg_mail = Email::Simple->create(
|
||||
header => [
|
||||
To => $to,
|
||||
From => 'Travelynx <travelynx@finalrewind.org>',
|
||||
Subject => $subject,
|
||||
'Content-Type' => 'text/plain; charset=UTF-8',
|
||||
],
|
||||
body => encode( 'utf-8', $body ),
|
||||
);
|
||||
|
||||
if ($ENV{TRAVELYNX_DB_NAME} eq 'travelynx_deva') {
|
||||
# Do not send mail in dev mode
|
||||
say "sendmail to ${to}: ${subject}\n\n${body}";
|
||||
return 1;
|
||||
}
|
||||
|
||||
return try_to_sendmail($reg_mail);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in a new issue