Пример #1
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'
Пример #2
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
Пример #3
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
Пример #4
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'
Пример #5
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
Пример #6
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
Пример #7
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'
Пример #8
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
Пример #9
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'
Пример #10
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'
Пример #11
0
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
Пример #12
0
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
Пример #13
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'
Пример #14
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
Пример #15
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
Пример #16
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
Пример #17
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
Пример #18
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
Пример #19
0
def login(username, password, isadmin=None):
    try:
        not_empty(username, password)
        cond = dict(username=username, password=hashPassword(password))
        if isadmin:
            cond.update(isadmin=isadmin)

        r = m_exists(TName, **cond)
        if r:
            r = mongo_conv(r)
            if r['status'] == INIT:
                return False, 'UNACTIVATED'
            return True, r
        else:
            return False, 'NO_EXISTED'
    except ValueError:
        return False, 'NO_EMPTY'
    except Exception as e:
        return False, e.message