Finsished breaking out anonymous (un)subscribe functions.
This commit is contained in:
parent
28e49e3dab
commit
66209f4102
1 changed files with 20 additions and 13 deletions
|
|
@ -2,6 +2,7 @@ package WebGUI::AssetAspect::Subscriber;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use 5.010;
|
||||
use Class::C3;
|
||||
use Carp;
|
||||
|
||||
|
|
@ -473,6 +474,7 @@ sub www_confirmMutation {
|
|||
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub subscribeAnonymous {
|
||||
my $self = shift;
|
||||
my $email = shift; # TODO || return ?
|
||||
|
|
@ -480,6 +482,7 @@ sub subscribeAnonymous {
|
|||
|
||||
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email );
|
||||
|
||||
# If email address doesn't have an account, create one.
|
||||
if ( !defined $emailUser ) {
|
||||
$emailUser = WebGUI::User::SpecialState->create( $session );
|
||||
$emailUser->update( { email => $email } );
|
||||
|
|
@ -491,6 +494,20 @@ sub subscribeAnonymous {
|
|||
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 {
|
||||
my $self = shift;
|
||||
|
|
@ -515,19 +532,9 @@ sub www_processSubscription {
|
|||
my $email = $form->email( 'email' );
|
||||
return 'Error: no email address passed' unless $email;
|
||||
|
||||
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email );
|
||||
if ( $action eq 'unsubscribe' && defined $emailUser ) {
|
||||
$self->unsubscribe( $emailUser, 1 );
|
||||
}
|
||||
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 );
|
||||
given ( $action ) {
|
||||
when ( 'unsubscribe' ) { $self->unsubscribeAnonymous( $email ); }
|
||||
when ( 'subscribe' ) { $self->subscribeAnonymous( $email ); }
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue