示例#1
0
def add_news(title,txt,lid,uid):
    v = Level.objects(id=ObjectId(lid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if v in u.power or u.user_type == 100:
        news = News(title=title,txt=txt,author=u.name)
        news.category = v
        news.save()
示例#2
0
def add_news(title, txt, lid, uid):
    v = Level.objects(id=ObjectId(lid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if v in u.power or u.user_type == 100:
        news = News(title=title, txt=txt, author=u.name)
        news.category = v
        news.save()
示例#3
0
def get_power(uid):
    res = User.objects(id=ObjectId(uid))
    if res:
        u = res.first()
        if u.user_type == 100:
            return get_sub_lvls("")
        else:
            return u.power if u.power else []
    return []
示例#4
0
def edit_user(uid, name, password):
    res = User.objects(id=ObjectId(uid))
    if res:
        u = res.first()
        if name:
            u.name = name
        if password:
            u.password = make_pw(name, password)
        u.save()
示例#5
0
def edit_user(uid,name,password):
    res = User.objects(id=ObjectId(uid))
    if res:
        u = res.first()
        if name:
            u.name = name
        if password:
            u.password = make_pw(name,password)
        u.save()
示例#6
0
def get_power(uid):
    res = User.objects(id=ObjectId(uid))
    if res:
        u = res.first()
        if u.user_type == 100:
            return get_sub_lvls('')
        else:
            return u.power if u.power else []
    return []
示例#7
0
def ch_pw(uid,opw,npw,name):
    opw = make_pw(name,opw)
    res = User.objects(id=ObjectId(uid)).filter(password=opw)
    if not res:
        return False
    u = res.first()
    npw = make_pw(u.name,npw)
    u.password = npw
    u.save()
    return u
示例#8
0
def ch_pw(uid, opw, npw, name):
    opw = make_pw(name, opw)
    res = User.objects(id=ObjectId(uid)).filter(password=opw)
    if not res:
        return False
    u = res.first()
    npw = make_pw(u.name, npw)
    u.password = npw
    u.save()
    return u
示例#9
0
def add_power(uids,powerids):
    uids = [ObjectId(i) for i in uids]
    users = User.objects(id__in=uids)
    powerids = [ObjectId(i) for i in powerids]
    powers = Level.objects(id__in=powerids)
    # print(uids,powerids)
    if not users or not powers:
        return
    for user in users:
        user.power.clear()
        for power in powers:
            user.power.append(power)
            user.save()
    return True
示例#10
0
def add_power(uids, powerids):
    uids = [ObjectId(i) for i in uids]
    users = User.objects(id__in=uids)
    powerids = [ObjectId(i) for i in powerids]
    powers = Level.objects(id__in=powerids)
    # print(uids,powerids)
    if not users or not powers:
        return
    for user in users:
        user.power.clear()
        for power in powers:
            user.power.append(power)
            user.save()
    return True
示例#11
0
def del_user(uid):
    User.objects(id=ObjectId(uid)).delete()
示例#12
0
def login(name, pw):
    pw = make_pw(name, pw)
    res = User.objects(name=name).filter(password=pw)
    if not res:
        return False
    return res.first()
示例#13
0
def get_users():
    users = User.objects(user_type__ne=100)
    return users if users else []
示例#14
0
def del_news(nid,uid):
    news = News.objects(id=ObjectId(nid))
    u = User.objects(id=ObjectId(uid)).first()
    if news.category in u.power:
        u.delete()
示例#15
0
def get_one_news(nid,uid,user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news.author == u or has_power(news,u.power) or user_type==100:
        return news
示例#16
0
def del_news(nid, uid):
    news = News.objects(id=ObjectId(nid))
    u = User.objects(id=ObjectId(uid)).first()
    if news.category in u.power:
        u.delete()
示例#17
0
def check_news(nid, uid, user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news and u and has_power(news, u.power) or user_type == 100:
        news.is_released = True
        news.save()
示例#18
0
def check_news(nid,uid,user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news and u and has_power(news,u.power) or user_type==100:
        news.is_released = True
        news.save()
示例#19
0
def get_one_news(nid, uid, user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news.author == u or has_power(news, u.power) or user_type == 100:
        return news
示例#20
0
def add_admin_user(name, password):
    admin_users = User.objects(user_type=100)
    if not admin_users:
        u = add_user(name, password)
        u.user_type = 100
        u.save()
示例#21
0
def add_admin_user(name,password):
    admin_users = User.objects(user_type=100)
    if not admin_users:
        u = add_user(name,password)
        u.user_type = 100
        u.save()
示例#22
0
def login(name,pw):
    pw = make_pw(name,pw)
    res = User.objects(name=name).filter(password=pw)
    if not res:
        return False
    return res.first()
示例#23
0
def get_users():
    users = User.objects(user_type__ne=100)
    return users if users else []
示例#24
0
def del_user(uid):
    User.objects(id=ObjectId(uid)).delete()
示例#25
0
def add_user(name, password):
    pw = make_pw(name, password)
    u = User(name=name, password=pw)
    u.save()
    return u
示例#26
0
def add_user(name,password):
    pw = make_pw(name,password)
    u = User(name=name,password=pw)
    u.save()
    return u