Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this is my home.html i have already define the home.html in my code #my code from flask import Flask, render_template, request, redirect, url_for,flash from Forms

this is my home.html

image text in transcribed

i have already define the home.html in my code image text in transcribed

#my code

from flask import Flask, render_template, request, redirect, url_for,flash from Forms import CreateUserForm, CreateCustomerForm, RegistrationForm, LoginForm from werkzeug.security import generate_password_hash, check_password_hash import shelve, User, Customer app = Flask(__name__, template_folder='template') app.app_context().push() app.config['SECRET_KEY'] = 'HELLO WORLD!' db = shelve.open("site.db", writeback=True) class pay(object): def __init__(self, username, email, password): self.username = username self.email = email self.password = generate_password_hash(password) def check_password(self, password): return check_password_hash(self.password, password) @app.route("/home") def home(): return render_template('home.html') @app.route("/") def index(): return redirect(url_for('login')) @app.route("/register", methods=['GET', 'POST']) def register(): form = RegistrationForm() if form.validate_on_submit(): user = pay(username=form.username.data, email=form.email.data, password=generate_password_hash(form.password.data)) if form.email.data in db: flash('Email already exists.', 'danger') return redirect(url_for('register')) db[form.email.data] = user flash('Your account has been created! You are now able to log in', 'success') return redirect(url_for('login')) return render_template('register.html', title='Register', form=form) @app.route("/login", methods=['GET', 'POST']) def login(): form = LoginForm() if form.validate_on_submit(): if form.email.data in db: user = db[form.email.data] if check_password_hash(user.password, form.password.data): flash('You have been logged in!', 'success') return redirect(url_for('home')) flash('Login Unsuccessful. Please check email and password', 'danger') return render_template('login.html', title='Login', form=form) @app.route('/createUser', methods=['GET', 'POST']) def create_user(): create_user_form = CreateUserForm(request.form) if request.method == 'POST' and create_user_form.validate(): users_dict = {} db = shelve.open('user.db', 'c') try: users_dict = db['Users'] except: print("Error in retrieving Users from user.db.") user = User.User(create_user_form.first_name.data, create_user_form.last_name.data, create_user_form.gender.data,) users_dict[user.get_user_id()] = user db['Users'] = users_dict db.close() return redirect(url_for('home')) return render_template('createUser.html', form=create_user_form) @app.route('/createCustomer', methods=['GET', 'POST']) def create_customer(): create_customer_form = CreateCustomerForm(request.form) if request.method == 'POST' and create_customer_form.validate(): customers_dict = {} db = shelve.open('customer.db', 'c') try: customers_dict = db['Customers'] except: print("Error in retrieving Customers from customer.db.") customer = Customer.Customer(create_customer_form.first_name.data, create_customer_form.last_name.data, create_customer_form.gender.data, create_customer_form.email.data, create_customer_form.date_joined.data, create_customer_form.address.data) customers_dict[customer.get_customer_id()] = customer db['Customers'] = customers_dict db.close() return redirect(url_for('home')) return render_template('createCustomer.html', form=create_customer_form) @app.route('/retrieveUsers') def retrieve_users(): users_dict = {} db = shelve.open('user.db', 'r') users_dict = db['Users'] db.close() users_list = [] for key in users_dict: user = users_dict.get(key) users_list.append(user) return render_template('retrieveUsers.html', count=len(users_list), users_list=users_list) @app.route('/retrieveCustomers') def retrieve_customers(): customers_dict = {} db = shelve.open('customer.db', 'r') customers_dict = db['Customers'] db.close() customers_list = [] for key in customers_dict: customer = customers_dict.get(key) customers_list.append(customer) return render_template('retrieveCustomers.html', count=len(customers_list), customers_list=customers_list) @app.route('/updateUser//', methods=['GET', 'POST']) def update_user(id): update_user_form = CreateUserForm(request.form) if request.method == 'POST' and update_user_form.validate(): users_dict = {} db = shelve.open('user.db', 'w') users_dict = db['Users'] user = users_dict.get(id) user.set_first_name(update_user_form.first_name.data) user.set_last_name(update_user_form.last_name.data) user.set_gender(update_user_form.gender.data) db['Users'] = users_dict db.close() return redirect(url_for('retrieve_users')) else: users_dict = {} db = shelve.open('user.db', 'r') users_dict = db['Users'] db.close() user = users_dict.get(id) update_user_form.first_name.data = user.get_first_name() update_user_form.last_name.data = user.get_last_name() update_user_form.gender.data = user.get_gender() return render_template('updateUser.html', form=update_user_form) @app.route('/updateCustomer//', methods=['GET', 'POST']) def update_customer(id): update_customer_form = CreateCustomerForm(request.form) if request.method == 'POST' and update_customer_form.validate(): customers_dict = {} db = shelve.open('customer.db', 'w') customers_dict = db['Customers'] customer = customers_dict.get(id) customer.set_first_name(update_customer_form.first_name.data) customer.set_last_name(update_customer_form.last_name.data) customer.set_gender(update_customer_form.gender.data) customer.set_email(update_customer_form.email.data) customer.set_date_joined(update_customer_form.date_joined.data) customer.set_address(update_customer_form.address.data) db['Customers'] = customers_dict db.close() return redirect(url_for('retrieve_customers')) else: customers_dict = {} db = shelve.open('customer.db', 'r') customers_dict = db['Customers'] db.close() customer = customers_dict.get(id) update_customer_form.first_name.data = customer.get_first_name() update_customer_form.last_name.data = customer.get_last_name() update_customer_form.gender.data = customer.get_gender() update_customer_form.email.data = customer.get_email() update_customer_form.date_joined.data = customer.get_date_joined() update_customer_form.address.data = customer.get_address() return render_template('updateCustomer.html', form=update_customer_form) @app.route('/deleteUser/', methods=['POST']) def delete_user(id): users_dict = {} db = shelve.open('user.db', 'w') users_dict = db['Users'] users_dict.pop(id) db['Users'] = users_dict db.close() return redirect(url_for('retrieve_users')) @app.route("/logout") def logout(): return redirect(url_for('login')) @app.route('/deleteCustomer/', methods=['POST']) def delete_customer(id): customers_dict = {} db = shelve.open('customer.db', 'w') customers_dict = db['Customers'] customers_dict.pop(id) db['Customers'] = customers_dict db.close() return redirect(url_for('retrieve_customers')) if __name__ == '__main__': app.run(port=4996) 

my code is supposed to register user using and registration form and using the ceated user. i can both create user and login using the created but my problem is my password the issue is when my email correct and password is wrong is still allows the login it dosent prompt any error, my flash error message is not showing up even though there is an error and also i have already define the home in the home.html help troubleshoot my code and help me

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Creating A Database In Filemaker Pro Visual QuickProject Guide

Authors: Steven A. Schwartz

1st Edition

0321321219, 978-0321321213

More Books

Students also viewed these Databases questions

Question

3 Find m PST Q P S 11x 3 5r 9 T H 3. Find mZPST. (l lx (5x-9Y

Answered: 1 week ago

Question

Evaluate the importance of the employee handbook.

Answered: 1 week ago

Question

Discuss the steps in the progressive discipline approach.

Answered: 1 week ago