1
0
Fork 0
gnuviechadmin-historic/backend/gvadm/DomainTools.py
Jan Dittberner 13b09a8844 - separated password and domain logic into package gvadm
git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@121 a67ec6bc-e5d5-0310-a910-815c51eb3124
2005-09-28 17:57:51 +00:00

30 lines
844 B
Python

#!/usr/bin/env python
import psycopg
import Settings
class InvalidDomain(Exception):
"""This Exception is thrown if an invalid domain is used."""
def __init__(self, domain):
self.domain = domain
def __str__(self):
return repr("Invalid domain %s" % (self.domain))
def validate_domain(domain):
"""This function validates whether the given domain is allowed.
That means that the domain needs to be registered in the database.
If the domain is invalid InvalidDomain is raised."""
cnx = psycopg.connect("user=%(dbuser)s password=%(dbpassword)s dbname=%(dbname)s" % Settings.dbsettings)
cr = cnx.cursor()
cr.execute("SELECT * FROM domain WHERE domainname=%(name)s" %
{'name': psycopg.QuotedString(domain)})
cnx.commit()
result = cr.fetchall()
if (not result):
raise InvalidDomain(domain)