# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


from mongokit import *
from whirlwind.db.mongo import Mongo
from tornado import options
import datetime
import hashlib, hmac, base64, re
    
    #don't allow $ and . because they screw up the db.
    name = name.replace(".", "")
    name = name.replace("$", "")
    return name;

@Mongo.db.connection.register
class User(Document):
    structure = {
                 '_id':unicode,
                 'email':unicode,
                 'roles':list,
                 'password':unicode,
                 'created_at':datetime.datetime,
                 'history' : {
                              'last_login' : datetime.datetime,
                              'num_logins' : long
                              },
                 'timezone':unicode,
                 'suspended_at':datetime.datetime,
                 }
    use_dot_notation=True
    
    @staticmethod
    def normalize(username):
        return normalize(username)
        
    
    @staticmethod
    def lookup(username):

# Path: whirlwind/db/mongo.py
# class Mongo(Singleton):
#     
#     db = None
#     
#     def __init__(self):
#         self.connection = None
#     
#     '''
#         register a collection of mongokit model objects
#     '''
#     def register_models(self,models):
#         self.connection.register(models)
#     
#     '''
#         Accessor for ui specific database.
#     '''   
#     @property
#     def ui(self):
#         return self.connection[options.db_name]
#     
#     '''
#         Useage:
#         from whirlwind.db.mongo import Mongo
#         Mongo.create(host='host.com', port='23423', username='mongouser', password='password')
#     '''
#     @staticmethod
#     def create(**kwargs):
#         db = Mongo()
#         db.connection = Connection(kwargs['host'],kwargs['port'])
#         Mongo.db = db
#         if 'debug' in kwargs:
#             print Mongo.db.connection


# Path: whirlwind/conf/app_template/application/models/user.py
from mongokit import *
from whirlwind.db.mongo import Mongo
from tornado import options
import datetime
import hashlib, hmac, base64, re

    
    #don't allow $ and . because they screw up the db.
    name = name.replace(".", "")
    name = name.replace("$", "")
    return name;

@Mongo.db.connection.register
class User(Document):
    structure = {
                 '_id':unicode,
                 'email':unicode,
                 'roles':list,
                 'password':unicode,
                 'created_at':datetime.datetime,
                 'history' : {
                              'last_login' : datetime.datetime,
                              'num_logins' : long
                              },
                 'timezone':unicode,
                 'suspended_at':datetime.datetime,
                 }
    use_dot_notation=True
    
    @staticmethod
    def normalize(username):
        return normalize(username)
        
    
    @staticmethod
    def lookup(username):

        return Mongo.db.ui.users.User.find_one({'_id' : normalize(username)})