Пример #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 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
Пример #19
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()
Пример #20
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()
Пример #21
0
def get_users():
    users = User.objects(user_type__ne=100)
    return users if users else []
Пример #22
0
def del_user(uid):
    User.objects(id=ObjectId(uid)).delete()
Пример #23
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()
Пример #24
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()