commit 7a94f4a26d9a7d73210b2896f11b7e848402bf69
parent 4dba35182dfdeff2ea4be8f6a28223fdcb1a1f42
Author: rob <rob@tarina.org>
Date: Fri, 15 Oct 2021 21:36:47 +0300
much
Diffstat:
M | server.py | | | 108 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 108 insertions(+), 0 deletions(-)
diff --git a/server.py b/server.py
@@ -36,6 +36,9 @@ urls = (
"/tuning?", "tuning",
"/senaste", "senaste",
"/admin", "admin",
+ "/dorrkoder?", "dorrkoder",
+ "/nydorrkod?", "nydorrkod",
+ "/dorrkoderapi?", "dorrkoderapi",
"/register?", "register",
"/forgotpass?", "forgotpass",
"/ny", "ny",
@@ -140,6 +143,28 @@ def getbilder():
def addbild(filename, titel, namn, year, fotograf, beskrivning, uppladdare, personer):
db.insert('bilder', filename=filename, titel=titel, uploaddate=datetime.datetime.now(), namn=namn, year=year, fotograf=fotograf, beskrivning=beskrivning, uppladdare=uppladdare, personer=personer)
+def addDorrkod(dorrkod, name, mail):
+ db.insert('dorrkoder', dorrkod=dorrkod, name=name, mail=mail, datum=datetime.datetime.now())
+
+def dorrLogger(dorrkod):
+ db.insert('dorrlogger', dorrkod=dorrkod, datum=datetime.datetime.now())
+
+def getDorrlog():
+ log=db.query("SELECT * FROM dorrlogger ORDER BY datum DESC")
+ return log
+
+def getDorrkoduser(dorrkod):
+ try:
+ user = db.query("SELECT name FROM dorrkoder WHERE dorrkod='"+str(dorrkod)+"';")[0]
+ return user.name
+ except:
+ user = 'unknown'
+ return user
+
+def getDorrkoder():
+ dorrkoder=db.query("SELECT * FROM dorrkoder ORDER BY datum DESC")
+ return dorrkoder
+
def sendmail(email, subject, msg):
#Send mail
echomsg = subprocess.Popen(('echo', msg), stdout=subprocess.PIPE)
@@ -480,6 +505,89 @@ class register():
session.user = i.user
return web.seeother('/ny')
+class nydorrkod():
+ form = web.form.Form(
+ web.form.Textbox('namn', description="användarnamn:"),
+ web.form.Textbox('mail', description="e-post:"),
+ web.form.Textbox('dorrkod', description="Dörrkod:"),
+ web.form.Button('Skapa ny Dörrkod'))
+ def GET(self):
+ registerform = self.form()
+ w = web.input()
+ formfail = ''
+ n = ''
+ m = ''
+ try:
+ if w.fail == 'namn':
+ formfail = 'du måst hiitt opa eitt namn åt te!'
+ if w.fail == 'notmail':
+ formfail = 'jusså, tetär e no inga nån mejl adress.'
+ if w.fail == 'kod':
+ formfail = 'koden måst vara 4 siffror!'
+ except:
+ pass
+ if session.login == 5:
+ return render.nydorrkod(registerform, formfail)
+ else:
+ raise web.seeother('/')
+ def POST(self):
+ if session.login == 5:
+ registerform = self.form()
+ i = web.input()
+ if i.namn == '':
+ raise web.seeother('/nydorrkod?fail=namn')
+ if '@' not in i.mail:
+ raise web.seeother('/nydorrkod?fail=notmail')
+ if i.dorrkod == '':
+ dorrkod = random.randint(1111,9999)
+ elif isinstance(int(i.dorrkod), int) and len(i.dorrkod) == 4:
+ dorrkod = str(i.dorrkod)
+ else:
+ raise web.seeother('/nydorrkod?fail=kod')
+ addDorrkod(dorrkod, i.namn, i.mail.lower())
+ #Send mail to Madbaker
+ msg = "Wowowowoweeewaaa! Ny dörrkod! " + i.namn + ' ' + i.mail + ' ' + str(dorrkod)
+ sendmail('rob@bygdis.fi', 'Wowowoweewaaa!', msg)
+ #Send mail to new user
+ msg = "Gratulis " + i.namn + ", du har en dörrkod ti bygdis: " + str(dorrkod)
+ sendmail(i.mail, 'Dörrkod till Bygdegården', msg)
+ return web.seeother('/dorrkoder')
+
+class dorrkoder():
+ def GET(self):
+ if session.login == 5:
+ dorrkoder = getDorrkoder()
+ log = getDorrlog()
+ print(dorrkoder)
+ return render.dorrkoder(dorrkoder, log, getDorrkoduser)
+ else:
+ web.seeother('/')
+
+class dorrkoderapi():
+ def GET(self):
+ global basedir
+ f = open(basedir+"/apikey", "r")
+ apikey = f.readline().strip()
+ print(apikey)
+ i = web.input(apikey=None,logger=None,doorstate=None,debug=None)
+ if i.apikey == apikey:
+ if i.logger != None:
+ if len(i.logger) == 4:
+ if getDorrkoduser(i.logger) != '':
+ print('logging dorrkod!')
+ dorrLogger(i.logger)
+ elif i.doorstate != None:
+ db.update('doordebug', where='id="1"', doorstate=i.doorstate, debug=i.debug, datum=datetime.datetime.now())
+ else:
+ dorrkoder = getDorrkoder()
+ #encoding = response.info().get_content_charset('utf8')
+ #apireq = data['icestats']['source'][1][i.req]
+ p = []
+ for i in dorrkoder:
+ p.append(i.dorrkod)
+ #print(i)
+ return json.dumps(p)
+
class ny():
def GET(self):
if session.login > 2: