当前位置: 首页>>代码示例>>Java>>正文


Java Results.forbidden方法代码示例

本文整理汇总了Java中play.mvc.Results.forbidden方法的典型用法代码示例。如果您正苦于以下问题:Java Results.forbidden方法的具体用法?Java Results.forbidden怎么用?Java Results.forbidden使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在play.mvc.Results的用法示例。


在下文中一共展示了Results.forbidden方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: foundNewspaper

import play.mvc.Results; //导入方法依赖的package包/类
public Result foundNewspaper(String region) throws SQLException {
	Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
	if (ret != null) {
		return ret;
	}
	String nation = Utils.sanitizeName(Utils.getPostValue(request(), "nation"));
	final int regionId = getDatabase().getRegionId(region);

	Map<String, Object> results = new HashMap<String, Object>(1);
	Utils.handleDefaultPostHeaders(request(), response());
	try (Connection conn = getConnection()) {
		try (PreparedStatement newspaper = conn.prepareStatement("SELECT id FROM assembly.newspapers WHERE region = ? AND disbanded = 0")) {
			newspaper.setInt(1, regionId);
			try (ResultSet result = newspaper.executeQuery()) {
				if (result.next()) {
					return Results.forbidden();
				}
			}
		}

		try (PreparedStatement select = conn.prepareStatement("SELECT delegate, founder FROM assembly.region WHERE name = ?")) {
			select.setString(1, region);
			try (ResultSet result = select.executeQuery()) {
				boolean regionAdministrator = false;
				if (result.next()) {
					Logger.info("Attempting to found paper for " + region + ", nation: " + nation);
					Logger.info("Delegate: " + result.getString("delegate") + " | Founder: " + result.getString("founder"));
					if (nation.equals(result.getString("delegate")) || nation.equals(result.getString("founder"))) {
						regionAdministrator = true;
					}
				} else {
					Logger.info("Attempting to found paper for " + region + ", no region found!");
				}
				
				if (!regionAdministrator) {
					return Results.unauthorized("You are not a regional administrator");
				}
			}
		}
		final int newspaperId;
		try (PreparedStatement newspaper = conn.prepareStatement("INSERT INTO assembly.newspapers (region, editor, title, byline) VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
			newspaper.setInt(1, regionId);
			newspaper.setString(2, nation);
			newspaper.setString(3, Utils.formatName(nation) + " Regional News");
			newspaper.setString(4, Utils.formatName(nation) + " makes the trains run on time!");
			newspaper.executeUpdate();
			ResultSet keys = newspaper.getGeneratedKeys();
			keys.next();
			newspaperId = keys.getInt(1);
		}

		results.put("newspaper_id", newspaperId);
		
		try (PreparedStatement editors = conn.prepareStatement("INSERT INTO assembly.newspaper_editors (newspaper, nation_id) VALUES (?, ?)")) {
			editors.setInt(1, newspaperId);
			editors.setInt(2, getDatabase().getNationId(nation));
			editors.executeUpdate();
		}
	}
	return Results.ok(Json.toJson(results)).as("application/json");
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:62,代码来源:NewspaperController.java

示例2: disbandNewspaper

import play.mvc.Results; //导入方法依赖的package包/类
public Result disbandNewspaper(String region) throws SQLException {
	Result ret = Utils.validateRequest(request(), response(), getAPI(), getDatabase());
	if (ret != null) {
		return ret;
	}
	final String nation = Utils.getPostValue(request(), "nation");
	final int regionId = getDatabase().getRegionId(region);
	
	Utils.handleDefaultPostHeaders(request(), response());
	try (Connection conn = getConnection()) {
		try (PreparedStatement newspaper = conn.prepareStatement("SELECT id FROM assembly.newspapers WHERE region = ? AND disbanded = 0")) {
			newspaper.setInt(1, regionId);
			try (ResultSet result = newspaper.executeQuery()) {
				if (!result.next()) {
					return Results.forbidden();
				}
			}
		}

		try (PreparedStatement select = conn.prepareStatement("SELECT delegate, founder FROM assembly.region WHERE id = ?")) {
			select.setInt(1, regionId);
			try (ResultSet result = select.executeQuery()) {
				boolean regionAdministrator = false;
				if (result.next()) {
					if (nation.equals(result.getString("delegate")) || nation.equals(result.getString("founder"))) {
						regionAdministrator = true;
					}
				}
				if (!regionAdministrator) {
					return Results.unauthorized();
				}
			}
		}

		try (PreparedStatement newspaper = conn.prepareStatement("UPDATE assembly.newspapers SET disbanded = 1 WHERE region = ?")) {
			newspaper.setInt(1, regionId);
			newspaper.executeUpdate();
		}
	}
	return Results.ok();
}
 
开发者ID:NationStates,项目名称:NationStatesPlusPlus,代码行数:42,代码来源:NewspaperController.java

示例3: receiveData

import play.mvc.Results; //导入方法依赖的package包/类
private Result receiveData() {
    if (!enabled.get()) {
        return Results.forbidden(
                        "UI server remote listening is currently disabled. Use UIServer.getInstance().enableRemoteListener()");
    }

    if (statsStorage == null) {
        return Results.internalServerError(
                        "UI Server remote listener: no StatsStorage instance is set/available to store results");
    }

    JsonNode jn = request().body().asJson();
    JsonNode type = jn.get("type");
    JsonNode dataClass = jn.get("class");
    JsonNode data = jn.get("data");

    if (type == null || dataClass == null || data == null) {

        log.warn("Received incorrectly formatted data from remote listener (has type = " + (type != null)
                        + ", has data class = " + (dataClass != null) + ", has data = " + (data != null) + ")");
        return Results.badRequest("Received incorrectly formatted data");
    }

    String dc = dataClass.asText();
    String content = data.asText();

    switch (type.asText().toLowerCase()) {
        case "metadata":
            StorageMetaData meta = getMetaData(dc, content);
            if (meta != null) {
                statsStorage.putStorageMetaData(meta);
            }
            break;
        case "staticinfo":
            Persistable staticInfo = getPersistable(dc, content);
            if (staticInfo != null) {
                statsStorage.putStaticInfo(staticInfo);
            }
            break;
        case "update":
            Persistable update = getPersistable(dc, content);
            if (update != null) {
                statsStorage.putUpdate(update);
            }
            break;
        default:

    }

    return Results.ok("Receiver got data: ");
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:52,代码来源:RemoteReceiverModule.java


注:本文中的play.mvc.Results.forbidden方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。