title: How to setup multiple login managers in Flask?
body: <p>Is it possible to setup multiple login managers in Flask? I have 3 pages with different content that need to be password protected:</p>
  
  <pre><code>mydomain.com/page1
  mydomain.com/page2
  mydomain.com/page3
  </code></pre>
  
  <p>Anyone logged in and accessing page1 <strong>should not</strong> have access to page2 or page3 (and vice-versa).</p>
  
  <p>I guess one way is to specify <code>username</code> in my jinja2 template and show page results based on that. For example, I could add:</p>
  
  <pre><code>{% if current_user.is_authenticated and current_user.username == 'abc' %}
  &lt;!-- show HTML for user 'abc' only --&gt;
  </code></pre>
  
  <p>But using this method, page2 and page3 would still be accessible. They just wouldn't show any content because nothing would be defined for those users in the jinja2 template.</p>
  
  <p>Here's how I currently have the <code>LoginManager()</code> setup:</p>
  
  <pre><code>lm = LoginManager()
  lm.init_app(app)
  lm.login_view = 'login'
  
  class User():
      def __init__(self, username):
          self.username = username
  
      def is_authenticated(self):
          return True
  
      def is_active(self):
          return True
  
      def is_anonymous(self):
          return False
  
      def get_id(self):
          return self.username
  
      @staticmethod
      def validate_login(password_hash, password):
          return check_password_hash(password_hash, password)
  
  @lm.user_loader
  def load_user(id):
      user = myUsers.find_one({"User": id})
      if not user:
          return None
      return User(user['User'])
  
  @app.route('/login', methods=['GET', 'POST'])
  def login():
      form = LoginForm()
      if current_user.is_authenticated:
          return redirect(request.args.get("next") or url_for("dashboard"))
          return redirect(url_for("dashboard"))
      else:
          if request.method == 'POST' and form.validate_on_submit():
              user = myUsers.find_one({"User": form.username.data})
              if user and User.validate_login(user['Password'], form.password.data):
                  user_obj = User(user['User'])
                  login_user(user_obj)
                  return redirect(request.args.get("next") or url_for("dashboard"))
              flash("Wrong username or password. Please try again.", category='error')
          return render_template('/login.html', title='Login', form=form)
  </code></pre>