예제 #1
0
def userstatus(username, enable=True, callback=None):
    ''' 启用或停用openfire用户'''
    not_empty(username)
    able = 'enable' if enable else 'disable'
    val = dict(type=able, username=username)
    url = _make_url(val)
    return client.fetch(url, callback=callback)
예제 #2
0
def userstatus(username, enable=True, callback=None):
    ''' 启用或停用openfire用户'''
    not_empty(username)
    able = 'enable' if enable else 'disable'
    val = dict(type=able, username=username)
    url = _make_url(val)
    return client.fetch(url, callback=callback)
예제 #3
0
파일: area.py 프로젝트: zhaojintian/migrant
 def info_city_listname(self, listname):
     ''' city info by listname '''
     not_empty(listname)
     try:
         return self._coll().info(listname, key='listname')
     except Exception as e:
         print e 
         return None
예제 #4
0
def add(username, password, name, email=None, group=None, callback=None):
    ''' 添加一个用户到openfire '''
    not_empty(username, password, name)
    val = dict(type='add', username=username,
               password=hashPassword(password), name=name, email=email, groups=group)
    url = _make_url(val)
    print url
    return client.fetch(url, callback=callback)
예제 #5
0
def update(username, password=None, name=None, email=None, group=None, callback=None):
    ''' 修改用户息 '''
    not_empty(username)
    val = dict(type='update', username=username,
               password=hashPassword(password), name=name, email=email, groups=group)
    url = _make_url(val)
    print url
    return client.fetch(url, callback=callback)
예제 #6
0
def add(uid,pid,body,**kwargs):
    not_empty(uid,pid,body)
    try:
        val = dict(uid=uid,pid=pid,body=body)
        _id = Tb().insert(val,saft=True)
        val['_id'] = str(_id)
        return True,val
    except Exception as e:
        return False,e.message
예제 #7
0
def add(uid, pid, body, **kwargs):
    not_empty(uid, pid, body)
    try:
        val = dict(uid=uid, pid=pid, body=body)
        _id = Tb().insert(val, saft=True)
        val['_id'] = str(_id)
        return True, val
    except Exception as e:
        return False, e.message
예제 #8
0
def m_info(table,_id):
    not_empty(_id)
    try:
        cond = dict(_id=ObjectId(_id))
        cond.update(StatusCond)
        return True,mongo_conv(Tb(table).find_one(cond,{'status':0}))
    except InvalidId as e:
        return False,"查询参数格式错误"
    except Exception as e:
        return False,e.message
예제 #9
0
def info_category_listname(listname):
    ''' category info by listname '''
    not_empty(listname)
    try:
        val = Tb().find_one(dict(listname = listname))
        val["_id"] = str(val['_id'])
        return val
    
    except Exception as e:
        return None
예제 #10
0
def m_info(table,_id):
    not_empty(_id)
    try:
        cond = dict(_id=ObjectId(_id))
        cond.update(StatusCond)
        return True,mongo_conv(Tb(table).find_one(cond,{'status':0}))
    except InvalidId as e:
        return False,"查询参数格式错误"
    except Exception as e:
        return False,e.message
예제 #11
0
def info_category_listname(listname):
    ''' category info by listname '''
    not_empty(listname)
    try:
        val = Tb().find_one(dict(listname=listname))
        val["_id"] = str(val['_id'])
        return val

    except Exception as e:
        return None
예제 #12
0
def m_update(table, _id, **kwargs):
    try:
        not_empty(table, _id)
        cond = dict(_id=ObjectId(_id))
        cond.update(StatusCond)
        Tb(table).update(cond, {'$set': kwargs})
        return True, None
    except InvalidId as e:
        return False, "查询参数格式错误"
    except Exception as e:
        return False, e.message
예제 #13
0
def m_update(table,_id,**kwargs):
    try:
        not_empty(table,_id)
        cond = dict(_id = ObjectId(_id))
        cond.update(StatusCond)
        Tb(table).update(cond,{'$set':kwargs})
        return True,None
    except InvalidId as e:
        return False,"查询参数格式错误"
    except Exception as e:
        return False,e.message
예제 #14
0
def info_group_listname(listname):
    not_empty(listname)
    try:
        val = Tb()().find_one(dict(listname = listname))
        val['_id'] = str(val['_id'])
        return val
    
    except Exception as e:
        return None

    return None
