new registration scripts

This commit is contained in:
Enno Rehling 2002-03-17 17:13:59 +00:00
parent 5f5b5e1f09
commit d1e574877a
6 changed files with 316 additions and 20 deletions

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
import sys
import MySQLdb
import cgi
import re
# specify the filename of the template file
scripturl="http://eressea.upb.de/~enno/cgi-bin/eressea-confirm.py"
HTMLTemplate = "eressea.html"
DefaultTitle = "Eressea Anmeldung"
dbname = "eressea"
db=None
# define a new function called Display
# it takes one parameter - a string to Display
def Display(Content, Title=DefaultTitle):
TemplateHandle = open(HTMLTemplate, "r") # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle.read()
TemplateHandle.close() # close the file
# this defines an exception string in case our
# template file is messed up
BadTemplateException = "There was a problem with the HTML template."
SubResult = re.subn("<!-- INSERT TITLE HERE -->", Title, TemplateInput)
SubResult = re.subn("<!-- INSERT CONTENT HERE -->", Content, SubResult[0])
if SubResult[1] == 0:
raise BadTemplateException
print "Content-Type: text/html\n\n"
print SubResult[0]
return
def GetKey(Form, key):
if Form.has_key(key):
value=Form[key].value
if value!="":
return value
return None
def genpasswd():
newpasswd=""
chars = string.letters + string.digits
for i in range(8):
newpasswd = newpasswd + choice(chars)
return newpasswd
Form = cgi.FieldStorage()
custid=GetKey(Form, "custid")
password=GetKey(Form, "password")
if (password==None) or (custid==None):
output="<p>Um Deine Anmeldung zu bestätigen musst Du das Formular vollständig ausfüllen.\n "
for key in Form.keys():
output=output+"<br>"+str(key)+"="+str(Form[key])
Display(output)
else:
db=MySQLdb.connect(db=dbname)
cursor=db.cursor()
exist=cursor.execute("select id from users where id="+custid+" and password='"+password+"'")
if exist==0:
Display('<p>Kundennummer oder Schlüssel falsch. Bitte beachte, dass Du beim Schlüssel auf Groß- und Kleinschreibung achten mußt.')
else:
cursor.execute("update users set status='CONFIRMED' where password='"+password+"' and id="+custid)
Display("<p>Deine Anmeldung wurde bestätigt.");
db.close()

View File

