@bp.route("<STR_LIT>", methods=("<STR_LIT:GET>", "<STR_LIT:POST>"))<EOL>def login():
if request.method == "<STR_LIT:POST>":<EOL><INDENT>username = request.form["<STR_LIT:username>"]<EOL>password = request.form["<STR_LIT:password>"]<EOL>error = None<EOL>user = User.query.filter_by(username=username).first()<EOL>if user is None:<EOL><INDENT>error = "<STR_LIT>"<EOL><DEDENT>elif not user.check_password(password):<EOL><INDENT>error = "<STR_LIT>"<EOL><DEDENT>if error is None:<EOL><INDENT>session.clear()<EOL>session["<STR_LIT>"] = user.id<EOL>return redirect(url_for("<STR_LIT:index>"))<EOL><DEDENT>flash(error)<EOL><DEDENT>return render_template("<STR_LIT>")<EOL>
Log in a registered user by adding the user id to the session.