unsubscribe button

This commit is contained in:
Al Beano 2016-09-15 22:04:29 +01:00
parent ba4133170a
commit f16b3b0b0f
3 changed files with 32 additions and 1 deletions

View File

@ -79,7 +79,9 @@ SUB: while (my $sub = $sth->fetchrow_hashref) {
],
body => "Hi,\n\nThe Tor node with the fingerprint '"
. $sub->{"fp"} . "' " .
($status == 1 ? "is down." : "has disappeared from the Tor network!"),
($status == 1 ? "is down." : "has disappeared from the Tor network!")
. "\n\n----------\nTo unsubscribe, click this link:\n"
. $config->{"baseurl"}."/unsubscribe?id=$sub->{id}&s=$sub->{secret}",
);
my $trans = new Email::Sender::Transport::SMTPS (
host => $config->{mail}->{host},

View File

@ -166,6 +166,33 @@ while ($request->Accept() <= 0) {
$content = read_file("$Bin/confirm.tt");
}
}
case (/^\/unsubscribe\?id=[0-9]+&s=[a-z]{16}$/) {
if ($ENV{REQUEST_URI} =~ /^\/unsubscribe\?id=([0-9]+)&s=([a-z]{16})$/) {
my $id = $1;
my $secret = $2;
my $q = $dbh->prepare("select * from users where id=? and secret=?");
$q->bind_param(1, $id);
$q->bind_param(2, $secret);
$q->execute;
my $href = $q->fetchrow_hashref;
if ($q->rows != 1) {
$code = "Status: 403 Forbidden";
my $tt = read_file("$Bin/error.tt");
$content = ${ $tmpl->render($tt, {err => 403}) };
last;
}
$q->finish;
$q = $dbh->prepare("delete from users where id=? and secret=?");
$q->bind_param(1, $id);
$q->bind_param(2, $secret);
$q->execute;
$q->finish;
$content = read_file("$Bin/unsubscribe.tt");
}
}
else {
my $tt = read_file("$Bin/error.tt");
$content = ${ $tmpl->render($tt, {err => 404}) };

2
tormon/unsubscribe.tt Normal file
View File

@ -0,0 +1,2 @@
<h1>Thank you</h1>
You are no longer subscribed.