@ -0,0 +1,121 @@
#!/usr/bin/env python
import sys
import MySQLdb
import cgi
import re
import string
import smtplib
from whrandom import choice
# specify the filename of the template file
scripturl="http://eressea.upb.de/~enno/cgi-bin/eressea-register.py"
HTMLTemplate = "eressea.html"
MailTemplate="register.mail"
DefaultTitle = "Eressea Anmeldung"
dbname = "eressea"
From = "accounts@eressea-pbem.de"
smtpserver = 'localhost'
db=None
# define a new function called Display
# it takes one parameter - a string to Display
def Display(Content, Title=DefaultTitle):
TemplateHandle = open(HTMLTemplate, "r") # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle.read()
TemplateHandle.close() # close the file
# this defines an exception string in case our
# template file is messed up
BadTemplateException = "There was a problem with the HTML template."
SubResult = re.subn("<!-- INSERT TITLE HERE -->", Title, TemplateInput)
SubResult = re.subn("<!-- INSERT CONTENT HERE -->", Content, SubResult[0])
if SubResult[1] == 0:
raise BadTemplateException
print "Content-Type: text/html\n\n"
print SubResult[0]
return
def Send(email, custid, firstname, password, position):
TemplateHandle = open(MailTemplate, "r") # open in read only mode
# read the entire file as a string
TemplateInput = TemplateHandle.read()
TemplateHandle.close() # close the file
SubResult = re.subn("<FIRSTNAME>", firstname, TemplateInput)
SubResult = re.subn("<PASSWORD>", password, SubResult[0])
SubResult = re.subn("<POSITION>", str(int(position)), SubResult[0])
SubResult = re.subn("<CUSTID>", str(int(custid)), SubResult[0])
Msg="From: "+From+"\nTo: "+email+"\nSubject: Vinambar Passwort\n\n"
Msg=Msg+SubResult[0]
server=smtplib.SMTP(smtpserver)
server.sendmail(From, email, Msg)
server.close()
return
def GetKey(Form, key):
if Form.has_key(key):
value=Form[key].value
if value!="":
return value
return None
def genpasswd():
newpasswd=""
chars = string.letters + string.digits
for i in range(8):
newpasswd = newpasswd + choice(chars)
return newpasswd
Form = cgi.FieldStorage()
email=GetKey(Form, "email")
firstname=GetKey(Form, "firstname")
lastname=GetKey(Form, "lastname")
info=GetKey(Form, "info")
address=GetKey(Form, "address")
city=GetKey(Form, "city")
country=GetKey(Form, "country")
phone=GetKey(Form, "phone")
race=GetKey(Form, "race")
if (lastname==None) or (race==None) or (firstname==None) or (address==None) or (city==None):
output="<p>Um Dich zu Eressea anzumelden musst Du das Formular vollständig ausfüllen.\n "
for key in Form.keys():
output=output+"<br>"+str(key)+"="+str(Form[key])
Display(output)
else:
db=MySQLdb.connect(db=dbname)
cursor=db.cursor()
exist=cursor.execute("select id from users where email='"+email+"' and (status='WAITING' or status='PENDING')")
if exist>0:
Display('<p>Du stehst bereits auf der Warteliste')
else:
password=genpasswd()
fields = "firstname, lastname, email, address, city, status, password"
values = "'"+firstname+"', '"+lastname+"', '"+email+"', '"+address+"', '"+city+"', 'WAITING', '"+password+"'"
if phone!=None:
fields=fields+", phone"
values=values+", '"+phone+"'"
if info!=None:
fields=fields+", info"
values=values+", '"+info+"'"
if country!=None:
fields=fields+", country"
values=values+", "+country+""
cursor.execute("insert into users ("+fields+") VALUES ("+values+")")
cursor.execute("SELECT LAST_INSERT_ID() from dual")
custid=cursor.fetchone()[0]
cursor.execute("insert into subscriptions (user, race, game, status) VALUES ("+str(int(custid))+", '"+race+"', 0, 'PENDING')")
cursor.execute("select count(*) from users")
Send(email, custid, firstname, password, cursor.fetchone()[0])
Display("<p>Deine Anmeldung wurde bearbeitet. Eine EMail mit Hinweisen ist unterwegs zu Dir.")
db.close()

View File

@ -0,0 +1,53 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<base href="http://www.vinyambar.de">
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta name="keywords" content="Eressea,PBeM,Postspiel">
<meta name="author" content="Enno Rehling - webmaster@vinyambar.de">
<meta name="abstract" content="Eressea">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>Eressea PBEM</title>
<link rel="stylesheet" type="text/css" href="eressea.css">
</head>
<body>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td bgcolor="#404080" align="left" valign="top">
<a href="http://www.eressea-pbem.de/"><img border="0" src="images/logo.png" alt="ERESSEA - Weltreiche und Legenden" width="500" height="91"></a>
</td>
<td bgcolor="#404080" valign="top">
<font color="#FFFFFF"><!--#echo var="DATE_LOCAL"--></font>
</td>
</tr>
</table>
<h1 align="center"><!-- INSERT TITLE HERE --></h1>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="150" valign="top">
<div class="navheader">Eressea</div>
<div class="navindex"><a href="http://www.eressea-pbem.de/">Home</a></div>
</td>
<td valign="top">
<!-- INSERT CONTENT HERE -->
</td>
<td width="150" valign="top">
<div align="center">
<a href="https://register.funcom.com/?partner=1000138917"><img src="images/athrox.png" align="top" border="0" alt="Download Anarchy Online"></a>
<br clear=all>
<a href="http://www.anarchy-online.com/content/downloads/tryout/"></a><br>
--AO Partnerprogramm--</div>
</td>
</tr>
</table>
</body>
</html>

