Beispiel #1
0
def update_pwd():
    data = request.get_json()
    if is_admin_login(request):
        admin_id = get_admin_id_by_cookie(request)
    else:
        return jsonify({'code': 208, 'msg': "登录信息已经过期"})
    update_pwd = data['update_pwd']
    original_pwd = data['original_pwd']
    # 根据用户id查询相关元组,如果该用户存在,继续逻辑判断,否则返回该用户不存在
    user = Admin.query.filter(Admin.admin_id == admin_id).first()
    if user:
        original_pwd = my_md5(str(original_pwd))
        # 根据传进来的id,原密码和数据库里的数据进行比较,成功继续,否则返回密码不一致
        account = Admin.query.filter(Admin.nick_name == user.nick_name, original_pwd == user.passwd).first()
        # 密码匹配成功
        if account:
            user.passwd = my_md5(str(update_pwd))
            # 新密码和旧密码一样,返回相同密码,否则将新密码提交
            if user.passwd == original_pwd:
                return jsonify({'code': 203, 'msg': "the same password"})
            else:
                db.session.commit()
                uid = request.cookies.get('admin_token')
                # 从redis里删除该用户之前的token
                redis = get_redis_cli()
                redis.delete("admin:" + str(uid))
                return jsonify({'code': 200, 'msg': "update password successfully"})
        else:
            return jsonify({'code': 203, 'msg': "Passwords are inconsistent!"})
    else:
        return jsonify({'code': 203, 'msg': "admin_id does't exit"})
Beispiel #2
0
def admin_quit():
    redis = get_redis_cli()
    if not is_admin_login(request):
        return jsonify({'code': 208, 'msg': '管理员信息已过期'})
    uuid = request.cookies.get('admin_token')
    redis.delete("admin:" + str(uuid))
    return jsonify({'code': 200, 'msg': '管理员退出成功'})
Beispiel #3
0
def user_list_slice():
    data = request.get_json()
    if not is_admin_login(request):
        return jsonify({"code": 208, "msg": "登录信息已经过期"})
    page_index = data['pageIndex']
    if int(page_index) <= 0:
        return jsonify([])
    page_size = 15
    query = db.session.query(User)
    if 'nick_name' in data.keys():
        query = query.filter(User.nick_name.like("%" + data['nick_name'] +
                                                 "%"))
    result = query.limit(page_size).offset((int(page_index) - 1) * page_size)
    return jsonify(User.serialize_list(result))
Beispiel #4
0
def get():
    work_id_data = request.get_data()
    if not is_admin_login(request):
        return jsonify({"code": 208, "msg": "登录信息已经过期"})
    user_list = json.loads(work_id_data)
    for i in range(len(user_list)):
        work_id = user_list[i].get("work_id")
        if work_id is None:
            return {"code": 203, "msg": "参数错误"}
        user = User(passwd=my_md5("123456"), work_id=work_id)
        try:
            db.session.add(user)
            db.session.commit()
        except sqlalchemy.exc.IntegrityError:
            # 重复插入错误处理
            db.session.remove()
            continue

    return {"code": 200, "msg": "success"}
Beispiel #5
0
def ad_update_pic():
    file = request.files['file']
    if not is_admin_login(request):
        return jsonify({"code": 208, "msg": "登录信息已经过期"})
    admin_id = get_admin_id_by_cookie(request)
    if exist_admin(admin_id):
        filename = "".join(lazy_pinyin(file.filename))
        b = "."
        redis = get_redis_cli()
        incr = redis.incr('admin-images')
        filename = str(incr) + str(filename[filename.rfind(b):])
        if file and allowed_file(filename):
            filename = secure_filename(filename)
            file.save(os.path.join(app.config['ADMIN_UPLOAD_FOLDER'],
                                   filename))
            url = "http://192.168.195.10:5005/admin/images/" + filename
            admin = Admin.query.filter(Admin.admin_id == admin_id).first()
            admin.head_pic = url
            db.session.commit()
            return {"code": "200", "msg": "上传成功", "url": url}
        else:
            return {"code": "203", "msg": "上传失败"}
    else:
        return {"code": "203", "msg": "抱歉,管理员不存在"}