source: freethepostcode.org/html/ruby/submit.rhtml @ 726

Last change on this file since 726 was 726, checked in by Dominic Hargreaves, 10 years ago

initial import

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1<html><body>
2
3<%   
4require 'cgi'
5require 'net/smtp'
6require 'dao.rb'
7include Math
8
9cgi = CGI.new
10dao = dao = OSM::Dao.instance
11
12email = cgi['email']
13lat = cgi['lat'].to_f
14lon = cgi['lon'].to_f
15postcode1 = cgi['postcode1'].upcase
16postcode2 = cgi['postcode2'].upcase
17%>
18
19Got this data: <%=email%> says that <%=postcode1%> <%=postcode2%> is at <%=lat%>, <%=lon%><br>
20
21%if lat > 65 || lat < 40.0 || lon > 2.5 || lon < -8
22  Looks like bad lat/lon values, please go back and try again.<br>
23<%
24exit
25else
26%>
27  Latitude and Longitude look reasonable :-)<br>
28%end
29
30%if dao.email_address?(email)
31  email address looks reasonable :-)<br>
32%else
33  Sorry, your email address does not look good, please go back and try again<br>
34% exit
35%end
36<%
37    if (postcode1.match(/[A-Z]\d/) ||
38    postcode1.match(/[A-Z][A-Z]\d/) ||
39    postcode1.match(/[A-Z]\d\d/) ||
40    postcode1.match(/[A-Z]\w\d\d/) ||
41    postcode1.match(/[A-Z][A-Z]\d[A-Z]/) ||
42    postcode1.match(/[A-Z]\d[A-Z]/) ) && postcode2.match(/\d[A-Z][A-Z]/) 
43%>
44  Postcode looks reasonable :-)<br>
45%else
46  Sorry, your postcode should be of one of these forms:<br>
47    <br>
48    LD DLL<br>
49    LLD DLL<br>
50    LDD DLL<br>
51    LLDD DLL<br>
52    LLDL DLL<br>
53    LDL DLL<br>
54    <br>
55    Where L is a letter and D a digit, for example SW1A 0AA matches LLDL DLL<br>'
56% exit
57%end
58<%
59confirmstring = dao.make_confirm_string
60dao.add_code email, lat, lon, postcode1, postcode2, confirmstring
61
62email = email.to_s.downcase
63
64msgstr = <<END_OF_MESSAGE
65From: webmaster <webmaster@freethepostcode.org>
66To: #{email}
67Subject: Please confirm: submitted data to freethepostcode.org
68
69Hi,
70
71Someone, hopefully you, submitted the postcode location
72
73#{postcode1} #{postcode2} -> #{lat},#{lon}
74
75to www.freethepostcode.org.
76
77We have to make sure you're really you with this confirmation email in
78case we get lawyered to death by someone. Please click the following
79link if you submitted the postcode and are happy for it to be in the
80public domain:
81
82http://www.freethepostcode.org/confirm?email=#{email}&confirmstring=#{confirmstring}
83
84If this in error, then please report abuse to webmaster@freethepostcode.org
85
86END_OF_MESSAGE
87
88Net::SMTP.start('127.0.0.1', 25) do |smtp|
89  smtp.send_message msgstr.untaint,
90  ''.untaint,
91  email.untaint
92end
93
94%>
95<br><br>You should have an email on its way to confirm that email address belongs to you. Click the confirm link in it and we are all done. Thanks!<br><br>
96<a href="http://www.freethepostcode.org/">Back to freethepostcode.org</a>
97
98</body></html>
99
Note: See TracBrowser for help on using the repository browser.