#10 Added ability for users to be removed from the site.
This commit is contained in:
@ -72,5 +72,10 @@ class UserController(DatabaseController):
|
||||
def update(self):
|
||||
print("Doing work")
|
||||
|
||||
def delete(self):
|
||||
print("Doing work")
|
||||
def delete(self, id: int):
|
||||
params = [
|
||||
id
|
||||
]
|
||||
query = """ DELETE FROM Users WHERE id = ? """
|
||||
|
||||
return self.do(query, params)
|
||||
|
@ -11,13 +11,13 @@ blueprint = Blueprint("admin", __name__, url_prefix="/admin")
|
||||
|
||||
|
||||
@blueprint.route('/')
|
||||
def main_admin():
|
||||
def main():
|
||||
""" Function responsible for delivering the admin page for the site """
|
||||
return "Hello, World"
|
||||
|
||||
|
||||
@blueprint.route('/users/')
|
||||
def admin_users():
|
||||
def users():
|
||||
""" Endpoint responsible for managing a users permissions """
|
||||
# Get all users to create admin table on frontend
|
||||
db = UserController()
|
||||
|
@ -7,6 +7,7 @@ from flask import render_template, redirect, request, session, flash
|
||||
from controllers.database.user import UserController
|
||||
from models.users.customer import Customer
|
||||
from models.users.seller import Seller
|
||||
from utils.user_utils import is_role
|
||||
from hashlib import sha512
|
||||
|
||||
# Blueprint to append user endpoints to
|
||||
@ -96,3 +97,16 @@ def logout():
|
||||
# Clear the current user from the session if they are logged in
|
||||
session.pop('user_id', None)
|
||||
return redirect("/")
|
||||
|
||||
|
||||
# DELETE USER FUNCTIONALITY
|
||||
@blueprint.post('/delete/<int:id>')
|
||||
def delete(id: int):
|
||||
""" Function responsible for deleting users from the site """
|
||||
if not is_role("Admin"):
|
||||
flash("You must be logged in an admin to remove users!", "error")
|
||||
return redirect("/")
|
||||
|
||||
db = UserController()
|
||||
db.delete(id)
|
||||
return redirect("/admin/users/")
|
||||
|
Reference in New Issue
Block a user