diff options
-rw-r--r-- | conf/general-example | 5 | ||||
-rw-r--r-- | conf/httpd.conf | 5 | ||||
-rw-r--r-- | db/schema.sql | 11 | ||||
-rw-r--r-- | perllib/Page.pm | 7 | ||||
-rw-r--r-- | templates/emails/comment-confirm | 14 | ||||
-rw-r--r-- | templates/emails/problem-confirm | 17 | ||||
-rwxr-xr-x | web/confirm.cgi | 69 | ||||
-rw-r--r-- | web/css.css | 4 | ||||
-rwxr-xr-x | web/index.cgi | 67 |
9 files changed, 182 insertions, 17 deletions
diff --git a/conf/general-example b/conf/general-example index 95cc19252..abe232331 100644 --- a/conf/general-example +++ b/conf/general-example @@ -14,7 +14,7 @@ * Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. * Email: francis@mysociety.org; WWW: http://www.mysociety.org * - * $Id: general-example,v 1.4 2006-09-22 18:19:37 francis Exp $ + * $Id: general-example,v 1.5 2006-09-25 22:59:06 matthew Exp $ * */ @@ -25,6 +25,9 @@ define('OPTION_BCI_DB_NAME', 'bci'); define('OPTION_BCI_DB_USER', 'bci'); define('OPTION_BCI_DB_PASS', ''); +define('OPTION_BASE_URL', 'http://www.example.org'); +define('OPTION_CONTACT_EMAIL', 'team@example.org'); + define('OPTION_MAPIT_URL', 'http://services.mysociety.org/mapit'); define('OPTION_TILES_URL', 'http://tilma.mysociety.org/tileserver/10k-full-london'); diff --git a/conf/httpd.conf b/conf/httpd.conf index cc5cea12a..d151abcfa 100644 --- a/conf/httpd.conf +++ b/conf/httpd.conf @@ -20,7 +20,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org # -# $Id: httpd.conf,v 1.2 2006-09-25 18:12:55 matthew Exp $ +# $Id: httpd.conf,v 1.3 2006-09-25 22:59:06 matthew Exp $ DirectoryIndex index.cgi @@ -28,6 +28,9 @@ RewriteEngine on #RewriteLog /var/log/apache/rewrite.log #RewriteLogLevel 3 +RewriteRule ^/[Cc]/([0-9A-Za-z]{16}).*$ /confirm.cgi?type=comment;token=$1 +RewriteRule ^/[Pp]/([0-9A-Za-z]{16}).*$ /confirm.cgi?type=problem;token=$1 + # CGI files can be referred without CGI RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.cgi -f RewriteRule /(.+) /$1.cgi [PT] diff --git a/db/schema.sql b/db/schema.sql index c160e2e27..0944d427f 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -4,7 +4,7 @@ -- Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. -- Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ -- --- $Id: schema.sql,v 1.7 2006-09-22 17:38:00 matthew Exp $ +-- $Id: schema.sql,v 1.8 2006-09-25 22:59:06 matthew Exp $ -- -- secret @@ -220,3 +220,12 @@ create table comment ( create index comment_problem_id_idx on comment(problem_id); create index comment_problem_id_whenposted_idx on comment(problem_id, whenposted); +-- Tokens for confirmations +create table token ( + scope text not null, + token text not null, + data bytea not null, + created timestamp not null default ms_current_timestamp(), + primary key (scope, token) +); + diff --git a/perllib/Page.pm b/perllib/Page.pm index 377d61dc3..9a3dfc0bd 100644 --- a/perllib/Page.pm +++ b/perllib/Page.pm @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: Page.pm,v 1.16 2006-09-25 18:39:54 matthew Exp $ +# $Id: Page.pm,v 1.17 2006-09-25 22:59:06 matthew Exp $ # package Page; @@ -66,10 +66,10 @@ sub header ($$%) { <html lang="en-gb"> <head> <!--[if lt IE 7.]> - <script defer type="text/javascript" src="pngfix.js"></script> + <script defer type="text/javascript" src="/pngfix.js"></script> <![endif]--> <title>${title}Neighbourhood Fix-It</title> - <style type="text/css">\@import url("css.css");</style> + <style type="text/css">\@import url("/css.css");</style> </head> <body> EOF @@ -86,6 +86,7 @@ EOF =cut sub footer { return <<EOF; +</div> <h2 class="v">Navigation</h2> <ul id="navigation"> <li><a href="/contact">Contact</a> diff --git a/templates/emails/comment-confirm b/templates/emails/comment-confirm new file mode 100644 index 000000000..6c2861410 --- /dev/null +++ b/templates/emails/comment-confirm @@ -0,0 +1,14 @@ +Subject: Confirm your comment on Neighbourhood Fix-It + +Hi <?=$values['name']?>, + +Please click on the link below to confirm the comment you just wrote: + +<?=$values['url']?> + +Your comment reads: + +<?=$values['comment']?> + +-- +The Neighbourhood Fix-It team diff --git a/templates/emails/problem-confirm b/templates/emails/problem-confirm new file mode 100644 index 000000000..2bc9e80e5 --- /dev/null +++ b/templates/emails/problem-confirm @@ -0,0 +1,17 @@ +Subject: Confirm your problem on Neighbourhood Fix-It + +Hi <?=$values['name']?>, + +Please click on the link below to confirm the problem you just +added to Neighbourhood Fix-It: + +<?=$values['url']?> + +Your problem had the title: +<?=$values['title']?> + +And details: +<?=$values['detail']?> + +-- +The Neighbourhood Fix-It team diff --git a/web/confirm.cgi b/web/confirm.cgi new file mode 100755 index 000000000..29f0b7c98 --- /dev/null +++ b/web/confirm.cgi @@ -0,0 +1,69 @@ +#!/usr/bin/perl -w + +# confirm.cgi: +# Confirmation code for Neighbourhood Fix-It +# +# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: confirm.cgi,v 1.1 2006-09-25 22:59:07 matthew Exp $ + +use strict; +require 5.8.0; + +# Horrible boilerplate to set up appropriate library paths. +use FindBin; +use lib "$FindBin::Bin/../perllib"; +use lib "$FindBin::Bin/../../perllib"; + +use Page; +use mySociety::AuthToken; +use mySociety::Config; +use mySociety::DBHandle qw(dbh select_all); + +BEGIN { + mySociety::Config::set_file("$FindBin::Bin/../conf/general"); + mySociety::DBHandle::configure( + Name => mySociety::Config::get('BCI_DB_NAME'), + User => mySociety::Config::get('BCI_DB_USER'), + Password => mySociety::Config::get('BCI_DB_PASS'), + Host => mySociety::Config::get('BCI_DB_HOST', undef), + Port => mySociety::Config::get('BCI_DB_PORT', undef) + ); +} + +sub main { + my $q = shift; + + my $out = ''; + my $token = $q->param('token'); + my $type = $q->param('type'); + my $id = mySociety::AuthToken::retrieve($type, $token); + if ($id) { + if ($type eq 'comment') { + dbh()->do("update comment set state='confirmed' where id=?", {}, $id); + my $id = dbh()->selectrow_array("select problem_id from comment where id=?", {}, $id); + $out = <<EOF; +<p>You have successfully confirmed your comment and you can now <a href="/?id=$id">view it on the site</a>.</p> +EOF + } elsif ($type eq 'problem') { + dbh()->do("update problem set state='confirmed' where id=?", {}, $id); + $out = <<EOF; +<p>You have successfully confirmed your problem and you can now <a href="/?id=$id">view it on the site</a>.</p> +EOF + } + dbh()->commit(); + } else { + $out = <<EOF; +<p>Thank you for trying to confirm your comment or problem. We seem to have a +problem ourselves though, so <a href="/contact">please let us know what went on</a> +and we'll look into it. +EOF + } + + print Page::header($q, 'Confirmation'); + print $out; + print Page::footer(); +} +Page::do_fastcgi(\&main); + diff --git a/web/css.css b/web/css.css index 742b68768..d8594d47f 100644 --- a/web/css.css +++ b/web/css.css @@ -185,3 +185,7 @@ ul#current img { position: absolute; border: none; } + +#comments div em { + border-bottom: dotted 1px #968d63; +} diff --git a/web/index.cgi b/web/index.cgi index 6570307a3..fdd670520 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -6,7 +6,10 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: index.cgi,v 1.24 2006-09-25 18:39:54 matthew Exp $ +# $Id: index.cgi,v 1.25 2006-09-25 22:59:07 matthew Exp $ + +# TODO +# Nothing is done about the update checkboxes - not stored anywhere on anything! use strict; require 5.8.0; @@ -16,14 +19,17 @@ use FindBin; use lib "$FindBin::Bin/../perllib"; use lib "$FindBin::Bin/../../perllib"; use Error qw(:try); +use File::Slurp; use LWP::Simple; use RABX; use POSIX qw(strftime); use CGI::Carp; use Page; +use mySociety::AuthToken; use mySociety::Config; use mySociety::DBHandle qw(dbh select_all); +use mySociety::Email; use mySociety::Util; use mySociety::MaPit; use mySociety::Web qw(ent NewURL); @@ -54,8 +60,10 @@ sub main { my $out = ''; my $title = ''; if ($q->param('submit_problem')) { + $title = 'Submitting your problem'; $out = submit_problem($q); } elsif ($q->param('submit_comment')) { + $title = 'Submitting your comment'; $out = submit_comment($q); } elsif ($q->param('map')) { $title = 'Reporting a problem'; @@ -117,13 +125,30 @@ sub submit_comment { push(@errors, 'Please enter your email') unless $input{email}; return display_problem($q, @errors) if (@errors); + my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/comment-confirm"); + + my $id = dbh()->selectrow_array("select nextval('comment_id_seq');"); dbh()->do("insert into comment - (problem_id, name, email, website, text, state) - values (?, ?, ?, ?, ?, 'unconfirmed')", {}, - $input{id}, $input{name}, $input{email}, '', $input{comment}); + (id, problem_id, name, email, website, text, state) + values (?, ?, ?, ?, ?, ?, 'unconfirmed')", {}, + $id, $input{id}, $input{name}, $input{email}, '', $input{comment}); + my %h = (); + $h{comment} = $input{comment}; + $h{name} = $input{name}; + $h{url} = mySociety::Config::get('BASE_URL') . '/C/' . mySociety::AuthToken::store('comment', $id); dbh()->commit(); - # Send confirmation email + my $email = mySociety::Email::construct_email({ + _template_ => $template, + _parameters_ => \%h, + From => [mySociety::Config::get('CONTACT_EMAIL'), 'Heighbourhood Fix-It'], + To => [[$input{email}, $input{name}]], + }); + my $result = mySociety::Util::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), $input{email}); + if ($result == mySociety::Util::EMAIL_SUCCESS) { + } elsif ($result == mySociety::Util::EMAIL_SOFT_ERROR) { + } else { + } my $out = <<EOF; <h1>Nearly Done! Now check your email...</h1> @@ -147,6 +172,9 @@ sub submit_problem { push(@errors, 'Please enter your email') unless $input{email}; return display_form($q, @errors) if (@errors); + my $template = File::Slurp::read_file("$FindBin::Bin/../templates/emails/problem-confirm"); + + my $id = dbh()->selectrow_array("select nextval('problem_id_seq');"); dbh()->do("insert into problem (postcode, easting, northing, title, detail, name, email, state) values @@ -154,9 +182,24 @@ sub submit_problem { $input{pc}, $input{easting}, $input{northing}, $input{title}, $input{detail}, $input{name}, $input{email} ); + my %h = (); + $h{title} = $input{title}; + $h{detail} = $input{detail}; + $h{name} = $input{name}; + $h{url} = mySociety::Config::get('BASE_URL') . '/P/' . mySociety::AuthToken::store('problem', $id); dbh()->commit(); - # Send confirmation email + my $email = mySociety::Email::construct_email({ + _template_ => $template, + _parameters_ => \%h, + From => [mySociety::Config::get('CONTACT_EMAIL'), 'Heighbourhood Fix-It'], + To => [[$input{email}, $input{name}]], + }); + my $result = mySociety::Util::send_email($email, mySociety::Config::get('CONTACT_EMAIL'), $input{email}); + if ($result == mySociety::Util::EMAIL_SUCCESS) { + } elsif ($result == mySociety::Util::EMAIL_SOFT_ERROR) { + } else { + } my $out = <<EOF; <h1>Nearly Done! Now check your email...</h1> @@ -367,20 +410,22 @@ sub display_problem { # Display comments my $comments = select_all( - "select id, name, whenposted, text + "select id, name, extract(epoch from whenposted) as whenposted, text from comment where problem_id = ? and state='confirmed' order by whenposted desc", $input{id}); if (@$comments) { - $out .= '<h3>Comments</h3>'; + $out .= '<div id="comments"> <h3>Comments</h3>'; foreach my $row (@$comments) { - $out .= "$row->{name} $row->{text}"; + $out .= "<div><em>Posted by $row->{name} at " . prettify_epoch($row->{whenposted}) . '</em>'; + $out .= '<br>' . $row->{text} . '</div>'; } + $out .= '</div>'; } $out .= '<h3>Add Comment</h3>'; if (@errors) { $out .= '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>'; } - my $updates = $input{updates} ? ' checked' : ''; + my $updates = (!defined($q->param('updates')) || $input{updates}) ? ' checked' : ''; # XXX: Should we have website too? $out .= <<EOF; <form method="post" action="./"> @@ -450,7 +495,7 @@ EOF sub display_map_end { my ($type) = @_; - my $out = '</div></div>'; + my $out = '</div>'; $out .= '</form>' if ($type); return $out; } |