Пример #1
0
def login():
    user_name = request.form['username']
    password = request.form['password']
    user_info = database.get('User', [
        or_(database.get_model('User').username == user_name, database.get_model('User').Snum == user_name, ),
        database.get_model('User').password == generate_password(password), ], first=True)
    if user_info:
        face_vector = request.form['face_vector'].split(',')
        face_vector1 = []
        for i in face_vector:
            face_vector1.append(float(i))
        if user_info.face_vector:
            standard_vector = user_info.face_vector.split(',')
            standard_vector1 = []
            for i in standard_vector:
                standard_vector1.append(float(i))
            if check_face_vector(face_vector1, standard_vector1):
                res = database.update('User', [or_(database.get_model('User').username == user_name,
                                                   database.get_model('User').Snum == user_name, )],
                                      {'token': new_token()})
                if res:
                    record_user_action(2, user_id=user_info.ID)
                    return reply_json(1, {'token': res.token})
                else:
                    return reply_json(-1)
            return reply_json(-8)
        return reply_json(-8)
    return reply_json(-6)
Пример #2
0
def change_password():
    """
    修改密码
    :return:
    """
    token = request.form['token']
    password = request.form['password']
    user_info = database.update('User', [database.get_model('User').token == token],
                                {'password': generate_password(password)})
    if user_info:
        return reply_json(1)
    return reply_json(-1)
Пример #3
0
def change_face_vector():
    """
    修改人脸识别信息
    :return:
    """
    token = request.form['token']
    if database.get('User', [database.get_model('User').token == token], first=True):
        face_vector = request.form['face_vector']
        user_info = database.update('User', [database.get_model('User').token == token],
                                    {'face_vector': face_vector})
        if user_info:
            return reply_json(1)
        return reply_json(-1)
    return reply_json(0)
Пример #4
0
def change_tag():
    """
    修改tag
    :return:
    """
    father = request.form['father']
    name = request.form['name']
    tag_id = request.form['tag_id']
    flag = database.update('Tag', [database.get_model('Tag').ID == tag_id], {
        'name': name,
        'father': father if father else None
    })
    if flag:
        return reply_json(1)
    return reply_json(-1)
Пример #5
0
def update_new_api():
    """
    从旧new_api升级到新new_api
    :return:
    """
    username = request.form['username']
    password = request.form['password']
    user_info = database.get('User', [
        or_(database.get_model('User').username == username, database.get_model('User').Snum == username, ),
        database.get_model('User').password == generate_password(password), ], first=True)
    if user_info:
        face_vector = request.form['face_vector']
        flag = database.update('User', [database.get_model('User').ID == user_info.ID],
                               {'face_vector': face_vector})
        if flag:
            database.add('UserRight', {'user_right': -1 if user_info.group == 1 else 0, 'user_id': user_info.ID})
            return reply_json(1)
        return reply_json(-1)
    return reply_json(0)
Пример #6
0
def change_article_tag():
    """
    修改文章标签
    :return:
    """
    tag_id = request.form['tag_id']
    name = request.form['name']
    tag_type = request.form['tag_type']
    icon = request.form['icon']
    description = request.form['description']
    flag = database.update(
        'ArticleTag', [database.get_model('ArticleTag').id == tag_id], {
            'name': name,
            'description': description,
            'icon': icon,
            'tag_type': tag_type
        })
    if flag:
        return reply_json(1)
    return reply_json(-1)
Пример #7
0
def change_article():
    """
    修改文章
    :return:
    """
    token = request.form['token']
    article_id = request.form['article_id']
    content = request.form['content']
    title = request.form['title']
    tag = request.form['tag']
    flag = database.update(
        'Article', [database.get_model('Article').ID == article_id], {
            'content': content,
            'title': title,
            'tag': tag,
            'changer': get_user_id(token)
        })
    if flag:
        database.add('History',
                     flag.get_history_format(user_id=get_user_id(token)))
        return reply_json(1)
    return reply_json(-1)
Пример #8
0
def register():
    """
    注册功能
    :return:
    """
    s_num = request.form['s_num']
    user_info = database.get('User', [database.get_model('User').Snum == s_num], first=True)
    if user_info:
        if not user_info.password:
            username = request.form['username']
            if database.get('User', [database.get_model('User').username == username]):
                return reply_json(-11)
            password = request.form['password']
            face_vector = request.form['face_vector']

            flag = database.update('User', [database.get_model('User').Snum == s_num],
                                   {'password': generate_password(password), 'username': username,
                                    'face_vector': face_vector})
            if flag:
                database.add('UserRight', {'user_right': flag.group, 'user_id': flag.ID})
                return reply_json(1)
            return reply_json(-1)
        return reply_json(-9)
    return reply_json(-10)