Finsished breaking out anonymous (un)subscribe functions.

This commit is contained in:
Martin Kamerbeek 2010-10-13 15:16:06 +02:00
parent 28e49e3dab
commit 66209f4102

View file

@ -2,6 +2,7 @@ package WebGUI::AssetAspect::Subscriber;
use strict; use strict;
use warnings; use warnings;
use 5.010;
use Class::C3; use Class::C3;
use Carp; use Carp;
@ -473,6 +474,7 @@ sub www_confirmMutation {
} }
#----------------------------------------------------------------------------
sub subscribeAnonymous { sub subscribeAnonymous {
my $self = shift; my $self = shift;
my $email = shift; # TODO || return ? my $email = shift; # TODO || return ?
@ -480,6 +482,7 @@ sub subscribeAnonymous {
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email ); my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email );
# If email address doesn't have an account, create one.
if ( !defined $emailUser ) { if ( !defined $emailUser ) {
$emailUser = WebGUI::User::SpecialState->create( $session ); $emailUser = WebGUI::User::SpecialState->create( $session );
$emailUser->update( { email => $email } ); $emailUser->update( { email => $email } );
@ -491,6 +494,20 @@ sub subscribeAnonymous {
return; return;
} }
#----------------------------------------------------------------------------
sub unsubscribeAnonymous {
my $self = shift;
my $email = shift;
my $session = $self->session;
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email );
if ( defined $emailUser ) {
$self->unsubscribe( $emailUser, 1 );
}
return;
}
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
sub www_processSubscription { sub www_processSubscription {
my $self = shift; my $self = shift;
@ -515,19 +532,9 @@ sub www_processSubscription {
my $email = $form->email( 'email' ); my $email = $form->email( 'email' );
return 'Error: no email address passed' unless $email; return 'Error: no email address passed' unless $email;
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email ); given ( $action ) {
if ( $action eq 'unsubscribe' && defined $emailUser ) { when ( 'unsubscribe' ) { $self->unsubscribeAnonymous( $email ); }
$self->unsubscribe( $emailUser, 1 ); when ( 'subscribe' ) { $self->subscribeAnonymous( $email ); }
}
if ( $action eq 'subscribe' ) {
$self->subscribeAnonymous( $email );
#if ( !defined $emailUser ) {
# $emailUser = WebGUI::User::SpecialState->create( $session );
# $emailUser->update( { email => $email } );
#}
#$emailUser->addSpecialState( 'Subscriber', $self->getId );
#$self->subscribe( $emailUser, 1 );
} }
} }
else { else {