cgi script kann jetzt speichern

This commit is contained in:
Enno Rehling 2002-01-02 16:39:19 +00:00
parent c23091e601
commit 5c7700b4a2
1 changed files with 27 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import re
import smtplib import smtplib
# specify the filename of the template file # specify the filename of the template file
scripturl="http://eressea.upb.de/~enno/cgi-bin/info.cgi"
TemplateFile = "vinyambar.html" TemplateFile = "vinyambar.html"
DefaultTitle = "Vinyambar Datenbank" DefaultTitle = "Vinyambar Datenbank"
dbname = "vinyambar" dbname = "vinyambar"
@ -22,7 +23,7 @@ def Display(Content, Title=DefaultTitle):
TemplateHandle.close() # close the file TemplateHandle.close() # close the file
for key in Form.keys(): for key in Form.keys():
Content=Content+"<br>"+key+"="+Form[key] Content=Content+"<br>"+str(key)+"="+str(Form[key])
# this defines an exception string in case our # this defines an exception string in case our
# template file is messed up # template file is messed up
@ -52,7 +53,7 @@ def ShowInfo(custid, Password):
results = cursor.execute(query); results = cursor.execute(query);
if results > 0: if results > 0:
output = "<div align=center>Letzte Aktualisierung: "+str(lastdate)[0:10]+"</div><form action=\"update.cgi\" method=post><div align=left><table width=80% border>\n" output = "<div align=center>Letzte Aktualisierung: "+str(lastdate)[0:10]+"</div><form action=\""+scripturl+"\" method=post><div align=left><table width=80% border>\n"
while results>0: while results>0:
results = results - 1 results = results - 1
row = cursor.fetchone() row = cursor.fetchone()
@ -107,13 +108,28 @@ def ShowInfo(custid, Password):
output=output+line output=output+line
output=output+"</table></div>" output=output+"</table></div>"
output=output+"<div align=left><input type=submit value=\"Speichern\"></div>" output=output+'<div align=left><input name="save" type="submit" value="Speichern"></div>'
output=output+'<input type="hidden" name="user" value="'+str(custid)+'"></div>'
output=output+'<input type="hidden" name="pass" value="'+Password+'"></div>'
output=output+"</form>" output=output+"</form>"
else: else:
output = "Die Kundennummer oder das angegebene Passwort sind nicht korrekt." output = "Die Kundennummer oder das angegebene Passwort sind nicht korrekt."
db.close()
Display(output, "Kundendaten #"+str(custid)) Display(output, "Kundendaten #"+str(custid))
def Save(custid, Password):
validkeys=['email','address','lastname','firstname','city','password','phone']
values='id='+str(custid)
for key in Form.keys():
if key in validkeys:
values=values+", "+key+"='"+Form[key].value+"'"
db = MySQLdb.connect(db=dbname)
cursor=db.cursor()
cursor.execute('UPDATE users SET '+values+' where id='+str(custid))
db.close()
ShowInfo(custid, Password)
# Display("Noch nicht implementiert", "Daten speichern für Kunde #"+str(custid))
def SendPass(custid): def SendPass(custid):
try: try:
db = MySQLdb.connect(db=dbname) db = MySQLdb.connect(db=dbname)
@ -127,15 +143,13 @@ def SendPass(custid):
server=smtplib.SMTP(smtpserver) server=smtplib.SMTP(smtpserver)
server.sendmail(From, email, Msg) server.sendmail(From, email, Msg)
server.close() server.close()
db.close()
Display('<div align="center">Das Passwort wurde verschickt</div>', 'Kundendaten #'+str(custid)) Display('<div align="center">Das Passwort wurde verschickt</div>', 'Kundendaten #'+str(custid))
except: except:
Display('<div align="center">Beim Versenden des Passwortes ist ein Fehler aufgetreten</div>', 'Kundendaten #'+str(custid)) Display('<div align="center">Beim Versenden des Passwortes ist ein Fehler aufgetreten</div>', 'Kundendaten #'+str(custid))
Form = cgi.FieldStorage() Form = cgi.FieldStorage()
if Form.has_key("user"):
custid = int(Form["user"].value)
if Form.has_key("user"): if Form.has_key("user"):
custid = int(Form["user"].value) custid = int(Form["user"].value)
else: else:
@ -146,7 +160,9 @@ if Form.has_key("pass"):
else: else:
Password="" Password=""
if Password!="": if Password=="":
ShowInfo(custid, Password)
else:
SendPass(custid) SendPass(custid)
elif Form.has_key("save"):
Save(custid, Password)
else:
ShowInfo(custid, Password)