Exemple #1
0
def deleteCatagory(cid):
    logged_in = CheckUserLoggedIn()
    if not logged_in:
        return redirect('/login')
    username = getSessionUsername()
    user_id = getSessionUserID()
    catagories = database_service.GetAllCatagory()
    picture = getSessionUserPic()
    #Check if the user is the owner of this catagory. Allow user to delete if they are the creator of it.
    if database_service.hasCatagoryPermission(cid, user_id):
        if request.method == 'POST':
            #When user clicks the Yes button, delete the catagory from our database
            database_service.DeleteCatagory(cid)
            flash('Catagory deleted!', 'alert-success')
            return redirect(url_for('IndexPage'))
        else:
            #When the page loads, load the deletecatagory.html page
            sel_catagory = database_service.GetCatagoryByID(cid)
            return render_template('deletecatagory.html',
                                   catagories=catagories,
                                   sel_catagory=sel_catagory,
                                   logged_in=logged_in,
                                   username=username,
                                   picture=picture)
    else:
        #User is NOT the owner of this catagory. Show red alert message and redirect back to product page
        flash('No permission to delete this catagory!', 'alert-danger')
        return redirect(url_for('showProducts', cid=cid))
Exemple #2
0
def editCatagory(cid):
    #Direct user to login page if not logged in. User must be logged in before modifying catagories.
    logged_in = CheckUserLoggedIn()
    if not logged_in:
        return redirect('/login')
    username = getSessionUsername()
    user_id = getSessionUserID()
    catagories = database_service.GetAllCatagory()
    picture = getSessionUserPic()
    #Check if the user is the owner of this catagory. Allow user to modify if they are the creator of it.
    if database_service.hasCatagoryPermission(cid, user_id):
        if request.method == 'POST':
            #When user clicks the submit button, updates catagory information into our database
            database_service.EditCatagory(cid, request.form['name'],
                                          request.form['desc'])
            flash('Catagory updated!', 'alert-success')
            return redirect(url_for('showProducts', cid=cid))
        else:
            #When the page loads, load the editcatagory.html page
            sel_catagory = database_service.GetCatagoryByID(cid)
            return render_template('editcatagory.html',
                                   catagories=catagories,
                                   sel_catagory=sel_catagory,
                                   logged_in=logged_in,
                                   username=username,
                                   picture=picture)
    else:
        #User is NOT the owner of this catagory. Show red alert message and redirect back to product page
        flash('No permission to modify this catagory!', 'alert-danger')
        return redirect(url_for('showProducts', cid=cid))
Exemple #3
0
def deleteCatagory(cid):
    logged_in = CheckUserLoggedIn()
    if not logged_in:
        return redirect('/login')
    username = getSessionUsername()
    user_id=getSessionUserID()
    catagories = database_service.GetAllCatagory()
    picture = getSessionUserPic()
    #Check if the user is the owner of this catagory. Allow user to delete if they are the creator of it.
    if database_service.hasCatagoryPermission(cid,user_id):
        if request.method == 'POST':
            #When user clicks the Yes button, delete the catagory from our database
            database_service.DeleteCatagory(cid)
            flash('Catagory deleted!','alert-success')
            return redirect(url_for('IndexPage'))
        else:
            #When the page loads, load the deletecatagory.html page
            sel_catagory = database_service.GetCatagoryByID(cid)
            return render_template('deletecatagory.html',catagories=catagories,sel_catagory=sel_catagory,logged_in=logged_in,username=username,picture=picture)
    else:
        #User is NOT the owner of this catagory. Show red alert message and redirect back to product page
        flash('No permission to delete this catagory!','alert-danger')
        return redirect(url_for('showProducts',cid=cid))
Exemple #4
0
def editCatagory(cid):
    #Direct user to login page if not logged in. User must be logged in before modifying catagories.
    logged_in = CheckUserLoggedIn()
    if not logged_in:
        return redirect('/login')
    username = getSessionUsername()
    user_id=getSessionUserID()
    catagories = database_service.GetAllCatagory()
    picture = getSessionUserPic()
    #Check if the user is the owner of this catagory. Allow user to modify if they are the creator of it.
    if database_service.hasCatagoryPermission(cid,user_id):
        if request.method == 'POST':
            #When user clicks the submit button, updates catagory information into our database
            database_service.EditCatagory(cid,request.form['name'],request.form['desc'])
            flash('Catagory updated!','alert-success')
            return redirect(url_for('showProducts',cid=cid))
        else:
            #When the page loads, load the editcatagory.html page
            sel_catagory = database_service.GetCatagoryByID(cid)
            return render_template('editcatagory.html',catagories=catagories,sel_catagory=sel_catagory,logged_in=logged_in,username=username,picture=picture)
    else:
        #User is NOT the owner of this catagory. Show red alert message and redirect back to product page
        flash('No permission to modify this catagory!','alert-danger')
        return redirect(url_for('showProducts',cid=cid))