Exemplo n.º 1
0
 def get_public_users():
     '''
     Get all users for public display
     '''
     db_handler = DBManager.get_connection()
     cursor = db_handler['user'].find(projection=['_id','name'])
     return UserDao._cursor_to_list(cursor)
Exemplo n.º 2
0
 def get_user_by_id(oid):
     '''
     Query user by id, return a user dict(unicoded)  
     '''
     db_handler = DBManager.get_connection()
     account = db_handler['user'].find_one({"_id": ObjectId(oid)})
     return account
Exemplo n.º 3
0
 def get_users():
     '''
     Get all users without password field, return a list of user dicts
     '''
     db_handler = DBManager.get_connection()
     cursor = db_handler['user'].find(projection={'password':False})
     return UserDao._cursor_to_list(cursor)
Exemplo n.º 4
0
 def get_public_users():
     '''
     Get all users for public display
     '''
     db_handler = DBManager.get_connection()
     cursor = db_handler['user'].find(projection=['_id', 'name'])
     return UserDao._cursor_to_list(cursor)
Exemplo n.º 5
0
 def get_users():
     '''
     Get all users without password field, return a list of user dicts
     '''
     db_handler = DBManager.get_connection()
     cursor = db_handler['user'].find(projection={'password': False})
     return UserDao._cursor_to_list(cursor)
Exemplo n.º 6
0
 def get_user_by_id(oid):
     '''
     Query user by id, return a user dict(unicoded)  
     '''
     db_handler = DBManager.get_connection()
     account = db_handler['user'].find_one({"_id": ObjectId(oid)})
     return account
Exemplo n.º 7
0
 def set_password(self, username, password):
     '''
     set password for a user
     '''
     salt = bcrypt.gensalt()
     password_hash_string = bcrypt.hashpw(password, salt)
     db_handler = DBManager.get_connection()
     db_handler[app_settings.AUTH_TABLE_NAME].update({'name': username}, {'$set': {'password': password_hash_string}})
Exemplo n.º 8
0
 def set_password(username, password):
     '''
     persist password string as hash into database 
     '''
     salt = bcrypt.gensalt()
     password_hash_string = bcrypt.hashpw(password, salt)
     db_handler = DBManager.get_connection()
     db_handler[app_settings.AUTH_TABLE_NAME].update({'name': username}, {'$set': {'password': password_hash_string}})
Exemplo n.º 9
0
def get_account(oid):
    db_handler = DBManager.get_connection()
    account = db_handler['user'].find_one({"_id": ObjectId(oid)})
    
    if not account:
        abort(404)
    
    account = JsonUtil.itemToStr(account)
    return jsonify({'account': account})
Exemplo n.º 10
0
 def get_user_by_id(id):
     '''
     Query user by id, return user dict
     '''
     db_handler = DBManager.get_connection()
     user = db_handler[app_settings.AUTH_TABLE_NAME].find_one({"_id": ObjectId(id)})
     # translate  ObjectId(id) to string id
     logger.debug('Authen.get_user_by_id()={0}'.format(type(user)))
     return user
Exemplo n.º 11
0
 def get_user_by_id(id):
     '''
     Query user by id, return user dict
     '''
     db_handler = DBManager.get_connection()
     user = db_handler[app_settings.AUTH_TABLE_NAME].find_one(
         {"_id": ObjectId(id)})
     # translate  ObjectId(id) to string id
     logger.debug('Authen.get_user_by_id()={0}'.format(type(user)))
     return user
Exemplo n.º 12
0
 def set_password(username, password):
     '''
     persist password string as hash into database 
     '''
     salt = bcrypt.gensalt()
     password_hash_string = bcrypt.hashpw(password, salt)
     db_handler = DBManager.get_connection()
     db_handler[app_settings.AUTH_TABLE_NAME].update(
         {'name': username}, {'$set': {
             'password': password_hash_string
         }})
Exemplo n.º 13
0
 def load(self, collection_name):
     '''
     Load collection from a json file
     1) parse file_name without json extension
     2) parse file as json objects 
     3) load json file into db
     '''
     
     docs = self._load_json_file(collection_name)
     print 'import collection = {0}'.format(collection_name)
     db_handler = DBManager.get_connection()
     db_handler[collection_name].insert_many(docs)
Exemplo n.º 14
0
 def authenticate(username, password):
     '''
     verify password with username and password
     '''
     db_handler = DBManager.get_connection()
     user = db_handler[app_settings.AUTH_TABLE_NAME].find_one({'name': username})
     db_hashed_password = str(user['password'])
     logger.debug('authenticate user type={0}'.format(type(user)))
     if not user or not Authen.compare_password(db_hashed_password, password):
         return None
     else:
         return user
Exemplo n.º 15
0
 def authenticate(username, password):
     '''
     verify password with username and password
     '''
     db_handler = DBManager.get_connection()
     user = db_handler[app_settings.AUTH_TABLE_NAME].find_one(
         {'name': username})
     db_hashed_password = str(user['password'])
     logger.debug('authenticate user type={0}'.format(type(user)))
     if not user or not Authen.compare_password(db_hashed_password,
                                                password):
         return None
     else:
         return user
Exemplo n.º 16
0
    def dump(self, collection_name):
        '''
        write collection into a json file
        
        1) read collections
        2) write collections into json file
        '''

        print 'export collection = {0}'.format(collection_name)
        
        json_file_name = collection_name + '.json'
        json_file_path = os.path.join(self.data_dir, json_file_name)

        db_handler = DBManager.get_connection()
        iterator = db_handler[collection_name].find()
        collection = []
        for item in iterator:
            item = JSONEncoder().encode(item)
            collection.append(item)
        
        with open(json_file_path, 'w') as file_handler:
            json.dump(collection, file_handler)