25 lines
565 B
Python
25 lines
565 B
Python
#!/usr/bin/python3
|
|
|
|
import sqlite3
|
|
|
|
class Tools():
|
|
|
|
def __init__(self):
|
|
self.username = ''
|
|
|
|
#check code
|
|
def code_is_valid(self, code, db):
|
|
con = sqlite3.connect(db)
|
|
cur = con.cursor()
|
|
|
|
codes=[]
|
|
for row in cur.execute('SELECT * FROM codes WHERE valid = 1'):
|
|
codes.append(row[0])
|
|
return(bool(code in codes))
|
|
|
|
def mark_code_as_used(self, code, db):
|
|
con = sqlite3.connect(db)
|
|
cur = con.cursor()
|
|
|
|
cur.execute('''UPDATE codes SET valid=? WHERE code==?''',(0, code))
|
|
con.commit() |