title: Ruby Sinatra - Protecting routes with authentication
body: <p>I have a Ruby class that basically authenticates a user to an LDAP directory as follows. The <code>DirectoryUser</code> class is using the net/ldap gem to do this. When called the class returns either a 'true' if the user is authenticated or 'false' if not.  </p>
  
  <pre><code>&gt;&gt;DirectoryUser.authenticate('user', 'password')
    #True
  </code></pre>
  
  <p>I want to use this mechanism to protect my routes in a basic Sinatra application for multiple users. </p>
  
  <ol>
  <li>Is there a recommended way to do this that follows best practise? </li>
  <li>Could somebody show how this could be achieved?</li>
  </ol>
  
  <p>I was thinking of just setting a variable and checking the status of the variable before allowing access to the route. However, I can't help thinking there are some security implications that I could be missing here!</p>