-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
691 lines (540 loc) · 24.8 KB
/
main.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
from tkinter import *
import tkinter as tk
import mysql.connector
# import requests
HEIGHT = 700
WIDTH = 800
username_global = ""
text_msg = ''
account_number = ''
account_name = ''
account_status = ''
customer_name = ''
account_open_date = ''
account_balance = ''
f_name = ''
l_name = ''
account_name_file = ''
account_number_file = ''
status = ''
open_date = ''
amount_file = ''
home_customer_username = ''
home_account_number = ''
home_balance = ''
class App(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
#Setup Menu
# MainMenu(self)
#Setup Frame
global HEIGHT
global WIDTH
container = tk.Canvas(self)
# container.pack()
# container = Frame(self, height='700', width='800')
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, Home, Account, Register, Fund):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, context):
frame = self.frames[context]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
base = Frame(self, bd=5)
base.place(relx=0.5, relwidth=1, relheight=1, anchor='n')
frame = Frame(base, bd=5)
frame.place(relx=0.5, rely=0.2, relwidth=0.6, relheight=0.6, anchor='n')
user_name = Label(frame, text = 'Username :-', font=('Sans', '14'), bd=5)
user_name.place(relx = 0.02, rely = 0.1, relwidth = 0.3, relheight = 0.1)
pass_word = Label(frame, text = 'Password :-', font=('Sans', '14'), bd=5)
pass_word.place(relx = 0.02, rely = 0.3, relwidth = 0.3, relheight = 0.1)
# username = StringVar()
# password = StringVar()
username_entry = Entry(frame)
username_entry.place(relx = 0.35, rely = 0.1, relwidth = 0.6, relheight = 0.1)
password_entry = Entry(frame, show="*")
password_entry.place(relx = 0.35, rely = 0.3, relwidth = 0.6, relheight = 0.1)
# global username
# username = self.username_entry.get()
# print(username)
# print('qwe')
login = Button(frame, text="Login", font=('Sans', '12'), bd=3, command=lambda:user_login(username_entry.get(), password_entry.get(), controller))
login.place(relx = 0.3, rely = 0.65, relwidth = 0.4, relheight = 0.1)
global text_msg
text_msg = Label(frame)
text_msg.place(rely=0.5, relx=0.4)
register = Button(frame, text="Register", font=('Sans', '12'), bd=3, command=lambda:controller.show_frame(Register))
register.place(relx = 0.3, rely = 0.8, relwidth = 0.4, relheight = 0.1)
def user_login(username, password, controller):
# print(username, password)
global username_global
username_global = username
# username_global = self.username_entry.get()
# print(username_global + ' gl')
# self.username_entry.delete(0, END)
# self.password_entry.delete(0, END)
global text_msg
mydb = mysql.connector.connect(host="remotemysql.com", user="HtVCfBRiAp", passwd="aahR8EPevy", database="HtVCfBRiAp")
mycursor = mydb.cursor()
query = "select * from login where username = '" + username + "'"
mycursor.execute(query)
myresult = mycursor.fetchone()
rows = mycursor.rowcount
print(rows)
if rows > 0 :
user_pass = myresult[1]
if user_pass == password:
controller.show_frame(Home)
else:
text_msg.config(text="Invalid Password ", fg="red")
# self.password_not_recognised()
else:
text_msg.config(text="User Not Found", fg="red")
# self.user_not_found()
mycursor.close()
mydb.close()
update(controller)
#-----------BOTO3--------------------------------
# import boto3
# s3_resource = boto3.resource('s3')
# s3_resource.meta.client.upload_file(Filename='C:/Users/hash-include/Documents/GitHub/banking-system/index.py', Bucket='jigyasa-files', Key='index.py')
#
#----------------BOTO-------------------------------
# import boto
# import boto.s3.connection
# access_key = 'AKIAJMI2PGLHYSBHUL7A'
# secret_key = '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'
#
# conn = boto.connect_s3(
# aws_access_key_id = access_key,
# aws_secret_access_key = secret_key,
# # host = 'objects.dreamhost.com',
# # #is_secure=False, # uncomment if you are not using ssl
# calling_format = boto.s3.connection.OrdinaryCallingFormat(),
# )
# #---------LISTING OWNED BUCKETS-------------------
# for bucket in conn.get_all_buckets():
# print ("%s \t %s" %(bucket.name, bucket.creation_date))
#
# # ------------LISTING A BUCKET’S CONTENT--------------
# for key in bucket.list():
# print ("%s \t %s \t %s" %(key.name, key.size, key.last_modified))
# def password_not_recognised(self):
# global password_not_recog_screen
# password_not_recog_screen = Toplevel(root)
# password_not_recog_screen.title("Success")
# password_not_recog_screen.geometry("150x100")
# Label(password_not_recog_screen, text="Invalid Password ").pack()
# Button(password_not_recog_screen, text="OK", command=self.delete_password_not_recognised).pack()
#
# def user_not_found(self):
# global user_not_found_screen
# user_not_found_screen = Toplevel(root)
# user_not_found_screen.title("Success")
# user_not_found_screen.geometry("150x100")
# Label(user_not_found_screen, text="User Not Found").pack()
# Button(user_not_found_screen, text="OK", command=self.delete_user_not_found_screen).pack()
#
# def delete_password_not_recognised(self):
# password_not_recog_screen.destroy()
#
#
# def delete_user_not_found_screen(self):
# user_not_found_screen.destroy()
class Home(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
# MENU FRAME----------------------------------------------------------------------------------------------------
base = Frame(self, bd=5)
base.place(relx=0.5, relwidth=1, relheight=1, anchor='n')
frame = Frame(base, bd=5)
frame.place(relx=0.5, rely=0.025, relwidth=0.95, relheight=0.15, anchor='n')
home = Button(frame, text="Home", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Home))
home.place(relx=0, relheight=1, relwidth=0.2)
button = Button(frame, text="Accounts", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Account))
button.place(relx=0.2, relheight=1, relwidth=0.2)
home = Button(frame, text="Fund \nTransfer", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Fund))
home.place(relx=0.4, relheight=1, relwidth=0.2)
home = Button(frame, text="Update", font=('Sans', '15'), bd=5, command=lambda:update(controller))
home.place(relx=0.6, relheight=1, relwidth=0.2)
home = Button(frame, text="Logout", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(StartPage))
home.place(relx=0.8, relheight=1, relwidth=0.2)
# MENU FRAME END----------------------------------------------------------------------------------------------------
# BODY FRAME--------------------------------------------------------------------------------------------------------
lower_frame = Frame(base, bd=5)
lower_frame.place(relx=0.5, rely=0.2, relwidth=0.95, relheight=0.75, anchor='n')
account_summary = Button(lower_frame, text="Account Summary", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Account))
account_summary.place(relx=0, rely=0, relheight=0.15, relwidth=0.5)
fund_transfer = Button(lower_frame, text="Fund Transfer", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Fund))
fund_transfer.place(relx=0.5, rely=0, relheight=0.15, relwidth=0.5)
# mini_statement = Button(lower_frame, text="Mini Statement", font=('Sans', '15'), bd=5)
# mini_statement.place(relx=0, rely=0.15, relheight=0.15, relwidth=0.5)
#
# mini_pdf = Button(lower_frame, text="Download Mini\nStatement as PDF", font=('Sans', '15'), bd=5)
# mini_pdf.place(relx=0.5, rely=0.15, relheight=0.15, relwidth=0.5)
user_name = Label(lower_frame, text = 'Hello welcome to INTRIGIN Banking.', font=('Sans', '14'), bd=5)
user_name.place(relx = 0, rely = 0.35, relheight=0.1)
global home_customer_username
global home_account_number
global home_balance
home_customer_username = Label(lower_frame, text = 'Account Number :-', font=('Sans', '14'), bd=5)
home_customer_username.place(relx = 0, rely = 0.45, relheight=0.1)
home_account_number = Label(lower_frame, text = 'Account Summary :-', font=('Sans', '14'), bd=5)
home_account_number.place(relx = 0, rely = 0.55, relheight=0.1)
home_balance = Label(lower_frame, text = 'Account Summary :-', font=('Sans', '14'), bd=5)
home_balance.place(relx = 0, rely = 0.65, relheight=0.1)
# BODY FRAME END----------------------------------------------------------------------------------------------------
class Account(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
# MENU FRAME----------------------------------------------------------------------------------------------------
base = Frame(self, bd=5)
base.place(relx=0.5, relwidth=1, relheight=1, anchor='n')
frame = Frame(base, bd=5)
frame.place(relx=0.5, rely=0.025, relwidth=0.95, relheight=0.15, anchor='n')
home = Button(frame, text="Home", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Home))
home.place(relx=0, relheight=1, relwidth=0.2)
button = Button(frame, text="Accounts", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Account))
button.place(relx=0.2, relheight=1, relwidth=0.2)
home = Button(frame, text="Fund \nTransfer", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Fund))
home.place(relx=0.4, relheight=1, relwidth=0.2)
home = Button(frame, text="Update", font=('Sans', '15'), bd=5, command=lambda:update(controller))
home.place(relx=0.6, relheight=1, relwidth=0.2)
home = Button(frame, text="Logout", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(StartPage))
home.place(relx=0.8, relheight=1, relwidth=0.2)
# MENU FRAME END----------------------------------------------------------------------------------------------------
# BODY FRAME--------------------------------------------------------------------------------------------------------
lower_frame = Frame(base, bd=5)
lower_frame.place(relx=0.5, rely=0.2, relwidth=0.95, relheight=0.75, anchor='n')
global username_global
global account_number
global account_name
global account_status
global customer_name
global account_open_date
global account_balance
account_number = Label(lower_frame, text = 'Account Number :- ' , font=('Sans', '14'), bd=5)
account_number.place(relx = 0.025, rely = 0, relheight = 0.166)
account_name = Label(lower_frame, text = 'Account Name :- ' , font=('Sans', '14'), bd=5)
account_name.place(relx = 0.025, rely = 0.17, relheight = 0.166)
account_status = Label(lower_frame, text = 'Account Status :- ' , font=('Sans', '14'), bd=5)
account_status.place(relx = 0.025, rely = 0.34, relheight = 0.166)
customer_name = Label(lower_frame, text = 'Customer Name :- ' , font=('Sans', '14'), bd=5)
customer_name.place(relx = 0.025, rely = 0.51, relheight = 0.166)
account_open_date = Label(lower_frame, text = 'Account Open Date :- ' , font=('Sans', '14'), bd=5)
account_open_date.place(relx = 0.025, rely = 0.68, relheight = 0.166)
account_balance = Label(lower_frame, text = 'Account Balance :- ' , font=('Sans', '14'), bd=5)
account_balance.place(relx = 0.025, rely = 0.85, relheight = 0.166)
# BODY FRAME END----------------------------------------------------------------------------------------------------
class Fund(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
# MENU FRAME----------------------------------------------------------------------------------------------------
base = Frame(self, bd=5)
base.place(relx=0.5, relwidth=1, relheight=1, anchor='n')
frame = Frame(base, bd=5)
frame.place(relx=0.5, rely=0.025, relwidth=0.95, relheight=0.15, anchor='n')
home = Button(frame, text="Home", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Home))
home.place(relx=0, relheight=1, relwidth=0.2)
button = Button(frame, text="Accounts", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(Account))
button.place(relx=0.2, relheight=1, relwidth=0.2)
home = Button(frame, text="Fund \nTransfer", font=('Sans', '15'), bd=5)
home.place(relx=0.4, relheight=1, relwidth=0.2)
home = Button(frame, text="Update", font=('Sans', '15'), bd=5)
home.place(relx=0.6, relheight=1, relwidth=0.2)
home = Button(frame, text="Logout", font=('Sans', '15'), bd=5, command=lambda:controller.show_frame(StartPage))
home.place(relx=0.8, relheight=1, relwidth=0.2)
# MENU FRAME END----------------------------------------------------------------------------------------------------
# BODY FRAME--------------------------------------------------------------------------------------------------------
lower_frame = Frame(base, bd=5)
lower_frame.place(relx=0.5, rely=0.2, relwidth=0.95, relheight=0.75, anchor='n')
account_no = Label(lower_frame, text = 'Account Number :-', font=('Sans', '14'), bd=5)
account_no.place(relx = 0.02, rely = 0.3, relwidth = 0.3, relheight = 0.08)
amount = Label(lower_frame, text = 'Amount :-', font=('Sans', '14'), bd=5)
amount.place(relx = 0.02, rely = 0.45, relwidth = 0.3, relheight = 0.08)
account_no = Entry(lower_frame, textvariable = '')
account_no.place(relx = 0.35, rely = 0.3, relwidth = 0.6, relheight = 0.08)
amount = Entry(lower_frame, textvariable = '')
amount.place(relx = 0.35, rely = 0.45, relwidth = 0.6, relheight = 0.08)
global text_msg_fund
text_msg_fund = Label(lower_frame)
text_msg_fund.place(rely=0.65, relx=0.45)
transfer1 = Button(lower_frame, text="Transfer", font=('Sans', '12'), bd=3, command=lambda:transfer(account_no.get(), amount.get(), controller))
transfer1.place(relx = 0.3, rely = 0.8, relwidth = 0.4, relheight = 0.1)
# BODY FRAME END----------------------------------------------------------------------------------------------------
def transfer(acc_no, amnt, controller):
global text_msg_fund
text_msg_fund.config(text="", fg="red")
mydb = mysql.connector.connect(host="remotemysql.com", user="HtVCfBRiAp", passwd="aahR8EPevy", database="HtVCfBRiAp")
mycursor = mydb.cursor()
global username_global
query = "select account_no from login where username = '" + username_global + "'"
mycursor.execute(query)
from_account = mycursor.fetchone()
from_account = str(from_account[0])
query = "select username from login where account_no = '" + acc_no + "'"
mycursor.execute(query)
to_username = mycursor.fetchone()
to_username = to_username[0]
import xml.etree.ElementTree as ET
import os
path_sender_trans = "users/" + username_global +"/transaction.xml"
path_receiver_trans = "users/" + to_username +"/transaction.xml"
path_sender_amt = "users/" + username_global +"/amount.xml"
path_receiver_amt = "users/" + to_username +"/amount.xml"
sender_lock = "users/" + username_global +"/file.lock"
receiver_lock = "users/" + to_username +"/file.lock"
# create the file structure sender
tree = ET.parse(path_sender_trans)
data = tree.getroot()
# statement = data.find('statement')
statement = ET.SubElement(data, 'statement')
from_account_no = ET.SubElement(statement, 'from_account_no')
to_account_no = ET.SubElement(statement, 'to_account_no')
amount = ET.SubElement(statement, 'amount')
type = ET.SubElement(statement, 'type')
from_account_no.text = from_account
to_account_no.text = acc_no
amount.text = amnt
type.text = "Debited"
# create a new XML string with the results sender
mydata_sender_trans = ET.tostring(data).decode()
# create the file structure sender
tree = ET.parse(path_receiver_trans)
data = tree.getroot()
# statement = data.find('statement')
statement = ET.SubElement(data, 'statement')
from_account_no = ET.SubElement(statement, 'from_account_no')
to_account_no = ET.SubElement(statement, 'to_account_no')
amount = ET.SubElement(statement, 'amount')
type = ET.SubElement(statement, 'type')
from_account_no.text = from_account
to_account_no.text = acc_no
amount.text = amnt
type.text = "Credited"
# create a new XML string with the results receiver
mydata_receiver_trans = ET.tostring(data).decode()
tree = ET.parse(path_sender_amt)
data = tree.getroot()
sender_amt = float(data[0].text)
print(sender_amt)
tree = ET.parse(path_receiver_amt)
data = tree.getroot()
receiver_amt = float(data[0].text)
print(receiver_amt)
amnt = float(amnt)
if(sender_amt >= amnt):
sender_amt = sender_amt - amnt
receiver_amt = receiver_amt + amnt
data = ET.Element('data')
amount = ET.SubElement(data, 'amount')
amount.text = str(sender_amt)
mydata_sender_amt = ET.tostring(data).decode()
data = ET.Element('data')
amount = ET.SubElement(data, 'amount')
amount.text = str(receiver_amt)
mydata_receiver_amt = ET.tostring(data).decode()
#-----------------File Locking---------------------------
from lockfile import LockFile
lock = LockFile(sender_lock)
lock2 = LockFile(receiver_lock)
print(lock)
print(lock2)
try:
lock.acquire(timeout=10)
lock2.acquire(timeout=10)
#-----------File handling sender------------------------
open(path_sender_trans, "w").write(mydata_sender_trans)
open(path_sender_amt, "w").write(mydata_sender_amt)
#-------------------------------------------------------
#-----------File handling receiver------------------------
open(path_receiver_trans, "w").write(mydata_receiver_trans)
open(path_receiver_amt, "w").write(mydata_receiver_amt)
#---------------------------------------------------------
lock.release()
lock2.release()
text_msg_fund.config(text="Money sent", fg="red")
except:
text_msg_fund.config(text="Server timeout ", fg="red")
print("lock failed")
else:
text_msg_fund.config(text="Insufficient Amount ", fg="red")
print("Insufficient amount")
update(controller)
def update(controller):
global username_global
global account_number
global account_name
global account_status
global customer_name
global account_open_date
global account_balance
global home_customer_username
global home_account_number
global home_balance
global f_name
global l_name
global account_name_file
global account_number_file
global status
global open_date
global amount_file
account_number.config(text='Account Number :- ' + username_global)
import xml.etree.ElementTree as ET
path = "users/" + username_global +"/details.xml"
tree = ET.parse(path)
root = tree.getroot()
user_data = []
for elem in root:
# for subelem in elem:
user_data.append(elem.text)
username_global, f_name, l_name, account_name_file, account_number_file, status, open_date = user_data
print(user_data)
account_number.config(text='Account Number :- ' + account_number_file)
account_name.config(text='Account Name :- ' + account_name_file)
account_status.config(text='Account Status :- ' + status)
customer_name.config(text='Customer Name :- ' + f_name + " " + l_name)
account_open_date.config(text='Account Open Date :- ' + open_date)
path = "users/" + username_global +"/amount.xml"
tree = ET.parse(path)
root = tree.getroot()
amount_file = root[0].text
print(amount_file)
account_balance.config(text='Account Balance :- ' + amount_file)
home_customer_username.config(text = f_name + ' ' + l_name)
home_account_number.config(text='Account Number :- ' + account_number_file)
home_balance.config(text='Account Balance :- ' + amount_file)
class Register(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
base = Frame(self, bd=5)
base.place(relx=0.5, relwidth=1, relheight=1, anchor='n')
frame = Frame(base, bd=5)
frame.place(relx=0.5, rely=0.2, relwidth=0.6, relheight=0.6, anchor='n')
user_name = Label(frame, text = 'Username :-', font=('Sans', '14'), bd=5)
user_name.place(relx = 0.02, rely = 0, relwidth = 0.3, relheight = 0.1)
first_name = Label(frame, text = 'Firstname :-', font=('Sans', '14'), bd=5)
first_name.place(relx = 0.02, rely = 0.15, relwidth = 0.3, relheight = 0.1)
last_name = Label(frame, text = 'Lastname :-', font=('Sans', '14'), bd=5)
last_name.place(relx = 0.02, rely = 0.3, relwidth = 0.3, relheight = 0.1)
pass_word = Label(frame, text = 'Password :-', font=('Sans', '14'), bd=5)
pass_word.place(relx = 0.02, rely = 0.45, relwidth = 0.3, relheight = 0.1)
# username = StringVar()
# password = StringVar()
# firstname = StringVar()
# lastname = StringVar()
self.username_entry = Entry(frame, textvariable = '')
self.username_entry.place(relx = 0.35, rely = 0, relwidth = 0.6, relheight = 0.1)
self.firstname_entry = Entry(frame, textvariable = '')
self.firstname_entry.place(relx = 0.35, rely = 0.15, relwidth = 0.6, relheight = 0.1)
self.lastname_entry = Entry(frame, textvariable = '')
self.lastname_entry.place(relx = 0.35, rely = 0.3, relwidth = 0.6, relheight = 0.1)
self.password_entry = Entry(frame, textvariable = '', show="*")
self.password_entry.place(relx = 0.35, rely = 0.45, relwidth = 0.6, relheight = 0.1)
self.text_msg = Label(frame)
self.text_msg.place(rely=0.65, relx=0.35)
register = Button(frame, text="Register", font=('Sans', '12'), bd=3, command=lambda:self.user_register(self.username_entry.get(), self.password_entry.get(), self.firstname_entry.get(), self.lastname_entry.get(), controller))
register.place(relx = 0.3, rely = 0.8, relwidth = 0.4, relheight = 0.1)
def user_register(self, username, password, firstname, lastname, controller):
print(username, password, firstname, lastname)
# self.username_entry.delete(0, END)
# self.password_entry.delete(0, END)
import string
import random
if username and password and firstname and lastname:
mydb = mysql.connector.connect(host="remotemysql.com", user="HtVCfBRiAp", passwd="aahR8EPevy", database="HtVCfBRiAp")
mycursor = mydb.cursor()
acc_no = str(''.join(random.choice(string.digits) for _ in range(10)))
query = "INSERT INTO login(username, password, firstname, lastname, account_no) VALUES ('" + username + "', '" + password + "', '" + firstname + "', '" + lastname + "', '" + acc_no + "')"
try:
mycursor.execute(query)
mydb.commit()
import xml.etree.ElementTree as ET
from datetime import date
import os
size=4
chars = string.ascii_uppercase + string.digits + string.ascii_lowercase
acc_name = ''.join(random.choice(chars) for _ in range(size))
# create the file structure
data = ET.Element('data')
user_name = ET.SubElement(data, 'username')
first_name = ET.SubElement(data, 'firstname')
last_name = ET.SubElement(data, 'lastname')
account_name = ET.SubElement(data, 'account_name')
account_number = ET.SubElement(data, 'account_number')
status = ET.SubElement(data, 'status')
open_date = ET.SubElement(data, 'open_date')
user_name.text = username
first_name.text = firstname
last_name.text = lastname
account_name.text = username + acc_name
account_number.text = acc_no
status.text = 'Active'
open_date.text = str(date.today())
# create a new XML file with the results
mydata = ET.tostring(data).decode()
#-----------File handling------------------------
path = "users/" + username
try:
os.mkdir(path)
except OSError:
print ("Creation of the directory %s failed" % path)
else:
print ("Successfully created the directory %s " % path)
path = "users/" + username +"/details.xml"
print(path)
myfile = open(path, "w")
myfile.write(mydata)
#-----------------------------------------------
data = ET.Element('data')
amount = ET.SubElement(data, 'amount')
amount.text = str(0.00)
mydata = ET.tostring(data).decode()
path = "users/" + username+"/amount.xml"
print(path)
myfile = open(path, "w")
myfile.write(mydata)
#------------------------------------------------------
# -------------creating transaction file-----------------------------------------------------
data = ET.Element('data')
statement = ET.SubElement(data, 'statement')
from_account_no = ET.SubElement(statement, 'from_account_no')
to_account_no = ET.SubElement(statement, 'to_account_no')
amount = ET.SubElement(statement, 'amount')
type = ET.SubElement(statement, 'type')
from_account_no.text = ''
to_account_no.text = ''
amount.text = ''
type.text = ''
mydata = ET.tostring(data).decode()
path = "users/" + username+"/transaction.xml"
print(path)
myfile = open(path, "w")
myfile.write(mydata)
# ---------------------------------------------------------------------
path = "users/" + username+"/file.lock"
print(path)
myfile = open(path, "w")
myfile.write("lock")
myfile.close()
controller.show_frame(StartPage)
except:
self.text_msg.config(text="User Already Exists.", fg="red")
mydb.rollback()
mycursor.close()
mydb.close()
else:
self.text_msg.config(text="All Fields are Mandatory.", fg="red")
root = App()
root.geometry('700x500')
root.title('INTRIGIN Banking')
root.resizable(0, 0)
root.mainloop()