Add text/plain part to confirmation and notifiocation mails.
This commit is contained in:
parent
a15b6a0edb
commit
63b0a9edf1
1 changed files with 41 additions and 21 deletions
|
|
@ -3,7 +3,7 @@ package WebGUI::AssetAspect::Subscriber;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use 5.010;
|
use 5.010;
|
||||||
use Class::C3;
|
use Class::C3;
|
||||||
use Carp;
|
use Carp;
|
||||||
|
|
||||||
use WebGUI::Asset::Template;
|
use WebGUI::Asset::Template;
|
||||||
|
|
@ -45,7 +45,7 @@ sub definition {
|
||||||
alwaysConfirmSubscription => {
|
alwaysConfirmSubscription => {
|
||||||
fieldType => 'yesNo',
|
fieldType => 'yesNo',
|
||||||
defaultValue => 0,
|
defaultValue => 0,
|
||||||
label => $i18n->get( 'require confirmation' ),
|
label => $i18n->get( 'require confirmation' ),
|
||||||
tab => 'subscription',
|
tab => 'subscription',
|
||||||
},
|
},
|
||||||
allowAnonymousSubscription => {
|
allowAnonymousSubscription => {
|
||||||
|
|
@ -128,7 +128,7 @@ sub getListHeaders {
|
||||||
my $site = $self->session->url->getSiteURL;
|
my $site = $self->session->url->getSiteURL;
|
||||||
|
|
||||||
my $headers = {
|
my $headers = {
|
||||||
'List-Unsubscribe' =>
|
'List-Unsubscribe' =>
|
||||||
'<' . $site . $self->getUrl( "func=processSubscription&action=unsubscribe&email=$email" ) . '>',
|
'<' . $site . $self->getUrl( "func=processSubscription&action=unsubscribe&email=$email" ) . '>',
|
||||||
'List-Subscribe' =>
|
'List-Subscribe' =>
|
||||||
'<' . $site . $self->getUrl( "func=processSubscription&action=subscribe&email=$email" ) . '>',
|
'<' . $site . $self->getUrl( "func=processSubscription&action=subscribe&email=$email" ) . '>',
|
||||||
|
|
@ -192,13 +192,13 @@ sub appendSubscriptionFormVars {
|
||||||
my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' );
|
my $i18n = WebGUI::International->new( $session, 'AssetAspect_Subscriber' );
|
||||||
|
|
||||||
# Setup form controls
|
# Setup form controls
|
||||||
my $formHeader =
|
my $formHeader =
|
||||||
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
||||||
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
||||||
;
|
;
|
||||||
my $subscribeButton =
|
my $subscribeButton =
|
||||||
sprintf '<button type="submit" name="action" value="subscribe">%s</button>', $i18n->get('subscribe');
|
sprintf '<button type="submit" name="action" value="subscribe">%s</button>', $i18n->get('subscribe');
|
||||||
my $unsubscribeButton =
|
my $unsubscribeButton =
|
||||||
sprintf '<button type="submit" name="action" value="unsubscribe">%s</button>', $i18n->get('unsubscribe');
|
sprintf '<button type="submit" name="action" value="unsubscribe">%s</button>', $i18n->get('unsubscribe');
|
||||||
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
||||||
my $formFooter = WebGUI::Form::formFooter( $session );
|
my $formFooter = WebGUI::Form::formFooter( $session );
|
||||||
|
|
@ -231,8 +231,8 @@ sub appendSubscriptionFormVars {
|
||||||
sub getSubscriptionGroup {
|
sub getSubscriptionGroup {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $groupId = $self->get( "subscriptionGroupId" );
|
my $groupId = $self->get( "subscriptionGroupId" );
|
||||||
my $group = $groupId
|
my $group = $groupId
|
||||||
? WebGUI::Group->new( $self->session, $groupId )
|
? WebGUI::Group->new( $self->session, $groupId )
|
||||||
: $self->createSubscriptionGroup
|
: $self->createSubscriptionGroup
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -243,7 +243,7 @@ sub getSubscriptionGroup {
|
||||||
sub getReturnUrl {
|
sub getReturnUrl {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $referer = $self->session->env->get('HTTP_REFERER');
|
my $referer = $self->session->env->get('HTTP_REFERER');
|
||||||
|
|
||||||
return unless $referer;
|
return unless $referer;
|
||||||
|
|
||||||
# Get path and strip leading and trailing slash if it exists.
|
# Get path and strip leading and trailing slash if it exists.
|
||||||
|
|
@ -331,14 +331,18 @@ sub sendSubscriptionConfirmation {
|
||||||
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
||||||
|
|
||||||
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
||||||
to => $user->get('email'),
|
to => $user->get('email'),
|
||||||
subject => $self->get('confirmationEmailSubject'),
|
subject => $self->get('confirmationEmailSubject'),
|
||||||
|
contentType => 'multipart/alternative',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
my $templateId = $self->get('confirmationEmailTemplateId');
|
my $templateId = $self->get('confirmationEmailTemplateId');
|
||||||
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
||||||
if ( $template ) {
|
if ( $template ) {
|
||||||
$mail->addHtml( $template->process( $var ) );
|
my $content = $template->process( $var );
|
||||||
|
|
||||||
|
$mail->addHtml( $content );
|
||||||
|
$mail->addText( $self->transformToText( $content ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$session->log->error( "Cannot instanciate confirmation email template with id [$templateId]" );
|
$session->log->error( "Cannot instanciate confirmation email template with id [$templateId]" );
|
||||||
|
|
@ -362,14 +366,18 @@ sub sendNoMutationEmail {
|
||||||
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
$var->{ actionIsSubscribe } = $action eq 'subscribe';
|
||||||
|
|
||||||
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
my $mail = WebGUI::Mail::Send->create( $self->session, {
|
||||||
to => $user->get('email'),
|
to => $user->get('email'),
|
||||||
subject => $self->get('noMutationEmailSubject'),
|
subject => $self->get('noMutationEmailSubject'),
|
||||||
|
contentType => 'multipart/alternative',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
my $templateId = $self->get('noMutationEmailTemplateId');
|
my $templateId = $self->get('noMutationEmailTemplateId');
|
||||||
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
my $template = WebGUI::Asset::Template->new( $session, $templateId );
|
||||||
if ( $template ) {
|
if ( $template ) {
|
||||||
$mail->addHtml( $template->process( $var ) );
|
my $content = $template->process( $var );
|
||||||
|
|
||||||
|
$mail->addHtml( $content );
|
||||||
|
$mail->addText( $self->transformToText( $content ) );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$session->log->error( "Cannot instanciate no mutation email template with id [$templateId]" );
|
$session->log->error( "Cannot instanciate no mutation email template with id [$templateId]" );
|
||||||
|
|
@ -383,6 +391,18 @@ sub sendNoMutationEmail {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub transformToText {
|
||||||
|
my $self = shift;
|
||||||
|
my $html = shift;
|
||||||
|
|
||||||
|
my $text = $html;
|
||||||
|
#HTML::Entities::decode($text);
|
||||||
|
$text =~ s/<a.*?href=["'](.*?)['"].*?>(.+?)<\/a>/$2 ($1)/g;
|
||||||
|
$text = WebGUI::HTML::html2text($text);
|
||||||
|
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub logConfirmation {
|
sub logConfirmation {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
@ -390,7 +410,7 @@ sub logConfirmation {
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $db = $session->db;
|
my $db = $session->db;
|
||||||
|
|
||||||
$db->write(
|
$db->write(
|
||||||
' update assetAspectSubscriber_log set '
|
' update assetAspectSubscriber_log set '
|
||||||
.' confirmationIp=?, confirmationDate=?, confirmed=? where code=? and assetId=?',
|
.' confirmationIp=?, confirmationDate=?, confirmed=? where code=? and assetId=?',
|
||||||
[
|
[
|
||||||
|
|
@ -414,7 +434,7 @@ sub logRequest {
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $db = $session->db;
|
my $db = $session->db;
|
||||||
|
|
||||||
$db->write(
|
$db->write(
|
||||||
' insert into assetAspectSubscriber_log set '
|
' insert into assetAspectSubscriber_log set '
|
||||||
.' assetId=?, requestIp=?, requestDate=?, code=?, confirmed=?, anonymous=?, type=?, userId=?, email=?',
|
.' assetId=?, requestIp=?, requestDate=?, code=?, confirmed=?, anonymous=?, type=?, userId=?, email=?',
|
||||||
[
|
[
|
||||||
|
|
@ -440,7 +460,7 @@ sub subscribe {
|
||||||
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
||||||
|
|
||||||
if ( $requireConfirm ) {
|
if ( $requireConfirm ) {
|
||||||
if ( $user->isInGroup( $self->getSubscriptionGroup->getId ) ) {
|
if ( $user->isInGroup( $self->getSubscriptionGroup->getId ) ) {
|
||||||
$self->sendNoMutationEmail( $user, 'subscribe' );
|
$self->sendNoMutationEmail( $user, 'subscribe' );
|
||||||
|
|
@ -466,7 +486,7 @@ sub unsubscribe {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $user = shift || $self->session->user;
|
my $user = shift || $self->session->user;
|
||||||
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
||||||
|
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
||||||
if ( $requireConfirm ) {
|
if ( $requireConfirm ) {
|
||||||
|
|
@ -499,8 +519,8 @@ sub www_confirmMutation {
|
||||||
my $code = $form->get('code');
|
my $code = $form->get('code');
|
||||||
return unless $code;
|
return unless $code;
|
||||||
|
|
||||||
my ($userId, $type) = $db->quickArray(
|
my ($userId, $type) = $db->quickArray(
|
||||||
'select userId, type from assetAspectSubscriber_log where confirmed=? and code=?',
|
'select userId, type from assetAspectSubscriber_log where confirmed=? and code=?',
|
||||||
[
|
[
|
||||||
0,
|
0,
|
||||||
$code,
|
$code,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue