title: How to get started on using Bottle-Cork with MongoDB?
body: <p>I am pretty new to Bottle and Cork. I am working on a web app using Bottle as the framework and MongoDB as the backend. I am trying to figure out how to implement a user-login system using Cork. </p>
  
  <p>I read documents and examples of Cork, and I tried to set things up. I have successfully hooked up the cork instance with Mongodb because I saw the database name, which I passed into the Cork() constructor as a parameter(backend), showed up in mongo shell. But then I have no idea how to keep going.</p>
  
  <p>I read all the Cork methods' source code and they all make sense to me. But a lot of them require to have a user with enough role level to be called like "list_roles()" or "create_users()". I understand that they are designed to be called by admin. But my question is how can I get started to create some users and test things out when I initially have no users at all?</p>
  
  <p>The following is what I got so far, and I just need some simple guidance or sample code to start. I would really appreciate any help!</p>
  
  <p>filename: api.py</p>
  
  <pre><code>from cork import Cork
  from cork.backends import MongoDBBackend
  from bottle import Bottle, redirect, static_file, request, response,HTTPResponse, HTTPError, abort, debug,run, route
  import bottle
  from beaker.middleware import SessionMiddleware
  import pymongo
  
  session_opts = {
     'session.type': 'cookie',
     'session.validate_key': True,
     'session.cookie_expires': True,
     'session.timeout': 3600 * 24, # 1 day
     'session.encrypt_key': 'lxy3344',
  }
  app = bottle.app()
  app = SessionMiddleware(app, session_opts)
  
  mb = MongoDBBackend(db_name='corkTry')
  aaa = Cork(backend=mb, email_sender='kkgghhyy@gmail.com')
  
  def postd():
      return bottle.request.forms
  
  def post_get(name, default=''):
      return bottle.request.POST.get(name, default).strip()
  
  
  # LOGIN # # LOGIN # # LOGIN # # LOGIN # # LOGIN # # LOGIN # # LOGIN # 
  @bottle.route('/')
  @bottle.get('/login')
  def login():
      print aaa.current_user()
      redirect('/static/login.html')
  
  @bottle.post('/login')
  def login():
      print 'in post login'
      """Authenticate users"""
      username = post_get('username')
      password = post_get('password')
      aaa.login(username, password, success_redirect='/home', fail_redirect='/login')
  
  # REGISTER # # REGISTER # # REGISTER # # REGISTER # # REGISTER # # REGISTER #
  @bottle.get('/register')
  def register():
      redirect('/static/register.html')
  
  @bottle.post('/register')
  def register():
      # Send out register email
      aaa.register(post_get('username'), post_get('password'), post_get('email_address'))
      return 'Please check your mailbox.'
  
  @bottle.route('/validate_registration/:registration_code')
  def validate_registration(registration_code):
      # Validate registration, create user account
      aaa.validate_registration(registration_code)
      return 'Thanks. &lt;a href="/login"&gt;Go to login&lt;/a&gt;'
  
  
  @bottle.route('/static/&lt;filepath:path&gt;',method='GET')
  def serve_static(filepath):
      return static_file(filepath, root='./static/' )
  
  @bottle.route('/home')
  def home():
      return '''This is the home page'''
  
  bottle.debug(True)
  bottle.run(app=app,reloader = True)
  </code></pre>