diff options
author | matthew <matthew> | 2008-09-10 18:06:30 +0000 |
---|---|---|
committer | matthew <matthew> | 2008-09-10 18:06:30 +0000 |
commit | 3f58bc0b7b6be8018ab2835c35b825fd9be887bb (patch) | |
tree | 23b3def658fac73e909335e6af6857b8a36bf71c | |
parent | 2d6ce634157186ab37a2af590c02f97e6923df33 (diff) |
TMS initial signup stuff.
-rw-r--r-- | conf/httpd.conf | 3 | ||||
-rw-r--r-- | db/schema.sql | 8 | ||||
-rw-r--r-- | perllib/CrossSell.pm | 43 | ||||
-rw-r--r-- | templates/emails/tms-confirm | 14 | ||||
-rwxr-xr-x | web/contact.cgi | 4 | ||||
-rwxr-xr-x | web/tms-signup.cgi | 119 |
6 files changed, 186 insertions, 5 deletions
diff --git a/conf/httpd.conf b/conf/httpd.conf index aa91e20b6..6ef555c94 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.32 2008-05-14 11:25:41 matthew Exp $ +# $Id: httpd.conf,v 1.33 2008-09-10 18:06:30 matthew Exp $ DirectoryIndex index.cgi @@ -40,6 +40,7 @@ RewriteRule ^/[Pp]/([0-9A-Za-z]{16,18}).*$ /confirm.cgi?type=problem;token=$1 RewriteRule ^/[Qq]/([0-9A-Za-z]{16,18}).*$ /questionnaire.cgi?token=$1 RewriteRule ^/[Ff]/([0-9A-Za-z]{16,18}).*$ /flickr.cgi?token=$1 RewriteRule ^/[Ll]/([0-9A-Za-z]{16,18}).*$ /flickr2.cgi?token=$1 +RewriteRule ^/[Tt]/([0-9A-Za-z]{16,18}).*$ /tms-signup.cgi?token=$1 # RSS feeds for updates on a problem RewriteRule ^/rss/([0-9]+)$ /rss.cgi?type=new_updates;id=$1 [QSA] diff --git a/db/schema.sql b/db/schema.sql index aea5d5fb5..028eedd7d 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.39 2008-05-06 15:18:24 matthew Exp $ +-- $Id: schema.sql,v 1.40 2008-09-10 18:06:30 matthew Exp $ -- -- secret @@ -301,3 +301,9 @@ create table abuse ( ); create unique index abuse_email_idx on abuse(lower(email)); +create table textmystreet ( + name text not null, + email text not null, + postcode text not null, + mobile text not null +); diff --git a/perllib/CrossSell.pm b/perllib/CrossSell.pm index 2faf5a6ee..14a93a838 100644 --- a/perllib/CrossSell.pm +++ b/perllib/CrossSell.pm @@ -9,7 +9,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: CrossSell.pm,v 1.11 2008-03-13 12:40:10 matthew Exp $ +# $Id: CrossSell.pm,v 1.12 2008-09-10 18:06:30 matthew Exp $ # Config parameters site needs set to call these functions: # OPTION_AUTH_SHARED_SECRET @@ -110,6 +110,38 @@ EOF return ($out, "cheltenhamhfyc$rand"); } +sub display_tms_form { + my (%input) = @_; + my %input_h = map { $_ => $input{$_} ? ent($input{$_}) : '' } qw(name email postcode mobile signed_email); + my $auth_signature = $input_h{signed_email}; + return <<EOF; +<h1 style="padding-top:0.5em">Coming Soon: TextMyStreet</h1> + +<p>Exclusive to FixMyStreet users: Sign up for a <strong>brand new</strong>, not-yet-launched +service which will make it easy to send short messages to other people on <strong>your +street</strong> and just round the corner.</p> + +<p>Use it to borrow a strimmer, discuss the weather or report a <strong>lost cat</strong>.</p> + +<form action="/tms-signup" method="post"> +<input type="hidden" name="signed_email" value="$auth_signature"> +<label for="name">Name:</label> +<input type="text" name="name" id="name" value="$input_h{name}" size="30"> +<br><label for="email">Email:</label> +<input type="text" name="email" id="email" value="$input_h{email}" size="30"> +<br><label for="postcode">Postcode:</label> +<input type="text" name="postcode" id="postcode" value="$input_h{postcode}" size="11"> +<br><label for="mobile">Mobile:</label> <input type="text" name="mobile" id="mobile" value="$input_h{mobile}" size="11"> + <input type="submit" class="submit" value="Sign up"> +</form> + +<p>mySociety respects your privacy, and we'll never sell or give away your private +details. Once we launch we'll send you some emails and perhaps some texts +explaining how it works, and it'll never cost you a penny unless we explicitly +say it will. You'll be able to <strong>unsubscribe</strong> at any time.</p> +EOF +} + # Choose appropriate advert and display it. # $this_site is to stop a site advertising itself. sub display_advert ($$;$%) { @@ -123,6 +155,15 @@ sub display_advert ($$;$%) { } } + $q->{scratch} = 'advert=tms'; + my $auth_signature = ''; + unless (defined $data{emailunvalidated} && $data{emailunvalidated}==1) { + $auth_signature = mySociety::AuthToken::sign_with_shared_secret($email, mySociety::Config::get('AUTH_SHARED_SECRET')); + } + return '<div style="margin: 0 5em; border-top: dotted 1px #666666;">' + . display_tms_form(email => $email, name => $name, signed_email => $auth_signature) + . '</div>'; + my @adverts = ( [ 'gny0', '<h2>Are you a member of a local group…</h2> …which uses the internet to coordinate itself, such as a neighbourhood watch? If so, please help the charity that runs FixMyStreet by <a href="http://www.groupsnearyou.com/add/about/">adding some information about it</a> to our new site, GroupsNearYou.' ], [ 'gny1', '<h2>Help us build a map of the world’s local communities –<br><a href="http://www.groupsnearyou.com/add/about/">Add one to GroupsNearYou</a></h2>' ], diff --git a/templates/emails/tms-confirm b/templates/emails/tms-confirm new file mode 100644 index 000000000..e3eb5b431 --- /dev/null +++ b/templates/emails/tms-confirm @@ -0,0 +1,14 @@ +Subject: Confirm your expression of interest in TextMyStreet + +Hi, + +Please click on the link below to confirm your expression of +interest in TextMyStreet: + + <?=$values['url']?> + +If you can't click the link, please copy and paste it to the +address bar of your web browser. + +Yours, +The FixMyStreet team diff --git a/web/contact.cgi b/web/contact.cgi index 60ef48474..ce03055ae 100755 --- a/web/contact.cgi +++ b/web/contact.cgi @@ -6,7 +6,7 @@ # Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: contact.cgi,v 1.29 2008-05-14 14:24:12 matthew Exp $ +# $Id: contact.cgi,v 1.30 2008-09-10 18:06:31 matthew Exp $ use strict; use Standard; @@ -67,7 +67,7 @@ sub contact_submit { my $result = mySociety::EmailUtil::send_email($email, $input{em}, mySociety::Config::get('CONTACT_EMAIL')); if ($result == mySociety::EmailUtil::EMAIL_SUCCESS) { my $out = $q->p(_("Thanks for your feedback. We'll get back to you as soon as we can!")); - $out .= CrossSell::display_advert($q, $input{em}, $input{name}); + $out .= CrossSell::display_advert($q, $input{em}, $input{name}, { emailunvalidated=>1 } ); return $out; } else { return $q->p('Failed to send message. Please try again, or <a href="mailto:' . mySociety::Config::get('CONTACT_EMAIL') . '">email us</a>.'); diff --git a/web/tms-signup.cgi b/web/tms-signup.cgi new file mode 100755 index 000000000..2122ecbdc --- /dev/null +++ b/web/tms-signup.cgi @@ -0,0 +1,119 @@ +#!/usr/bin/perl -w -I../perllib + +# tms-signup.cgi +# Showing interest in TextMyStreet +# +# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. +# Email: matthew@mysociety.org. WWW: http://www.mysociety.org +# +# $Id: tms-signup.cgi,v 1.1 2008-09-10 18:06:31 matthew Exp $ + +use strict; +use Standard; +use Digest::SHA1 qw(sha1_hex); +use CrossSell; +use mySociety::Alert; +use mySociety::AuthToken; +use mySociety::Config; +use mySociety::EmailUtil qw(is_valid_email); +use mySociety::PostcodeUtil qw(is_valid_postcode); +use mySociety::Web qw(ent); + + #dbh()->'insert into textmystreet (name, email, postcode, mobile) values ()'; + +sub main { + my $q = shift; + my $out = ''; + my $title = 'Confirmation'; + if (my $token = $q->param('token')) { + my $data = mySociety::AuthToken::retrieve('tms', $token); + if ($data->{email}) { + $out = tms_token($q, $data); + } else { + $out = $q->p(<<EOF); +Thank you for trying to confirm your interest. 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 + } + } elsif ($q->param('email')) { + $out = tms_do_subscribe($q); + } else { + $out = tms_updates_form($q); + } + + print Page::header($q, title => $title); + print $out; + print Page::footer($q); +} +Page::do_fastcgi(\&main); + +sub tms_updates_form { + my ($q, @errors) = @_; + my @vars = qw(email name postcode mobile signed_email); + my %input = map { $_ => $q->param($_) || '' } @vars; + my $out = ''; + if (@errors) { + $out .= '<ul id="error"><li>' . join('</li><li>', @errors) . '</li></ul>'; + } + $out .= CrossSell::display_tms_form(%input); + return $out; +} + +sub tms_token { + my ($q, $data) = @_; + my $type = $data->{type}; + my $out = ''; + if ($type eq 'subscribe') { + tms_confirm(%$data); + $out = $q->p('You have successfully registered your interest.'); + } + return $out; +} + +sub tms_do_subscribe { + my ($q) = @_; + my @vars = qw(email name postcode mobile signed_email); + my %input = map { $_ => $q->param($_) || '' } @vars; + + my @errors; + push @errors, 'Please enter your name' unless $input{name}; + push @errors, 'Please enter a valid email address' unless is_valid_email($input{email}); + push @errors, 'Please enter a valid postcode' unless is_valid_postcode($input{postcode}); + push @errors, 'Please enter a mobile number' unless $input{mobile}; + if (@errors) { + return tms_updates_form($q, @errors); + } + + # See if email address has been signed + if ($input{signed_email}) { + my $out; + if (mySociety::AuthToken::verify_with_shared_secret($input{email}, mySociety::Config::get('AUTH_SHARED_SECRET'), $input{signed_email})) { + tms_confirm(%input); + $out = $q->p('You have successfully registered your interest.'); + } else { + my @errors = ('We could not validate that signature; please try again.'); + $out = tms_updates_form($q, @errors); + } + return $out; + } + + my %h = (); + $h{url} = mySociety::Config::get('BASE_URL') . '/T/' + . mySociety::AuthToken::store('tms', { + type => 'subscribe', + name => $input{name}, + email => $input{email}, + postcode => $input{postcode}, + mobile => $input{mobile}, + }); + dbh()->commit(); + return Page::send_email($q, $input{email}, $input{name}, 'tms', %h); +} + +sub tms_confirm { + my %input = @_; + dbh()->do("insert into textmystreet (name, email, postcode, mobile) values (?, ?, ?, ?)", {}, + $input{name}, $input{email}, $input{postcode}, $input{mobile}); + dbh()->commit(); +} + |