summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorroot <root@dev.spline.de>2008-10-27 18:55:10 +0100
committerroot <root@dev.spline.de>2008-10-27 18:55:10 +0100
commit661617e90d01c6dd6f62b320c40e00712f1123c0 (patch)
tree89140df44562755ecd5267b361121b18b0da19f6
parent5179bbf9ebcbd091cd3082858a72b76fad93e086 (diff)
downloaddev-account-661617e90d01c6dd6f62b320c40e00712f1123c0.tar.gz
dev-account-661617e90d01c6dd6f62b320c40e00712f1123c0.tar.xz
dev-account-661617e90d01c6dd6f62b320c40e00712f1123c0.zip
check for valid fu-berlin.de email address
-rw-r--r--index.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/index.py b/index.py
index f6e08e1..ebb4c60 100644
--- a/index.py
+++ b/index.py
@@ -109,11 +109,57 @@ def set_random_password(req, user_id, length):
return None
+# Ditch nonsense email addresses.
+# taken from http://commandline.org.uk/python/2008/may/3/email-syntax-check/
+
+GENERIC_DOMAINS = "aero", "asia", "biz", "cat", "com", "coop", \
+ "edu", "gov", "info", "int", "jobs", "mil", "mobi", "museum", \
+ "name", "net", "org", "pro", "tel", "travel"
+
+def invalid(emailaddress, domains = GENERIC_DOMAINS):
+ """Checks for a syntactically invalid email address."""
+
+ # Email address must be 7 characters in total.
+ if len(emailaddress) < 7:
+ return True # Address too short.
+
+ # Split up email address into parts.
+ try:
+ localpart, domainname = emailaddress.rsplit('@', 1)
+ host, toplevel = domainname.rsplit('.', 1)
+ except ValueError:
+ return True # Address does not have enough parts.
+
+ # Check for Country code or Generic Domain.
+ if len(toplevel) != 2 and toplevel not in domains:
+ return True # Not a domain name.
+
+ for i in '-_.%+.':
+ localpart = localpart.replace(i, "")
+ for i in '-_.':
+ host = host.replace(i, "")
+
+ if localpart.isalnum() and host.isalnum():
+ return False # Email address is fine.
+ else:
+ return True # Email address has funny characters.
+
+
def validate_and_register(req, login, email):
# check for invalid entries
+
+ # empty login
+ if login == "":
+ return "please enter a username";
+
+ # no fu-berlin.de address
if not email.endswith('.fu-berlin.de'):
return "you did not give a &nbsp;*.fu-berlin.de address"
+ # regex checker for valid email
+ if invalid(email):
+ return "please enter a valid email address";
+
req.cursor.execute("SELECT login FROM user WHERE login = %s", (login, ))
if req.cursor.fetchone():
return "username already taken, please choose another one"