예제 #15
0
def add(username, password, name, email=None, group=None, callback=None):
    ''' 添加一个用户到openfire '''
    not_empty(username, password, name)
    val = dict(type='add',
               username=username,
               password=hashPassword(password),
               name=name,
               email=email,
               groups=group)
    url = _make_url(val)
    print url
    return client.fetch(url, callback=callback)
예제 #16
0
파일: category.py 프로젝트: sarike/migrant
def add(name, groupid, listname, intro, **kwargs):
    """ add category """
    not_empty(name, listname, groupid)
    val = dict(name=name, groupid=groupid, listname=listname, intro=intro)
    val.update(kwargs)
    try:
        _id = Tb().insert(val, saft=True)
        val["_id"] = str(_id)

    except Exception as e:
        return False, e.message

    return True, val
예제 #17
0
def reset_pwd(uid, old_password, new_password):
    try:
        not_empty(uid, old_password, new_password)
        _id = ObjectId(uid)
        kwargs = dict(_id=_id, password=hashPassword(old_password))
        valid = m_exists(TName, **kwargs)
        if valid:
            Tb().update(kwargs, {'$set': {'password': hashPassword(new_password)}})
            return True, 'OK'
        else:
            return False, 'INVALIDED'
    except ValueError:
        return False, 'NO_EMPTY'
예제 #18
0
def hashPassword(password):
    """Hash the user password.

    Args:
        password : the user input password.
    Returns:
        the password with md5 hashable

    """
    not_empty(password)
    md5 = hashlib.md5()
    md5.update(password)
    return md5.hexdigest()
예제 #19
0
def hashPassword(password):
    """Hash the user password.

    Args:
        password : the user input password.
    Returns:
        the password with md5 hashable

    """
    not_empty(password)
    md5 = hashlib.md5()
    md5.update(password)
    return md5.hexdigest()
예제 #20
0
def add(name,parent=None,level=0):
    try:
        not_empty(name)
        r = m_exists(TName,name=name,parent=parent,level=level)
        if not r:
            val = dict(name=name,parent=parent,level=level,status=0)
            _id = Tb().insert(val,saft=True)
            val['_id'] = str(_id)
            return True,val
        else:
            return False,'EXIST'
    except Exception as e:
        return False,e.message
예제 #21
0
def add(name, parent=None, level=0):
    try:
        not_empty(name)
        r = m_exists(TName, name=name, parent=parent, level=level)
        if not r:
            val = dict(name=name, parent=parent, level=level)
            _id = Tb().insert(val, saft=True)
            val['_id'] = str(_id)
            return True, val
        else:
            return False, 'EXITS'
    except Exception as e:
        return False, e.message
예제 #22
0
 def reset_pwd(self, uid, old_password, new_password):
     try:
         not_empty(uid, old_password, new_password)
         _id = ObjectId(uid)
         kwargs = dict(_id=_id, password=hashPassword(old_password))
         valid = self.exists(**kwargs)
         if valid:
             self.update(uid, password= hashPassword(new_password))
             return True, 'OK'
         else:
             return False, 'INVALIDED'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #23
0
 def reset_pwd(self, uid, old_password, new_password):
     try:
         not_empty(uid, old_password, new_password)
         _id = ObjectId(uid)
         kwargs = dict(_id=_id, password=hashPassword(old_password))
         valid = self.exists(**kwargs)
         if valid:
             self.update(uid, password=hashPassword(new_password))
             return True, 'OK'
         else:
             return False, 'INVALIDED'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #24
0
 def add(self, username, password, city=None, **kwargs):
     try:
         not_empty(username, password)
         r = self.exists(username=username)
         if not r:
             val = dict(username=username, password=hashPassword(password), city=city)
             _id = self.insert(val,**kwargs)
             val['_id'] = str(_id)
             return True, val
         else:
             return False, 'EXISTS'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #25
0
def add(name, groupid, listname, intro, **kwargs):
    ''' add category '''
    not_empty(name, listname, groupid)
    val = dict(name=name, groupid=groupid, listname=listname, intro=intro)
    val.update(kwargs)
    try:
        _id = Tb().insert(val, saft=True)
        val["_id"] = str(_id)

    except Exception as e:
        return False, e.message

    return True, val
예제 #26
0
 def auth_login(self, site,otherid,name,**kwargs):
     try:
         not_empty(site,otherid,name)
         r = self.exists(site=site,otherid=otherid,name=name)
         if r:
             r = mongo_conv(r)
             return True,r
         else:
             val = dict(site=site,otherid=otherid,name=name)
             _id = self.insert(val)
             val['_id'] = str(_id)
             return True,val
     except Exception as e:
         return False,e.message
