#!/usr/bin/python3 from python.webpage_functions import print_html, get_form_data, has_form_data, print_main, get_user, set_cookie from python.htmlGenerators import viewProducts, nav from python.password import Password from python.login import tryLogIn # Either show login page or landing page if not get_user().logged_in: if has_form_data(): # Page loading with incoming form data # Try to log in with the data login_id, password = get_form_data("id"), Password(get_form_data("password")) logInCookie = tryLogIn(login_id, password) if logInCookie: # successful set_cookie(logInCookie) # print the main dashboard print_main(viewProducts.create_table_of_locations()) else: # unsuccessful - print login page with error message print_html('login.html') #### Error message? else: # No data - Print log in page print_html('login.html') else: print_main(viewProducts.create_table_of_locations())
#!/usr/bin/python3 from python.webpage_functions import print_html, get_form_data, has_form_data from python.databases.databaseQueries import select_all_with_conditions from python.htmlGenerators.qrElement import create_qr_info if has_form_data(): if get_form_data('id'): lid = get_form_data('id') info = select_all_with_conditions('products', 'id', lid)[0] print_html('print_qr.html', dict(title=info['title'], qrcode=create_qr_info(int(lid)))) else: print_html('404.html') else: print_html('404.html')
#!/usr/bin/python3 from json import dumps # Import to authenticate user, as well as form data stuff from python.webpage_functions import get_form_data, has_form_data from python.databases.databaseQueries import select_all_with_conditions output = dict() if has_form_data(): location = get_form_data('lid') row = select_all_with_conditions('locations', 'id', location) if len(row): output["name"] = row[0]['title'] print('Content-Type: text/json') print() print(dumps(output))
#!/usr/bin/python3 from python.webpage_functions import print_html, get_form_data, has_form_data, print_main, get_user from python.databases.databaseQueries import select_all_with_conditions, update_user if get_user().logged_in: if has_form_data(): user_id = get_form_data("users") updated = update_user(int(user_id), "role", "1") userForm = "" users = select_all_with_conditions("users", "role", "0") if len(users) > 0: for row in users: userForm += '<option value="%s">%s %s</option>' % ( row["id"], row["fname"], row["lname"]) else: userForm += '<option value="">None</option>' if get_user().logged_in: if has_form_data(): user_id = get_form_data("users") updated = update_user(int(user_id), "role", "1") if updated: #successful print_main("makeAdmin.html", dict(msg="Successful!", users=userForm)) else: #failed print_main("makeAdmin.html", dict(msg="Unsuccessful, try again", users=userForm)) else: print_main("makeAdmin.html", dict(msg="", users=userForm))
og = values.copy() def show_add_product(): # get_form_data might return None so switch that to '' for printing for k, v in values.items(): if not v: values[k] = '' print_main('add_product.html', values) reason = "No reason" valid = False if has_form_data(): title = get_form_data("title") location = get_form_data("location") description = get_form_data("description") date = get_form_data("date") comments = get_form_data("comments") result, new_id = addProduct(title, description, location, comments=comments, expiry_date=date) og['result'] = date if new_id == -1: new_id = '' print_main('add_product.html', {'result':result, 'id': new_id}) valid = True if not valid: show_add_product()
#!/usr/bin/python3 from python.webpage_functions import print_html, get_form_data, has_form_data, print_main, get_user from python.password import Password from python.login import register if not get_user().logged_in: if has_form_data(): # collect data fname, lname, email, pword = get_form_data("fname"), get_form_data("lname"), get_form_data("email"), Password(get_form_data("pword")) #send to db registered = register(email, str(pword), fname, lname) print(registered) # check if successfully registered if registered: ## Print "successfully registered" page print_html('redirect.html', dict(url='/index.py')) else: # print signup page #### preferably with error message print_html("signup.html") else: print_html("signup.html") else: print_html('redirect.html', dict(url='/index.py'))
#!/usr/bin/python3 from python.webpage_functions import get_form_data, has_form_data from python.addRemoveProduct import removeProduct from json import dumps output = dict(success=False, message='Error removing product') if has_form_data(): pid = get_form_data('pid') if pid is None: output['message'] = 'Error specifying pid' else: result = removeProduct(pid) if result == "Product successfully removed.": output['success'] = True output['message'] = result else: output['message'] = 'No product specified to remove' print('Content-Type: text/json') print() print(dumps(output))
} og = values.copy() def showUsers(): # get_form_data might return None so switch that to '' for printing for k, v in values.items(): if not v: values[k] = '' print_main('addUser.html', values) reason = "No reason" valid = False if has_form_data(): email = get_form_data("email") username = get_form_data("username") fname = get_form_data("fname") lname = get_form_data("lname") password = get_form_data("password") role = get_form_data("role") image = get_form_data("image") result = addUser(email,username,fname,lname,password,role,image) og['result'] = email print_main('addUser.html', {'result':result}) valid = True if not valid: showUsers()