View File

@ -85,6 +85,11 @@ def ShowInfo(custid, Password):
cursor.execute("select max(date), max(id) from transactions")
lastdate, id = cursor.fetchone()
nraces = cursor.execute("select distinct race, name from races where locale='de'")
races=[('', 'Keine Anmeldung')]
while nraces>0:
nraces = nraces - 1
races.append(cursor.fetchone())
query=("select firstname, lastname, email, address, city, country, phone, status "+
"from users "+
"where id="+str(custid)+" and password='"+Password+"' ")
@ -130,24 +135,26 @@ def ShowInfo(custid, Password):
while games>0:
games=games-1
gid, game, status, info = cursor.fetchone()
cself = db.cursor();
sub = cself.execute("select s.race from subscriptions s, users u where game="+str(int(gid))+" and u.id=s.user and u.id="+str(int(custid)))
prev=""
if sub>0:
prev=cself.fetchone()[0]
if prev==None:
prev=""
line = '<table bgcolor="#e0e0e0" width=80% border>\n<tr><th align=center><em>' + game + '</em>: ' + info + '</th></tr>'
if status=='WAITING':
line = line+'<tr><td>'
line = line + 'Ich möchte an diesem Spiel teilnehmen, und bevorzuge folgende Rasse:<br>\n'
line = line + '<select name="oldrace" size=1>'
line = line + '<OPTION selected value="">Keine Anmeldung'
line = line + '<option value="GOBLIN">Goblin'
line = line + '<option value="DWARF">Zwerg'
line = line + '<option value="ELF">Elf'
line = line + '<option value="HALFLING">Halbling'
line = line + '<option value="INSECT">Insekt'
line = line + '<option value="AQUARIAN">Meermensch'
line = line + '<option value="HUMAN">Mensch'
line = line + '<option value="CAT">Katze'
line = line + '<option value="TROLL">Troll'
line = line + '<option value="ORC">Ork'
line = line + '<option value="DEMON">Dämon'
nraces=len(races)
line = line + '<select name="race_'+str(int(gid))+'" size="1">'
while nraces>0:
nraces=nraces-1
race=races[nraces]
if prev == race[0]:
line = line + '<OPTION selected value="'+race[0]+'">'+race[1]+'\n'
else:
line = line + '<OPTION value="'+race[0]+'">'+race[1]+'\n'
line = line + '</select>'
line = line+'</td></tr>'
elif status=='RUNNING':
@ -226,6 +233,27 @@ def Save(custid, Password):
cursor=db.cursor()
cursor.execute('UPDATE users SET '+values+' where id='+str(custid))
ngames = cursor.execute("select id from games where status='WAITING'")
while ngames > 0:
ngames=ngames - 1
gid = cursor.fetchone()[0]
key="race_"+str(int(gid))
if Form.has_key(key):
update = db.cursor()
newrace=Form[key].value
if newrace=='':
newrace=None
if newrace==None:
update.execute('delete from subscriptions where user='+str(int(custid))+' and game='+str(int(gid)))
else:
exist=update.execute('select id, race from subscriptions where game='+str(int(gid))+' and user='+str(int(custid)))
if exist>0:
sid, race = update.fetchone()
if race!=newrace:
update.execute("update subscriptions set race='"+newrace+"' where id="+str(int(sid)))
else:
update.execute("insert subscriptions (race, user, status, game) values ('"+newrace+"', "+str(int(custid))+", 'WAITING', "+str(int(gid))+") where id="+str(int(sid)))
nfactions = cursor.execute("select g.name, s.id, faction from games g, subscriptions s where s.status='ACTIVE' and s.user="+str(custid) + " and s.game=g.id")
while nfactions > 0:
game, sid, faction = cursor.fetchone()

View File

