Created
May 6, 2016 22:10
-
-
Save nfarah86/dbde054e26fe6d259ce3dd5ae25e5b66 to your computer and use it in GitHub Desktop.
Processing Login Information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// omitted code | |
@app.route("/process_login", methods=["POST"]) | |
def process_login(): | |
#user should be in db, so .get | |
user_name = request.form.get("user_name") | |
password = request.form.get("password") | |
email = request.form.get("email") | |
#going to search db for user_name and password | |
user = db_session.query(User).filter_by( | |
user_name = user_name, | |
password = password).first() | |
if user: | |
#if true and user is in db | |
flash("Hurrah, system recognizes you!") | |
session["user_name"] = user.user_name | |
print user.user_name | |
session["user_id"] = user.id | |
print user.id | |
#going to access session | |
return redirect(url_for("personal_map")) | |
else: | |
#db doesn't recognize user | |
#redirect user to registration page | |
flash("Sorry, incorrect username or password!") | |
return render_template("register_user.html") | |
// omitted code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment