Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Secure smart parking solution
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-122
Secure smart parking solution
Commits
9911eec3
Commit
9911eec3
authored
Jul 06, 2021
by
kaveena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add UI Floder
parent
144fef40
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
163 additions
and
0 deletions
+163
-0
UI/connect/app.py
UI/connect/app.py
+163
-0
No files found.
UI/connect/app.py
0 → 100644
View file @
9911eec3
from
flask
import
Flask
,
render_template
,
request
,
flash
,
redirect
,
url_for
,
session
from
flask_mysqldb
import
MySQL
import
yaml
from
functools
import
wraps
from
wtforms
import
Form
,
StringField
,
validators
# TextAreaField, PasswordField, DateTimeField
app
=
Flask
(
__name__
)
db
=
yaml
.
load
(
open
(
'db.yaml'
))
app
.
config
[
'MYSQL_HOST'
]
=
db
[
'mysql_host'
]
app
.
config
[
'MYSQL_USER'
]
=
db
[
'mysql_user'
]
app
.
config
[
'MYSQL_PASSWORD'
]
=
db
[
'mysql_password'
]
app
.
config
[
'MYSQL_DB'
]
=
db
[
'mysql_db'
]
mysql
=
MySQL
(
app
)
# @app.route('/', methods=['GET', 'POST'])
# def index():
# if request.method == 'POST':
# userDetails = request.form
# name = userDetails['name']
# email = userDetails['email']
# cur = mysql.connection.cursor()
# cur.execute("INSERT INTO users(name, email) VALUES(%s, %s)", (name, email))
# mysql.connection.commit()
# cur.close()
# return 'Success'
# return render_template('index.html')
# @app.route('/users')
# def users():
# cur = mysql.connection.cursor()
# resultValue = cur.execute("SELECT * FROM users")
# if resultValue > 0:
# userDetails = cur.fetchall()
# return render_template('users.html', userDetails = userDetails)
# def Extract(lst):
# return list(list(zip(*lst))[0])
def
is_logged_in
(
f
):
@
wraps
(
f
)
def
wrap
(
*
args
,
**
kwargs
):
if
'logged_in'
in
session
:
return
f
(
*
args
,
**
kwargs
)
else
:
flash
(
'Unauthorized, Please login'
,
'danger'
)
return
redirect
(
url_for
(
'login'
))
return
wrap
class
AddTruckForm
(
Form
):
vin
=
StringField
(
'userName'
,
[
validators
.
Length
(
min
=
3
,
max
=
20
)])
location
=
StringField
(
'password'
,
[
validators
.
Length
(
min
=
3
,
max
=
20
)])
@
app
.
route
(
'/'
)
def
index
():
cur1
=
mysql
.
connection
.
cursor
()
cur2
=
mysql
.
connection
.
cursor
()
resultValue1
=
cur1
.
execute
(
"SELECT * FROM users"
)
resultValue2
=
cur2
.
execute
(
"SELECT id, type, inDate FROM users WHERE isExit = 1"
)
if
resultValue1
>
0
or
resultValue2
>
0
:
userDetails
=
cur1
.
fetchall
()
userDetails2
=
cur2
.
fetchall
()
# name = (list(list(zip(*userDetails))[0]))
# mail = (list(list(zip(*userDetails))[1]))
# userDetails = [name, mail]
# print(userDetails)
return
render_template
(
'index.html'
,
userDetails
=
userDetails
,
userDetails2
=
userDetails2
)
@
app
.
route
(
'/edit_pass'
,
methods
=
[
'GET'
,
'POST'
])
@
is_logged_in
def
edit_pass
():
session
[
'is_admin'
]
=
False
form
=
AddTruckForm
(
request
.
form
)
if
request
.
method
==
'POST'
:
if
request
.
form
[
'submit'
]
==
'Cancel'
:
return
redirect
(
url_for
(
'login'
))
# return render_template('admin.html')
elif
request
.
form
[
'submit'
]
==
'Edit'
:
# location = form.location.data
# cur = mysql.connection.cursor()
# cur.execute("""UPDATE Truck SET truckLocation='{}' WHERE VIN='{}'""".format(location, id))
# mysql.connection.commit()
# cur.close()
# flash('Truck VIN {} location has been updated to {}'.format(id, location), 'success')
return
redirect
(
url_for
(
'login'
))
return
render_template
(
'edit_pass.html'
,
form
=
form
)
@
app
.
route
(
'/edit_price'
,
methods
=
[
'GET'
,
'POST'
])
@
is_logged_in
def
edit_price
():
session
[
'is_admin'
]
=
False
form
=
AddTruckForm
(
request
.
form
)
if
request
.
method
==
'POST'
:
if
request
.
form
[
'submit'
]
==
'Cancel'
:
return
redirect
(
url_for
(
'login'
))
# return render_template('admin.html')
elif
request
.
form
[
'submit'
]
==
'Edit'
:
# location = form.location.data
# cur = mysql.connection.cursor()
# cur.execute("""UPDATE Truck SET truckLocation='{}' WHERE VIN='{}'""".format(location, id))
# mysql.connection.commit()
# cur.close()
# flash('Truck VIN {} location has been updated to {}'.format(id, location), 'success')
return
redirect
(
url_for
(
'login'
))
return
render_template
(
'edit_price.html'
,
form
=
form
)
@
app
.
route
(
'/login'
,
methods
=
[
'GET'
,
'POST'
])
def
login
():
if
request
.
method
==
'POST'
:
username_candidate
=
request
.
form
[
'username'
]
password_candidate
=
request
.
form
[
'password'
]
cur
=
mysql
.
connection
.
cursor
()
result
=
cur
.
execute
(
"""SELECT * FROM admin WHERE userName='{}'"""
.
format
(
username_candidate
))
if
result
>
0
:
data
=
cur
.
fetchone
()
username
=
data
[
0
]
password
=
data
[
1
]
if
password_candidate
==
password
:
session
[
'logged_in'
]
=
True
session
[
'username'
]
=
username
flash
(
"You are now logged in"
,
"success"
)
cur
=
mysql
.
connection
.
cursor
()
# resultValue = cur.execute("SELECT * FROM users")
resultValue
=
cur
.
execute
(
"SELECT id, type, inDate FROM users WHERE isVIP = 1"
)
if
resultValue
>
0
:
session
[
'is_admin'
]
=
True
userDetails
=
cur
.
fetchall
()
return
render_template
(
'admin.html'
,
userDetails
=
userDetails
)
else
:
error
=
'Invalid login'
return
render_template
(
'login.html'
,
error
=
error
)
cur
.
close
()
else
:
error
=
'Username not found'
return
render_template
(
'login.html'
,
error
=
error
)
return
render_template
(
'login.html'
)
@
app
.
route
(
'/logout'
)
@
is_logged_in
def
logout
():
session
.
clear
()
flash
(
'You are now logged out'
,
'success'
)
return
redirect
(
url_for
(
'index'
))
@
app
.
route
(
'/admin'
)
@
is_logged_in
def
admin
():
session
[
'is_admin'
]
=
True
cur
=
mysql
.
connection
.
cursor
()
# resultValue = cur.execute("SELECT * FROM users")
resultValue
=
cur
.
execute
(
"SELECT id, type, inDate FROM users WHERE isVIP = 1"
)
userDetails
=
cur
.
fetchall
()
return
render_template
(
'admin.html'
,
userDetails
=
userDetails
)
if
__name__
==
'__main__'
:
app
.
secret_key
=
'12'
app
.
run
(
host
=
'0.0.0.0'
,
port
=
8080
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment