-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
136 lines (109 loc) · 5.06 KB
/
application.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
from curses import flash
from email.mime import application
from email.mime.multipart import MIMEMultipart
from flask import Flask, redirect, render_template, url_for, request
from flask_sqlalchemy import SQLAlchemy
import urllib.parse
from sqlalchemy.orm import sessionmaker
import deploy
app = Flask(__name__)
password = urllib.parse.quote_plus("")
app.config['SQLALCHEMY_DATABASE_URI'] = f'mysql://mysqlUsername:{password}@localhost/dbname'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
Session = sessionmaker(bind=app.config['SQLALCHEMY_DATABASE_URI'])
session = Session()
db = SQLAlchemy(app)
@app.route('/')
def index():
return render_template('Login.html')
@app.route('/Login', methods=['GET', 'POST'])
def Login():
if request.method == 'POST':
userName = request.form['userName']
passwordS = request.form['password']
isOwner = db.session.execute(
"select isOwner from DemoUser where userName='" + userName + "' and password='" + passwordS + "'").all()
if not isOwner:
return ('Wrong Credentials')
elif isOwner[0][0] == 1:
return redirect(url_for('Owner'))
elif isOwner[0][0] == 0:
return redirect(url_for('Tenant'))
@app.route('/owner', methods=['POST', 'GET'])
def Owner():
cus = db.session.execute("select * from customers").all()
properties = db.session.execute('select * from Property').all()
print('oaky')
return render_template('owner.html', properties=properties)
@app.route('/tenant', methods=['POST', 'GET'])
def Tenant():
return render_template('tenant.html')
@app.route('/addTenant', methods=['POST'])
def AddTenant():
firstName = request.form['firstName']
lastName = request.form['lastName']
userName = request.form['userName']
password = request.form['password']
phoneNo = request.form['phoneNo']
linkedWallet = request.form['linkedWallet']
query = f'''INSERT INTO demouser(Name, userName, password, phoneNo, linkedWallet, isOwner) VALUES('{0}', '{1}', '{2}', '{3}','{4}', 0);commit;'''
query = query.format(firstName+lastName,userName,password,phoneNo,linkedWallet)
test = db.session.execute(query)
return render_template('tenant.html')
#deploy.addTenant(linkedWallet, firstName, lastName, phoneNo, rating=0, rentalPoints=0, canRent=True, lastRentPaid=0,dueAmount=0)
# query.format(name,userName,password,phoneNo,linkedWallet)
@app.route('/addOwner', methods=['POST'])
def AddOwner():
firstName = request.form['firstName']
lastName = request.form['lastName']
userName = request.form['userName']
password = request.form['password']
phoneNo = request.form['phoneNo']
linkedWallet = request.form['linkedWallet']
balance = 0
deploy.addOwner(linkedWallet, firstName, lastName, phoneNo, balance)
query = "INSERT INTO DemoUser(Name,userName,password,PhoneNo,linkedWallet,isOwner) values('{0}','{1}','{2}','{3}','{4}',1);commit;"
query = query.format(firstName + ' ' + lastName, userName, password, phoneNo, linkedWallet, balance)
test = db.session.execute(query)
# uid = db.session.execute("select max(Uid) from DemoUser where userName='"+userName+"'").all()
# propInsertQuery = "Insert into Property(Uid,Address,ApplicationNo) values('{0}','-','{1}');commit;"
# propInsertQuery = propInsertQuery.format(uid[0][0],applicationNo)
# test = db.session.execute(propInsertQuery)
# test = db.session.execute
return redirect(url_for('Owner'))
@app.route('/addProperty', methods=['POST'])
def AddProperty():
propertyId = request.form['propertyId']
linkedWallet = request.form['linkedWallet']
isCurrentlyRented = request.form['isCurrentlyRented']
if isCurrentlyRented == 'on':
isCurrentlyRented = True
else:
isCurrentlyRented = False
rent = request.form['rent']
deploy.addProperty(linkedWallet,int(propertyId),bool(isCurrentlyRented),int(rent))
propInsertQuery = "Insert into Property(propertyId,linkedWallet,isCurrentlyRented,rent) values('{0}','{1}','{2}','{3}');commit;"
propInsertQuery = propInsertQuery.format(propertyId, str(linkedWallet),int(isCurrentlyRented),str(rent))
test = db.session.execute(propInsertQuery)
return redirect(url_for('Owner'))
@app.route('/rentOut',methods = ['POST'])
def RentOut():
propertyId =request.form['propertyId']
ownerLinkedWallet = request.form['ownerLinkedWallet']
tenantLinkedWallet = request.form['tenantLinkedWallet']
startDate = request.form['startDate']
endDate = request.form['endDate']
# deploy.signAgreement(ownerLinkedWallet,tenantLinkedWallet,int(propertyId),1661599508,1661599508)
return redirect(url_for('Owner'))
@app.route('/rentClose',methods = ['POST'])
def RentClose():
propertyId =request.form['propertyId']
cleanlinessRating = request.form['cleanlinessRating']
tenantLinkedWallet = request.form['tenantLinkedWallet']
neighbourRating = request.form['neighbourRating']
return redirect(url_for('Owner'))
@app.route('/logout')
def Logout():
return render_template('Login.html')
if __name__ == "__main__":
app.run(debug=False)