Adding basic anonymous subscription.
This commit is contained in:
parent
c4115cc82a
commit
8fdeca68b5
3 changed files with 124 additions and 5 deletions
|
|
@ -4,6 +4,7 @@ use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
use Class::C3;
|
use Class::C3;
|
||||||
|
use WebGUI::User::SpecialState;
|
||||||
|
|
||||||
use base qw{
|
use base qw{
|
||||||
WebGUI::AssetAspect::Mailable
|
WebGUI::AssetAspect::Mailable
|
||||||
|
|
@ -126,6 +127,39 @@ sub isSubscribed {
|
||||||
# $self->{_viewTemplate} = $template;
|
# $self->{_viewTemplate} = $template;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getSubscriptionForm {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
||||||
|
|
||||||
|
my $formHeader =
|
||||||
|
WebGUI::Form::formHeader( $session, { action => $self->getUrl } )
|
||||||
|
. WebGUI::Form::hidden( $session, { name => 'func', value => 'processSubscription' } )
|
||||||
|
;
|
||||||
|
my $subscribeButton =
|
||||||
|
sprintf '<button type="submit" name="action" value="subscribe">%s</button>', $i18n->get('subscribe');
|
||||||
|
my $unsubscribeButton =
|
||||||
|
sprintf '<button type="submit" name="action" value="unsubscribe">%s</button>', $i18n->get('unsubscribe');
|
||||||
|
my $emailBox = WebGUI::Form::email( $session, { name => 'email', value => '' } );
|
||||||
|
my $formFooter = WebGUI::Form::formFooter( $session );
|
||||||
|
|
||||||
|
my $output = '';
|
||||||
|
if ( $session->user->isRegistered ) {
|
||||||
|
$output .= $subscribeButton if $self->canSubscribe;
|
||||||
|
$output .= $unsubscribeButton if $self->canUnsubscribe;
|
||||||
|
|
||||||
|
return unless $output;
|
||||||
|
return $formHeader . $output . $formFooter;
|
||||||
|
}
|
||||||
|
#### TODO: anonymousAllowed
|
||||||
|
else {
|
||||||
|
return $formHeader . $emailBox . $subscribeButton . $unsubscribeButton . $formFooter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub view {
|
sub view {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
@ -136,10 +170,11 @@ sub view {
|
||||||
my $issues = $self->getIssues;
|
my $issues = $self->getIssues;
|
||||||
return $output . "No issues yet" unless scalar @{ $issues };
|
return $output . "No issues yet" unless scalar @{ $issues };
|
||||||
|
|
||||||
$output .= $self->isSubscribed
|
$output .= $self->getSubscriptionForm;
|
||||||
? '<p><a href="' . $self->getUrl( 'func=unsubscribe' ) . '">Unsubscribe</a></p>'
|
# $output .= $self->isSubscribed
|
||||||
: '<p><a href="' . $self->getUrl( 'func=subscribe' ) . '">Subscribe</a></p>'
|
# ? '<p><a href="' . $self->getUrl( 'func=unsubscribe' ) . '">Unsubscribe</a></p>'
|
||||||
;
|
# : '<p><a href="' . $self->getUrl( 'func=subscribe' ) . '">Subscribe</a></p>'
|
||||||
|
# ;
|
||||||
|
|
||||||
$output .= '<p>Issues: <ul>';
|
$output .= '<p>Issues: <ul>';
|
||||||
$output .=
|
$output .=
|
||||||
|
|
@ -188,6 +223,50 @@ sub unsubscribe {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub www_processSubscription {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
my $action = $form->get( 'action' );
|
||||||
|
return unless $action eq 'subscribe' || $action eq 'unsubscribe';
|
||||||
|
|
||||||
|
if ( $session->user->isRegistered ) {
|
||||||
|
if ( $action eq 'subscribe' && $self->canSubscribe ) {
|
||||||
|
$self->subscribe;
|
||||||
|
}
|
||||||
|
if ( $action eq 'unsubscribe' && $self->canUnsubscribe ) {
|
||||||
|
$self->unsubscribe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# TODO: anonymousAllowed
|
||||||
|
else {
|
||||||
|
my $email = $form->email( 'email' );
|
||||||
|
return 'no email' unless $email;
|
||||||
|
|
||||||
|
my $emailUser = WebGUI::User::SpecialState->newByEmail( $session, $email );
|
||||||
|
if ( $action eq 'unsubscribe' && defined $emailUser ) {
|
||||||
|
$session->log->warn( 'unsub anon' );
|
||||||
|
$self->unsubscribe( $emailUser->getId );
|
||||||
|
}
|
||||||
|
if ( $action eq 'subscribe' ) {
|
||||||
|
if ( !defined $emailUser ) {
|
||||||
|
$emailUser = WebGUI::User::SpecialState->create( $session );
|
||||||
|
$emailUser->disable;
|
||||||
|
$emailUser->username( $emailUser->getId );
|
||||||
|
$emailUser->update( { email => $email } );
|
||||||
|
}
|
||||||
|
$emailUser->addSpecialState( 'Newsletter', $self->getId );
|
||||||
|
|
||||||
|
$session->log->warn( 'sub anon ' . $emailUser->username);
|
||||||
|
$self->subscribe( $emailUser->getId );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
sub www_subscribe {
|
sub www_subscribe {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
|
||||||
35
lib/WebGUI/User/SpecialState.pm
Normal file
35
lib/WebGUI/User/SpecialState.pm
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
package WebGUI::User::SpecialState;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Carp;
|
||||||
|
|
||||||
|
use base 'WebGUI::User';
|
||||||
|
|
||||||
|
sub create {
|
||||||
|
my $class = shift;
|
||||||
|
my $session = shift;
|
||||||
|
|
||||||
|
my $self = $class->SUPER::create( $session, @_ );
|
||||||
|
|
||||||
|
return $self->new( $session, $self->getId );
|
||||||
|
}
|
||||||
|
|
||||||
|
sub addSpecialState {
|
||||||
|
my $self = shift;
|
||||||
|
my $state = shift || croak 'state is required';
|
||||||
|
my $id = shift;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub removeSpecialState {
|
||||||
|
my $self = shift;
|
||||||
|
my $state = shift || croak 'state is required';
|
||||||
|
my $id = shift;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
|
|
@ -3,7 +3,12 @@ package WebGUI::i18n::English::Asset_NewsletterCollection;
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
our $I18N = {
|
our $I18N = {
|
||||||
|
'subscribe' => {
|
||||||
|
message => 'subscribe',
|
||||||
|
},
|
||||||
|
'unsubscribe' => {
|
||||||
|
message => 'unsubscribe',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue