-
Notifications
You must be signed in to change notification settings - Fork 0
/
brmedituser.py
executable file
·178 lines (152 loc) · 4.84 KB
/
brmedituser.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/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 - Edit user")
mainWidget.setStyleSheet(STYLE_WIDGET)
said=str(int(sys.argv[1]))
san=brmSatanize(sys.argv[2])
sac=str(float(sys.argv[3]))
sam=brmSatanize(sys.argv[4])
def brmStoreUser(mw=None):
if DEBUG: print("brmStoreUser")
le=mw.findChildren(QLineEdit)
leid=str(le[-1].text())
lename=brmSatanize(le[0].text())
lecash=str(le[1].text())
lepass=hashlib.sha512(brmSatanize(le[2].text())).hexdigest()
lenewpass=hashlib.sha512(brmSatanize(le[3].text())).hexdigest()
lemail=str(le[4].text())
if lename=="":
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
if lecash=="":
lecash="0"
db=sqlite3.connect(BRMDB)
dbc=db.cursor()
# Usename already used?
dbc.execute("SELECT id FROM users WHERE name='"+lename+"';")
cname=dbc.fetchone()
if cname!=None and str(cname[0])!=leid:
db.close()
le[0].setStyleSheet(le[0].styleSheet()+STYLE_BADLE)
return
else:
le[0].setStyleSheet(le[0].styleSheet()+STYLE_OKLE)
if leid=="0": # New user?
dbc.execute("INSERT INTO users VALUES (NULL,'"+lename+"',"+lecash+","
"'"+lename+"','"+lenewpass+"','"+lemail+"');")
db.commit() # Sync required before next insert
if lecash!="0": # New credit?
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
"(SELECT id FROM users WHERE name='"+lename+"' LIMIT 1),"
"0,1,"+lecash+",0);")
else: # Existing user
dbc.execute("SELECT pass,cash FROM users WHERE id="+leid+" LIMIT 1;")
pswddb=dbc.fetchone()
if lepass!=pswddb[0] and pswddb[0]!=NULL512:
db.close()
le[2].setText("")
le[2].setStyleSheet(le[2].styleSheet()+STYLE_BADLE)
return
else:
le[2].setStyleSheet(le[2].styleSheet()+STYLE_OKLE)
if lename!="sachy_overflow": # Allow overflowers ignore the limit
if ((int(pswddb[1])<BUY_LIMIT and int(lecash)<0) or
int(pswddb[1])+int(lecash)<BUY_LIMIT):
le[1].setStyleSheet(le[1].styleSheet()+STYLE_BADLE)
db.close()
return
else:
le[1].setStyleSheet(le[1].styleSheet()+STYLE_OKLE)
if lecash!="0": # Charge/withdrawal?
dbc.execute("INSERT INTO transactions VALUES (NULL,CURRENT_TIMESTAMP,"
" "+leid+",0,1,"+lecash+",0);")
zasranypython=" " if lenewpass==NULL512 else "pass='"+lenewpass+"',"
dbc.execute("UPDATE users SET name='"+lename+"',cash=cash+("+lecash+"),"
" "+zasranypython+" code='"+lename+"', mail='"+lemail+"' "
"WHERE id="+leid+" LIMIT 1;")
db.commit()
db.close()
sys.exit(EXIT_USER)
bbox=QHBoxLayout()
bbox.addStretch(1)
brmAddButton(bbox,"Save",lambda:brmStoreUser(mainWidget))
bbox.addStretch(1)
brmAddButton(bbox,"Cancel",lambda:sys.exit(EXIT_CANCEL))
bbox.addStretch(1)
ename=QHBoxLayout()
ename.addStretch(1)
brmAddLine(ename,san,
'T',STYLE_LE,None,c=0,foc=0,w=800)
ename.addStretch(1)
ecash=QHBoxLayout()
cl=QLabel("Charge credit (now "+sac+")")
cl.setStyleSheet(STYLE_TEXT)
ecash.addWidget(cl)
ecash.addStretch(1)
brmAddLine(ecash,"0","N",STYLE_LE,None,c=0,foc=0)
ecode=QHBoxLayout()
bl=QLabel("Assigned barcode")
bl.setStyleSheet(STYLE_TEXT)
ecode.addWidget(bl)
ecode.addStretch(1)
bl2=QLabel(san)
bl2.setStyleSheet(STYLE_TEXT+"margin-right:100px;")
ecode.addWidget(bl2)
epass=QHBoxLayout()
pl=QLabel("Password (if set)")
pl.setStyleSheet(STYLE_TEXT)
epass.addWidget(pl)
epass.addStretch(1)
brmAddLine(epass,"","T",STYLE_LE,None,c=0,foc=0)
enpass=QHBoxLayout()
pnl=QLabel("New password?")
pnl.setStyleSheet(STYLE_TEXT)
enpass.addWidget(pnl)
enpass.addStretch(1)
brmAddLine(enpass,"","T",STYLE_LE,None,c=0,foc=0)
email=QHBoxLayout()
pm=QLabel("Send daily reports to:")
pm.setStyleSheet(STYLE_TEXT)
email.addWidget(pm)
email.addStretch(1)
brmAddLine(email,sam,'M',STYLE_LE,None,c=0,foc=0,w=500)
hbox=QHBoxLayout()
hbox.addStretch(1)
hlp=QLabel("Fill out name for a new user or edit the existing one\n\n"
"You can 'Charge' or 'Withdraw' credit by adding/substracting the Credit\n\n"
"If you are setting the password for the 1st time, leave the upper clear\n\n"
"Fill your mail to receive daily transaction reports\n\n"
"Invalid value is indicated by red background color")
hlp.setStyleSheet(STYLE_HELP)
hbox.addWidget(hlp)
hbox.addStretch(1)
screenbox=QVBoxLayout()
brmLabelBox(screenbox,"Edit user")
screenbox.addLayout(ename)
screenbox.addLayout(ecash)
screenbox.addLayout(ecode)
screenbox.addLayout(epass)
screenbox.addLayout(enpass)
screenbox.addLayout(email)
screenbox.addStretch(1)
screenbox.addLayout(hbox)
screenbox.addStretch(3)
screenbox.addLayout(bbox)
brmAddLine(screenbox,said,'T',STYLE_HIDDEN,None)
mainWidget.setLayout(screenbox)
mainWidget.showFullScreen()
pf=mainWidget.findChildren(QLineEdit)
pf[2].setEchoMode(2) # Password masking
pf[3].setEchoMode(2)
app.exec_()
sys.exit(EXIT_CANCEL)