From d1e574877a54e745c7473f3920e897da9ed26b7d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 17 Mar 2002 17:13:59 +0000 Subject: [PATCH] new registration scripts --- scripts/cgi-bin/eressea-confirm.py | 72 +++++++++++++++++ scripts/cgi-bin/eressea-register.py | 121 ++++++++++++++++++++++++++++ scripts/cgi-bin/eressea.html | 53 ++++++++++++ scripts/cgi-bin/info.py | 56 +++++++++---- scripts/cgi-bin/register.mail | 22 +++++ scripts/cgi-bin/standin.py | 12 +-- 6 files changed, 316 insertions(+), 20 deletions(-) create mode 100755 scripts/cgi-bin/eressea-confirm.py create mode 100755 scripts/cgi-bin/eressea-register.py create mode 100644 scripts/cgi-bin/eressea.html create mode 100644 scripts/cgi-bin/register.mail diff --git a/scripts/cgi-bin/eressea-confirm.py b/scripts/cgi-bin/eressea-confirm.py new file mode 100755 index 000000000..8f55c133c --- /dev/null +++ b/scripts/cgi-bin/eressea-confirm.py @@ -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("", Title, TemplateInput) + SubResult = re.subn("", 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="

Um Deine Anmeldung zu bestätigen musst Du das Formular vollständig ausfüllen.\n " + for key in Form.keys(): + output=output+"
"+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('

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("

Deine Anmeldung wurde bestätigt."); + db.close() diff --git a/scripts/cgi-bin/eressea-register.py b/scripts/cgi-bin/eressea-register.py new file mode 100755 index 000000000..a599c8bec --- /dev/null +++ b/scripts/cgi-bin/eressea-register.py @@ -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("", Title, TemplateInput) + SubResult = re.subn("", 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, TemplateInput) + SubResult = re.subn("", password, SubResult[0]) + SubResult = re.subn("", str(int(position)), SubResult[0]) + SubResult = re.subn("", 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="

Um Dich zu Eressea anzumelden musst Du das Formular vollständig ausfüllen.\n " + for key in Form.keys(): + output=output+"
"+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('

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("

Deine Anmeldung wurde bearbeitet. Eine EMail mit Hinweisen ist unterwegs zu Dir.") + db.close() diff --git a/scripts/cgi-bin/eressea.html b/scripts/cgi-bin/eressea.html new file mode 100644 index 000000000..7dd87d963 --- /dev/null +++ b/scripts/cgi-bin/eressea.html @@ -0,0 +1,53 @@ + + + + + + + + + + +Eressea PBEM + + + + + + + + + + +
+ ERESSEA - Weltreiche und Legenden + + +
+ + +

+ + + + + + + +
+ + + + + + + +
+ Download Anarchy Online +
+
+ --AO Partnerprogramm--
+
+ + diff --git a/scripts/cgi-bin/info.py b/scripts/cgi-bin/info.py index eb9bd3eb8..2f8b54e5b 100755 --- a/scripts/cgi-bin/info.py +++ b/scripts/cgi-bin/info.py @@ -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 = '\n' if status=='WAITING': line = line+'' 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() diff --git a/scripts/cgi-bin/register.mail b/scripts/cgi-bin/register.mail new file mode 100644 index 000000000..d910c47d4 --- /dev/null +++ b/scripts/cgi-bin/register.mail @@ -0,0 +1,22 @@ +Hallo , + +Du stehst mit deiner Anmeldung bei Eressea auf der Warteliste für neue Parteien +derzeit an 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: + Schlüssel: + +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 diff --git a/scripts/cgi-bin/standin.py b/scripts/cgi-bin/standin.py index d778e861a..9cd048a10 100755 --- a/scripts/cgi-bin/standin.py +++ b/scripts/cgi-bin/standin.py @@ -48,7 +48,7 @@ def ShowPage(): lastturn, game = cursor.fetchone() maxturn[game] = lastturn output='

Um eine der folgenden Parteien zu übernehmen, musst du zuerst ein Spielerkonto anlegen. 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+'

' + game + ': ' + info + '
' line = line + 'Ich möchte an diesem Spiel teilnehmen, und bevorzuge folgende Rasse:
\n' - line = line + '' + while nraces>0: + nraces=nraces-1 + race=races[nraces] + if prev == race[0]: + line = line + '
\n' output=output+'' @@ -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.
" 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)
RasseSpielNMRsInformationenMarkieren