예제 #27
0
def list_by_post(pid, since=None, size=10):
    not_empty(pid)
    cond = dict(pid=pid)
    r, lst = m_page(TName, since, size, **cond)
    arr = []
    for item in lst:
        try:
            r, v = m_info(T_ACCOUNT, item['uid'])
            if r: item['user'] = v['username']
            arr.append(item)
        except Exception as e:
            pass

    return r, arr
예제 #28
0
def list_by_post(pid,since=None,size=10):
    not_empty(pid)
    cond = dict(pid=pid)
    r,lst = m_page(TName,since,size,**cond)
    arr = []
    for item in lst:
        try:
            r,v = m_info(T_ACCOUNT,item['uid'])
            if r:item['user'] = v['username']
            arr.append(item)
        except Exception as e:
            pass

    return r,arr
예제 #29
0
def add(username, password, city=None, **kwargs):
    try:
        not_empty(username, password)
        r = m_exists(TName, username=username)
        if not r:
            val = dict(username=username, password=hashPassword(password), city=city)
            val.update(kwargs)
            _id = Tb().insert(val, saft=True)
            val['_id'] = str(_id)
            return True, val
        else:
            return False, 'EXISTS'
    except ValueError:
        return False, 'NO_EMPTY'
예제 #30
0
def add(username,password,city=None,**kwargs):
    try:
        not_empty(username,password)
        r = m_exists(TName,username=username,password=password)
        if not r:
            val = dict(username=username,password=password,city=city)
            val.update(kwargs)
            _id = Tb().insert(val,saft=True)
            val['_id'] = str(_id)
            return True,val
        else:
            return False,'EXITS'
    except Exception as e:
        return False,e.message
예제 #31
0
def auth_login(site,otherid,name,**kwargs):
    try:
        not_empty(site,otherid,name)
        r = m_exists(TName,site=site,otherid=otherid,name=name)
        if r:
            r = mongo_conv(r)
            return True,r
        else:
            val = dict(site=site,otherid=otherid,name=name)
            _id = Tb().insert(val,saft=True)
            val['_id'] = str(_id)
            return True,val
    except Exception as e:
        return False,e.message
예제 #32
0
 def active_account(self, key):
     try:
         not_empty(key)
         redis = get_context().get_redis()
         username = redis.get(key)
         if not username:
             return False, 'EXPIRED'
         existed = self.exists(username=username)
         if existed:
             self.update(username, key='username', status=ACTIVATED)
             return True, dict(username=username)
         else:
             return False, 'NO_EXIST'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #33
0
 def add(self, username, password, city=None, **kwargs):
     try:
         not_empty(username, password)
         r = self.exists(username=username)
         if not r:
             val = dict(username=username,
                        password=hashPassword(password),
                        city=city)
             _id = self.insert(val, **kwargs)
             val['_id'] = str(_id)
             return True, val
         else:
             return False, 'EXISTS'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #34
0
def forgot_pwd(username):
    try:
        not_empty(username)
        existed = m_exists(TName, username=username)
        if existed:
            key = random_key()
            redis = get_context().get_redis()
            redis.set(key, username, 60 * 60)
            r = send_mail([username], '找回密码',
                          get_email_content('email_forget_password.html', key=key, username=username))
            return r, 'OK' if r else 'FAIL'
        else:
            return False, 'NO_EXIST'
    except ValueError:
        return False, 'NO_EMPTY'
예제 #35
0
def apply_active_account(username):
    try:
        not_empty(username)
        existed = m_exists(TName, username=username)
        if existed:
            key = random_key()
            redis = get_context().get_redis()
            redis.set(key, username, 60 * 60)
            r = send_mail([username], '账号激活',
                          get_email_content('email_active_account.html', key=key, username=username))
            return r, 'OK' if r else 'FAIL'
        else:
            return False, 'NO_EXIST'
    except ValueError:
        return False, 'NO_EMPTY'
예제 #36
0
def login(username,password,isadmin = None):
    try:
        not_empty(username,password)
        cond = dict(username=username,password=password)
        if isadmin:
            cond.update(isadmin = isadmin)

        r = m_exists(TName,**cond)
        if r:
            r = mongo_conv(r)
            return True, r
        else:
            return False,None
    except Exception as e:
        return False,e.message
