text: from flask import flash, redirect, render_template, url_for
  from flask_login import current_user, login_user, logout_user
  
  from app import db
  from app.auth import bp
  from app.auth.forms import LoginForm, RegistrationForm
  from app.models import User
  
  
  @bp.route("/login", methods=["GET", "POST"])
  def login():
      if current_user.is_authenticated:
          return redirect(url_for("main.pitches"))
  
      form = LoginForm()
      if form.validate_on_submit():
          user = User.query.filter_by(username=form.username.data).first()
          if user is None or not user.verify_password(form.password.data):
              flash("Invalid username or password")
              return redirect(url_for("auth.login"))
  
          login_user(user, remember=form.remember_me.data)
          flash("Welcome {}".format(current_user.username))
          return redirect(url_for("main.pitches"))
  
      return render_template("auth/login.html", title="Sign In", form=form)
  
  
  @bp.route("/logout")
  def logout():
      logout_user()
      return redirect(url_for("main.pitches"))
  
  
  @bp.route("/register", methods=["GET", "POST"])
  def register():
      if current_user.is_authenticated:
          return redirect(url_for("main.pitches"))
  
      form = RegistrationForm()
      if form.validate_on_submit():
          user = User(username=form.username.data, email=form.email.data)
          user.password = form.password.data
  
          db.session.add(user)
          db.session.commit()
  
          flash("Congratulations, you are now a registered user!")
          return redirect(url_for("auth.login"))
      return render_template("auth/register.html", title="Register", form=form)
  