| Home | TPT Notes | TPT Questions | Create Task Plan | Python Project | Logins and Accounts | CB Quiz Corrections | Study Plan |
analysis: Anyone can login into the crud part and can look at emails and phone numbers, which may be sensitive info for some. Also, there really isn’t a way to logout yet, so this would cause someone else to use someone else’s account if they just used that person’s computer.
Code Snippets:
Phone Number
def authorize(name, email, password, phone):
if is_user(email, password):
return False
else:
auth_user = Users(
name=name,
email=email,
password=password,
phone=phone,
)
auth_user.create()
return True
<tr><th><label for="phone">Phone Number</label></th></tr>
<tr><td><input type="phone" id="phone" name="phone" size="20" required></td></tr>
phone = request.form.get("phone")
Logout
@app_crud.route('/logout')
@login_required
def crud_logout():
logout()
return redirect(url_for('crud.crud_login'))
return render_template("login.html")
<div style="margin-left:10px;">
<a href = , style="color:black;">Log Out</a>
<a href = , style="color:black;">Login</a>
</div>
Password Protect a Page (search)
@app_crud.route('/search/')
@login_required
def search():
"""obtains all Users from table and loads Admin Form"""
return render_template("search.html", table=users_all())
@login_manager.unauthorized_handler
def unauthorized():
"""Redirect unauthorized users to Login page."""
return redirect(url_for('crud.crud_login'))
@app_crud.route('/login/', methods=["GET", "POST"])
def crud_login():
if request.form:
email = request.form.get("email")
password = request.form.get("password")
if login(email, password):
return redirect(url_for('crud.search'))
return render_template("login.html")
Screenshots
Phone Number
Login/Logout on navbar

login_required added to search