Add basic logging.
This commit is contained in:
parent
c0669627fa
commit
d4c9973c1e
2 changed files with 72 additions and 23 deletions
|
|
@ -3,6 +3,7 @@ package WebGUI::AssetAspect::Subscriber;
|
|||
use strict;
|
||||
use warnings;
|
||||
use Class::C3;
|
||||
use Carp;
|
||||
|
||||
use WebGUI::Asset::Template;
|
||||
use WebGUI::Macro;
|
||||
|
|
@ -282,33 +283,76 @@ sub sendNoMutationEmail {
|
|||
return;
|
||||
}
|
||||
|
||||
sub logConfirmation {
|
||||
my $self = shift;
|
||||
my $code = shift || return;
|
||||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
$db->write(
|
||||
' update assetAspectSubscriber_log set '
|
||||
.' confirmationIp=?, confirmationDate=?, confirmed=? where code=? and assetId=?',
|
||||
[
|
||||
$session->env->getIp,
|
||||
time(),
|
||||
1,
|
||||
$code,
|
||||
$self->getId,
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
sub logRequest {
|
||||
my $self = shift;
|
||||
my $type = shift || croak 'No type passed to logrequest';
|
||||
my $user = shift || croak 'No user passed to logRequest';
|
||||
my $code = shift;
|
||||
my $session = $self->session;
|
||||
my $db = $session->db;
|
||||
|
||||
$db->write(
|
||||
' insert into assetAspectSubscriber_log set '
|
||||
.' assetId=?, requestIp=?, requestDate=?, code=?, confirmed=?, anonymous=?, type=?, userId=?, email=?',
|
||||
[
|
||||
$self->getId,
|
||||
$session->env->getIp,
|
||||
time(),
|
||||
$code,
|
||||
0,
|
||||
$self->session->user->isVisitor,
|
||||
$type,
|
||||
$user->getId,
|
||||
$user->get('email'),
|
||||
]
|
||||
);
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
sub subscribe {
|
||||
my $self = shift;
|
||||
my $user = shift || $self->session->user;
|
||||
my $requireConfirm = shift // $self->get('alwaysConfirmSubscription');
|
||||
my $session = $self->session;
|
||||
my $db = $self->session->db;
|
||||
|
||||
if ( $requireConfirm ) {
|
||||
if ( $user->isInGroup( $self->getSubscriptionGroup->getId ) ) {
|
||||
$self->sendNoMutationEmail( $user, 'subscribe' );
|
||||
$self->logRequest( 'already_subscribed', $user );
|
||||
}
|
||||
else {
|
||||
my $code = $self->session->id->generate;
|
||||
|
||||
$db->write( 'replace into NewsletterCollection_subscriptions set assetId=?, userId=?, code=?, confirmed=?', [
|
||||
$self->getId,
|
||||
$user->getId,
|
||||
$code,
|
||||
0,
|
||||
] );
|
||||
$self->logRequest( 'subscribe', $user, $code );
|
||||
|
||||
$self->sendSubscriptionConfirmation( $user, $code );
|
||||
}
|
||||
}
|
||||
else {
|
||||
$self->getSubscriptionGroup->addUsers( [ $user->getId ] );
|
||||
$self->logRequest( 'subscribe', $user );
|
||||
}
|
||||
|
||||
return;
|
||||
|
|
@ -320,6 +364,7 @@ sub unsubscribe {
|
|||
my $user = shift || $self->session->user;
|
||||
|
||||
$self->getSubscriptionGroup->deleteUsers( [ $user->getId ] );
|
||||
$self->logRequest( 'unsubscribe', $user );
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -332,16 +377,15 @@ sub www_confirmSubscription {
|
|||
my $code = $form->get('code');
|
||||
return unless $code;
|
||||
|
||||
my $userId = $db->quickScalar( 'select userId from NewsletterCollection_subscriptions where confirmed=? and code=?', [
|
||||
my $userId = $db->quickScalar( 'select userId from assetAspectSubscriber_log where confirmed=? and code=?', [
|
||||
0,
|
||||
$code,
|
||||
] );
|
||||
# $db->write( 'update NewsletterCollection_subscriptions set confirmed=1, code=NULL where code=?', [
|
||||
# $code
|
||||
# ] );
|
||||
|
||||
if ( $userId ) {
|
||||
$self->getSubscriptionGroup->addUsers( [ $userId ] );
|
||||
|
||||
$self->logConfirmation( $code );
|
||||
}
|
||||
else {
|
||||
return $self->processStyle( 'Verkeerde code' );
|
||||
|
|
|
|||
|
|
@ -69,6 +69,22 @@ sub installSubscriberAspectTable {
|
|||
);
|
||||
EOSQL
|
||||
|
||||
$session->db->write(<<EOSQL2);
|
||||
create table if not exists assetAspectSubscriber_log (
|
||||
assetId char(22) binary not null,
|
||||
requestIp char(15) not null,
|
||||
requestDate bigint(20) not null,
|
||||
confirmationIp char(15),
|
||||
confirmationDate bigint(20),
|
||||
userId char(22) binary not null,
|
||||
email varchar(255) not null,
|
||||
type char(30) not null,
|
||||
anonymous tinyint(1) not null,
|
||||
confirmed tinyint(1) default 0,
|
||||
code char(22) default null
|
||||
);
|
||||
EOSQL2
|
||||
|
||||
print "Done.\n";
|
||||
}
|
||||
|
||||
|
|
@ -85,17 +101,6 @@ sub installNewsletterCollection {
|
|||
);
|
||||
EOSQL
|
||||
|
||||
$session->db->write(<<EOSQL2);
|
||||
create table if not exists NewsletterCollection_subscriptions (
|
||||
assetId char(22) binary not null,
|
||||
userId char(22) binary not null,
|
||||
confirmed tinyint(1) default 0,
|
||||
code char(22) default null,
|
||||
creationDate timestamp default CURRENT_TIMESTAMP,
|
||||
primary key( assetId, userId )
|
||||
);
|
||||
EOSQL2
|
||||
|
||||
print "Done.\n";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue