def deleteUSER():
    """ 管理员或者super用户在用户管理界面删除其他用户(低权限用户)

    :return:
    """
    tup = ("user", "admin", "super")  # 用下标 0, 1, 2 来比较权限的大小!!
    # 当前修改者属性
    username = request.form.get("username", type=str, default="")
    # 被修改者的属性
    othername = request.form.get('othername', type=str, default="")
    otheremail = request.form.get("otheremail", type=str, default="")

    result = DB_Sync.query_redis(othername)
    # print(result)
    othertype = result["data"]["USER_TYPE"]
    # 判断当前用户是否在线
    if session.get("username") == username and session.get('isLogin'):
        # 获取当前用户的权限和锁定情况
        result = DB_Sync.query_redis(username)
        usertype = result["data"]["USER_TYPE"]
        userlock = result["data"]["USER_LOCK"]
        # 判断当前用户是否有权限删除,自己删除不了自己
        if userlock == 0 and tup.index(usertype) > tup.index(othertype):
            is_delete = DB_Sync.sync_redis_delete(othername, otheremail)
            if is_delete:
                code = "0"
                msg = "用户账号注销成功"
                logger.info("%s管理员注销%s用户成功" % (username, othername))
                # 用户删除成功时候,删除用户目录
                if User_Action.remove_user_homedir(username):
                    logger.warning("注销删除%s用户文件目录数据成功" % username)
                else:
                    logger.error("注销删除%s用户文件目录数据失败" % username)
            else:
                code = "-1"
                msg = "用户账号注销失败"
                logger.error("%s管理员注销%s用户失败" % (username, othername))
        else:
            code = "1"
            msg = "您没有权限执行操作"

    else:
        code = "-1"
        msg = "您当前不处于登录状态,请先登录"
    resp = jsonify(code=code, msg=msg)
    resp.set_cookie("datetime", getlocaltime())
    return resp
def eraseUSER():
    """ 清空redis数据并删除本地数据库用户信息,同步redis

    :return: json结果
    """
    username = request.form.get("username", type=str, default="")
    email = request.form.get("email", type=str, default="")
    captureCode = request.form.get("capture", type=str, default="")
    # 判断是否处于登录状态
    if session["isLogin"] and session.get("username") == username:
        # 判断验证码是否正确
        isConsist = DB_Sync.is_consistent(email, username)
        if captureCode == DB_Sync.query_redis_Capture(email) and isConsist:
            # 删除redis数据,然后删除本地mysql数据
            isDelete = DB_Sync.sync_redis_delete(username, email)
            if isDelete:
                code = "0"
                msg = "用户账号注销成功"
                session["isLogin"] = False
                # 清除服务器数据
                session.clear()
                logger.info("%s用户账号注销成功" % username)
                # 用户删除成功时候,删除用户目录
                if User_Action.remove_user_homedir(username):
                    logger.warning("注销删除%s用户文件目录数据成功" % username)
                else:
                    logger.error("注销删除%s用户文件目录数据失败" % username)
            else:
                code = "-1"
                msg = "用户账号注销失败"
                logger.warning("%s用户账户注销失败" % username)
        else:
            code = "-1"
            msg = "验证码不一致"
            logger.info("%s用户输入验证码不一致" % username)
    # 当前不是处于登录状态
    else:
        code = "-1"
        msg = "您当前不处于登录状态,请先登录"
        logger.warning("%s用户删除数据失败,原因:当前处于非登录状态" % username)
    resp = jsonify(code=code, msg=msg)
    resp.set_cookie("datetime", getlocaltime())
    return resp