@ -0,0 +1,22 @@
Hallo <FIRSTNAME>,
Du stehst mit deiner Anmeldung bei Eressea auf der Warteliste für neue Parteien
derzeit an Position <POSITION>. Um Deine Anmeldung zu bestätigen, gehe bitte
auf die folgende Webseite, und gib dort zur Bestätigung deine Kundennummer
und den Bestätigungsschlüssel ein.
http://eressea-pbem.de/confirm.html
Kundennummer: <CUSTID>
Schlüssel: <PASSWORD>
Um sicherzustellen, das nur interessierte Spieler in der Warteliste sind,
muß diese Prozedur einmal wöchentlich wiederholt werden. Du bekommst daher
wöchentlich eine Erinnerungsmail, in der Du auch deine aktuelle Position in
der Warteliste sehen kannst.
Solltest Du den Schlüssel bis Sonntag früh nicht eingegeben haben, wird
deine Anmeldung aus der Warteliste entfernt, und Du bekommst keine weiteren
Mails von uns.
Das Eressea-Team

View File

@ -48,7 +48,7 @@ def ShowPage():
lastturn, game = cursor.fetchone()
maxturn[game] = lastturn
output='<p>Um eine der folgenden Parteien zu übernehmen, musst du zuerst ein <a href="register.php">Spielerkonto anlegen</a>. Wenn Du eines hast, markiere die Partei, die Du übernehmen willst, und trage Kundennummer und Kundenpasswort ein.'
query = "SELECT g.id, g.name, s.faction, s.lastturn, s.id, r.name, s.info from games g, subscriptions s, races r where s.game=g.id and s.race=r.race and s.status='CANCELLED'"
query = "SELECT g.id, g.name, s.faction, s.lastturn, s.id, r.name, s.info from games g, subscriptions s, races r where s.game=g.id and s.race=r.race and s.status='CANCELLED' order by s.lastturn DESC"
results = cursor.execute(query)
output=output+'<div align=center><form action="'+scripturl+'" method=post><table bgcolor="#e0e0e0" width="80%" border>\n'
output=output+'<tr><th>Rasse</th><th>Spiel</th><th>NMRs</th><th>Informationen</th><th>Markieren</th></tr>'
@ -82,20 +82,20 @@ if (password!=None) & (custid!=None):
output=""
if cursor.execute("select email, id from users where password='"+password+"' and id="+str(int(custid)))==1:
email, custid = cursor.fetchone()
c = cursor.execute("SELECT id, faction from subscriptions where status='CANCELLED'")
c = cursor.execute("SELECT id, game, password, faction from subscriptions where status='CANCELLED'")
while c>0:
c=c-1
sid, faction = cursor.fetchone()
sid, gid, newpass, faction = cursor.fetchone()
if Form.has_key("accept_"+str(int(sid))):
update = db.cursor()
update.execute("UPDATE subscriptions set user=" + str(int(custid)) + ", status='ACTIVE' where id=" + str(int(sid)))
output=output+"Die Partei " + faction + " wurde Dir überschrieben. Eine Email mit dem Passwort und weiteren Hinweisen ist unterwegs zu Dir.<br>"
Msg="From: "+From+"\nTo: "+email+"\nSubject: Vinambar Parteiuebernahme\n\n"
Msg=Msg+"Das Passwort für deine neue Vinyambar-Partei "+faction+" lautet\n"
Msg=Msg+" "+password+"\n"
Msg=Msg+" "+newpass+"\n"
Msg=Msg+"\nUm den Report der letzten Woche zu erhalten, schicke eine Mail mit dem Betreff\n"
Msg=Msg+"ERESSEA REPORT "+faction+" \""+password+"\" an die Adresse "
Msg=Msg+"eressea@eressea.amber.kn-bremen.de"
Msg=Msg+"VIN"+str(int(gid))+" REPORT "+faction+" \""+newpass+"\" an die Adresse "
Msg=Msg+"vinyambar@eressea.amber.kn-bremen.de"
server=smtplib.SMTP(smtpserver)
server.sendmail(From, email, Msg)