def forgetPWD():
    """用户名和邮箱以及邮箱的验证码和新密码,查询本地用户名和邮箱是否对应,是发送验证码,然后检验验证码

    :return: json结果
    """
    email = request.form.get("email", type=str, default="")
    username = request.form.get("username", type=str, default="")
    captureCode = request.form.get("capture", type=str, default="")
    new_passwd = request.form.get("new_passwd", type=str, default="")
    # 本地数据库无对应数据,修改不了
    if not DB_Sync.exist_UserName_email(username, email):
        code = "-1"
        msg = "用户名或者邮箱错误"
    # 本地有数据可以修改,核对验证码
    else:
        # 判断根据邮箱查到的用户名是否一致,避免修改他人的数据
        # 验证码一致,而且email和用户名也对应.(默认不考虑用户忘记用户名的情况)
        isConsist = DB_Sync.is_consistent(email, username)
        if captureCode == DB_Sync.query_redis_Capture(email) and isConsist:
            result = DB_Sync.query_redis(username)
            # 根据用户名查询到了结果(salt)
            print(result)
            salt = result["data"]['USER_SALT']
            compute_new_pwd = computePW(new_passwd, salt)
            isOK = DB_Sync.sync_redis_insert(username, compute_new_pwd, salt,
                                             email)
            print("is ok", isOK)
            if isOK:
                code = "0"
                msg = "密码重置成功,请用新的密码登录"
                logger.info("%s用户密码修改成功" % username)
                # 修改密码后需要清除session数据
                session["isLogin"] = False
                session.clear()
                if DB_Sync.refresh_redis(username):
                    print("redis刷新成功...")
                else:
                    print("redis刷新失败...")
            else:
                code = "-1"
                msg = "密码重置失败,请重试"
                print("{0}用户重置密码失败".format(username))
                logger.error("%s用户重置密码失败" % username)
        else:
            code = "-1"
            msg = ("验证码失效" if isConsist else "用户名密码不一致")
            logger.error("%s用户重置密码失败,原因:%s" % (username, 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