-
Notifications
You must be signed in to change notification settings - Fork 0
/
brmdon.py
executable file
·115 lines (98 loc) · 2.97 KB
/
brmdon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/python
import sys
import sqlite3
from fce import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
DEBUG=0
app=QApplication(sys.argv)
mainWidget=QWidget()
mainWidget.resize(1280,1024)
mainWidget.setWindowTitle("BrmbarSAP - Donation")
mainWidget.setStyleSheet(STYLE_WIDGET)
def brmDonate(mw=None,c=0):
if DEBUG: print("brmDonate")
les=mw.findChildren(QLineEdit)
cash=str(les[0].text())
pswd=hashlib.sha512(brmSatanize(les[1].text())).hexdigest()
code=brmSatanize(les[-1].text())
if cash=="0":
les[0].setStyleSheet(les[0].styleSheet()+STYLE_BADLE)
return
else:
les[0].setStyleSheet(les[0].styleSheet()+STYLE_OKLE)
if code=="" and c==1:
return # Accidental double-enter
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
if code!="":
dbc.execute("SELECT id,cash,pass FROM users WHERE"
" code='"+code+"' LIMIT 1;")
usr=dbc.fetchone()
if usr==None:
les[-1].setText("")
db.close()
return
if usr[1]<=BUY_LIMIT:
db.close()
sys.exit(EXIT_NOCREDIT)
if usr[2]!=pswd:
db.close()
les[1].setStyleSheet(les[1].styleSheet()+STYLE_BADLE)
return
else:
les[1].setStyleSheet(les[1].styleSheet()+STYLE_OKLE)
dbc.execute("UPDATE users SET cash=cash-"+cash+" WHERE id="+str(usr[0])+""
" LIMIT 1;")
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP"
","+str(usr[0])+",1,1,"+cash+","+cash+");")
else:
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP"
",0,1,1,"+cash+","+cash+");")
db.commit()
db.close()
sys.exit(EXIT_DONATION)
sbox=QHBoxLayout()
al=QLabel("Amount")
al.setStyleSheet(STYLE_TEXT)
sbox.addWidget(al)
sbox.addStretch(1)
brmAddLine(sbox,"0",'N0',STYLE_LE,lambda:QTimer.singleShot(0,
mainWidget.findChildren(QLineEdit)[-1],SLOT('setFocus()')),c=0)
pbox=QHBoxLayout()
pl=QLabel("User password (if set)")
pl.setStyleSheet(STYLE_TEXT)
pbox.addWidget(pl)
pbox.addStretch(1)
brmAddLine(pbox,"","T",STYLE_LE,lambda:QTimer.singleShot(0,
mainWidget.findChildren(QLineEdit)[-1],SLOT('setFocus()')),c=0)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Donate cash",lambda:brmDonate(mainWidget,0))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Set the required amount you want to donate to brmlab.\n\n"
"You can either 'Donate cash', or scan your barcode to donate credit\n\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Donation to brmlab")
screenbox.addStretch(1)
screenbox.addLayout(sbox)
screenbox.addStretch(1)
screenbox.addLayout(pbox)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
brmAddLine(screenbox,"",'T',STYLE_HIDDEN,lambda:brmDonate(mainWidget,1))
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
mainWidget.findChildren(QLineEdit)[1].setEchoMode(2) # Password masking
app.exec_()
sys.exit(EXIT_CANCEL)