-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransfer.py
119 lines (94 loc) · 3.68 KB
/
transfer.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
#!/usr/bin/python3
#Author: Andy Garcia
import database
import os
import cgi
import html_pages
#Grabs cookie information stored in browser
cookie_dict = dict()
if "HTTP_COOKIE" in os.environ:
cookie_info = os.environ["HTTP_COOKIE"]
cookies = cookie_info.split(';')
for cookie in cookies:
cookie_split = cookie.split('=')
cookie_dict[cookie_split[0].strip()] = cookie_split[1].strip()
#Stores cookie data
CookieUsername = cookie_dict.get('username')
CookiePassword = cookie_dict.get('password')
CookieToken = cookie_dict.get('CSRFtoken')
#Grabs information from transfer_page
form = cgi.FieldStorage()
try:
Recipient = cgi.escape(form["recipient"].value)
except KeyError:
Recipient = "void"
try:
SendersAcc = cgi.escape(form["SenderAccount"].value)
except KeyError:
SendersAcc = "void"
try:
RecipientsAcc = cgi.escape(form["RecipientAccount"].value)
except KeyError:
RecipientsAcc = "void"
try:
Transfer = cgi.escape(form["transfer"].value)
except KeyError:
Transfer = "void"
#Grabs user from database
from database import UserInfo
user = UserInfo(CookieUsername)
#Validates cookies with credentials from database
from database import validCookies
if (validCookies(CookieUsername, CookiePassword, CookieToken)):
#Checks for a valid recipient
RecipientUser = UserInfo(Recipient)
#Validates form for any blank information
if RecipientUser:
if RecipientsAcc != "void":
if Transfer != "void":
if SendersAcc == "checkings":
#Checks if enough funds are in the account
if int(Transfer) <= int(user[3]):
from database import updateBalance
updateBalance(Recipient, user[0], RecipientsAcc, SendersAcc, Transfer)
from html_pages import transfersuccess_page
transfersuccess_page()
elif int(Transfer) > int(user[3]):
status = "Not enough funds!"
from html_pages import failure_page
failure_page(status)
elif SendersAcc == "savings":
#Checks if enough funds are in the account
if int(Transfer) <= int(user[4]):
from database import updateBalance
updateBalance(Recipient, user[0], RecipientsAcc, SendersAcc, Transfer)
from html_pages import transfersuccess_page
transfersuccess_page()
elif int(Transfer) > int(user[4]):
status = "Not enough funds!"
from html_pages import failure_page
failure_page(status)
#Checks sender's account box for blank information
elif SendersAcc == "void":
status = "You need to select the sender's account!"
from html_pages import failure_page
failure_page(status)
#Checks transfer box for blank information
else:
status = "You need to enter the amount to transfer!"
from html_pages import failure_page
failure_page(status)
#Checks recipient's account box for blank information
else:
status = "You need to select the recipient's account!"
from html_pages import failure_page
failure_page(status)
#Checks recipient box for blank information
else:
status = "Invalid recipient!"
from html_pages import failure_page
failure_page(status)
#Returns to login page if cookies are missing
elif (validCookies(CookieUsername, CookiePassword, CookieToken) is not True):
from html_pages import login_page
login_page()