예제 #37
0
 def active_account(self,key):
     try:
         not_empty(key)
         redis = get_context().get_redis()
         username = redis.get(key)
         if not username:
             return False, 'EXPIRED'
         existed = self.exists(username=username)
         if existed:
             self.update(username,key='username',status=ACTIVATED)
             return True, dict(username=username)
         else:
             return False, 'NO_EXIST'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #38
0
def active_account(key):
    try:
        not_empty(key)
        redis = get_context().get_redis()
        username = redis.get(key)
        if not username:
            return False, 'EXPIRED'
        existed = m_exists(TName, username=username)
        if existed:
            Tb().update(dict(username=username),
                        {'$set': {'status': ACTIVATED}})
            return True, dict(username=username)
        else:
            return False, 'NO_EXIST'
    except ValueError:
        return False, 'NO_EMPTY'
예제 #39
0
파일: report.py 프로젝트: sarike/migrant
def add(title, pid, city, body, source=None, **kwargs):
    """ add report """
    try:
        not_empty(title, body)
        val = dict(title=title, pid=pid, city=city, body=body, source=source)
        r = m_exists(TName, title=title, pid=pid)
        if not r:
            val.update(kwargs)
            _id = Tb().insert(val, saft=True)
            val["_id"] = str(_id)
        else:
            return False, "exists"

    except Exception as e:
        return False, e.message

    return True, val
예제 #40
0
def add(name, listname, **kwargs):
    ''' add group '''
    not_empty(name, listname)
    r = m_exists(TName,name=name,listname=listname)
    if r:
        return False,'存在name 或 listname '

    val = dict(name = name, listname = listname)
    val.update(kwargs)
    try:
        _id = Tb().insert(val, saft = True)
        val["_id"] = str(_id)

    except Exception as e:
        return False, e.message

    return True, val
예제 #41
0
    def reset_forgotten_password(self, key, new_password):
        try:
            not_empty(key, new_password)
            redis = get_context().get_redis()
            username = redis.get(key)
            if not username:
                return False, 'EXPIRED'

            existed = self.exists(username=username)
            if existed:
                self.update(username,key='username', password=hashPassword(new_password))
                return True, 'OK'
            else:
                return False, 'NO_EXIST'

        except ValueError:
            return False, 'NO_EMPTY'
예제 #42
0
파일: report.py 프로젝트: sunbenxin/migrant
def add(title, pid, city, body, source=None, **kwargs):
    ''' add report '''
    try:
        not_empty(title, body)
        val = dict(title=title, pid=pid, city=city, body=body, source=source)
        r = m_exists(TName, title=title, pid=pid)
        if not r:
            val.update(kwargs)
            _id = Tb().insert(val, saft=True)
            val["_id"] = str(_id)
        else:
            return False, 'exists'

    except Exception as e:
        return False, e.message

    return True, val
예제 #43
0
def update(username,
           password=None,
           name=None,
           email=None,
           group=None,
           callback=None):
    ''' 修改用户息 '''
    not_empty(username)
    val = dict(type='update',
               username=username,
               password=hashPassword(password),
               name=name,
               email=email,
               groups=group)
    url = _make_url(val)
    print url
    return client.fetch(url, callback=callback)
예제 #44
0
def reset_forgotten_password(key, new_password):
    try:
        not_empty(key, new_password)
        redis = get_context().get_redis()
        username = redis.get(key)
        if not username:
            return False, 'EXPIRED'

        existed = m_exists(TName, username=username)
        if existed:
            Tb().update(dict(username=username), {'$set': {'password': hashPassword(new_password)}})
            return True, 'OK'
        else:
            return False, 'NO_EXIST'

    except ValueError:
        return False, 'NO_EMPTY'
예제 #45
0
파일: label.py 프로젝트: Angel-fund/migrant
def add(category, name, **kwargs):
    try:
        not_empty(name)
        cond = dict(category = category, name=name)
        val = m_exists(TName,**cond)
        if not val:
            #如果不存在此标签 则添加
            cond['usage'] = 1
            cond['hot']  = 0
            r,_id = m_add(TName,cond)
            cond['_id'] = _id
        else:
            cond.update(status={'$ne':-1})
            Tb().update(cond,{'$inc':{'usage':1}})

        return True, cond
    except Exception as e:
        return False,e.message
예제 #46
0
 def apply_active_account(self, username, host):
     try:
         not_empty(username)
         existed = self.exists(username=username)
         if existed:
             key = random_key()
             redis = get_context().get_redis()
             redis.set(key, username, 60 * 60)
             r = send_mail([username], '账号激活',
                           get_email_content('email_active_account.html',
                                             host=host,
                                             key=key,
                                             username=username))
             return r, 'OK' if r else 'FAIL'
         else:
             return False, 'NO_EXIST'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #47
0
def add(category, name, **kwargs):
    try:
        not_empty(name)
        cond = dict(category=category, name=name)
        val = m_exists(TName, **cond)
        if not val:
            #如果不存在此标签 则添加
            cond['usage'] = 1
            cond['hot'] = 0
            r, _id = m_add(TName, cond)
            cond['_id'] = _id
        else:
            cond.update(status={'$ne': -1})
            Tb().update(cond, {'$inc': {'usage': 1}})

        return True, cond
    except Exception as e:
        return False, e.message
예제 #48
0
 def forgot_pwd(self, username, host):
     try:
         not_empty(username)
         existed = self.exists(username=username)
         if existed:
             key = random_key()
             redis = get_context().get_redis()
             redis.set(key, username, 60 * 60)
             r = send_mail([username], '找回密码',
                           get_email_content('email_forget_password.html',
                                             host=host,
                                             key=key,
                                             username=username))
             return r, 'OK' if r else 'FAIL'
         else:
             return False, 'NO_EXIST'
     except ValueError:
         return False, 'NO_EMPTY'
예제 #49
0
def add(uid, body, city=None, **kwargs):
    try:
        not_empty(uid, body)
        r = m_exists(TName, uid=uid, body=body)
        if not city:
            r, v = m_info(account.TName, uid)
            if r: city = v.get('city', None)

        if not r:
            val = dict(uid=uid, body=body, city=city)
            val.update(kwargs)
            _id = Tb().insert(val, saft=True)
            val['_id'] = str(_id)
            return True, val
        else:
            return False, 'EXITS'
    except Exception as e:
        return False, e.message
예제 #50
0
    def login(self, username, password, isadmin=None):
        try:
            not_empty(username, password)
            cond = dict(username=username, password=hashPassword(password))
            #cond = dict(username=username, password=password)
            if isadmin:
                cond.update(isadmin=isadmin)

            r = self.exists(**cond)
            if r:
                r = mongo_conv(r)
                return True, r
            else:
                return False, 'NO_EXISTED'
        except ValueError:
            return False, 'NO_EMPTY'
        except Exception as e:
            return False, e.message
예제 #51
0
    def login(self, username, password, isadmin=None):
        try:
            not_empty(username, password)
            cond = dict(username=username, password=hashPassword(password))
            #cond = dict(username=username, password=password)
            if isadmin:
                cond.update(isadmin=isadmin)

            r = self.exists(**cond)
            if r:
                r = mongo_conv(r)
                return True, r
            else:
                return False, 'NO_EXISTED'
        except ValueError:
            return False, 'NO_EMPTY'
        except Exception as e:
            return False, e.message
예제 #52
0
    def reset_forgotten_password(self, key, new_password):
        try:
            not_empty(key, new_password)
            redis = get_context().get_redis()
            username = redis.get(key)
            if not username:
                return False, 'EXPIRED'

            existed = self.exists(username=username)
            if existed:
                self.update(username,
                            key='username',
                            password=hashPassword(new_password))
                return True, 'OK'
            else:
                return False, 'NO_EXIST'

        except ValueError:
            return False, 'NO_EMPTY'
예제 #53
0
def m_del(table, _id, is_del=False):
    '''
        通用删除逻辑
        table : 表名
        _id : 主键
        is_del: 是否为硬删除
    '''
    try:
        not_empty(table, _id)
        if is_del:
            Tb(table).remove(dict(_id=ObjectId(_id)))
        else:
            cond = dict(_id=ObjectId(_id))
            cond.update(StatusCond)
            Tb(table).update(cond, {'$set': {'status': -1}})
    except InvalidId as e:
        return False, "查询参数格式错误"
    except Exception as e:
        return False, e.message

    return True, None
예제 #54
0
def m_add(table, data):
    not_empty(table)
    _id = Tb(table).insert(data, saft=True)
    return True, str(_id)
예제 #55
0
 def get(self):
     _id = self.get_argument("_id", None)
     not_empty(_id)
     info = AModel.info(_id)
     self.write(dict(status=True, data=info))