@Override public void redirect(String location, int httpStatusCode) { redirected = true; delegate.redirect(location, httpStatusCode); }
@Override public void redirect(String location) { redirected = true; delegate.redirect(location); }
public ModelAndView index(Request request, Response response) { Username username = currentUsername(); if (pipelineConfigService.viewableGroupsFor(username).isEmpty() && securityService.canCreatePipelines(username)) { response.redirect("/go/admin/pipeline/new?group=defaultGroup"); return null; } HashMap<Object, Object> object = new HashMap<Object, Object>() {{ put("viewTitle", "Dashboard"); put("shouldShowAnalyticsIcon", showAnalyticsIcon()); }}; return new ModelAndView(object, "new_dashboard/index.vm"); }
@Override public void redirect(String location) { delegate.redirect(location); }
@Override public void redirect(String location, int httpStatusCode) { delegate.redirect(location, httpStatusCode); }
@Override public void redirect(String location) { redirected = true; delegate.redirect(location); }
@Override public void redirect(String location, int httpStatusCode) { redirected = true; delegate.redirect(location, httpStatusCode); }
params.put("class", new String[]{plugin.getClass().getCanonicalName()}); saveModuleWithSettings(params, page); res.redirect("/"); return null;
public static void ensureUserIsLoggedIn(Request request, Response response) { if (request.session().attribute("currentUser") == null) { request.session().attribute("loginRedirect", request.pathInfo()); response.redirect(Path.Web.LOGIN); } };
public static void ensureUserIsLoggedIn(Request request, Response response) { if (request.session().attribute("currentUser") == null) { request.session().attribute("loginRedirect", request.pathInfo()); response.redirect(Path.Web.LOGIN); } };
/** * Processes a login request. * * @param req a Spark {@link Request} * @param res a Spark {@link Response} * @return null, will redirect to main page if the login is successful, if not will, return the login compiled template with errors * @throws NoSuchAlgorithmException */ private ModelAndView login(Request req, Response res) throws NoSuchAlgorithmException { String username = req.queryParams("username"); String password = req.queryParams("password"); String hash = hashPassword(username, password); try { if (checkPassword(hash)) { logger.info("Logging in successful, redirecting to main"); Session session = req.session(true); session.attribute(AUTH_KEY, hash); res.cookie(AUTH_KEY, hash, 31557600);//one year res.redirect("/"); return null; } } catch (Exception e) { logger.error("Logging in failed due to some error", e); } Map<String, String> error = new HashMap<String, String>(); error.put("error", "Wrong username/password"); return new ModelAndView(error, "login"); }
@Override public Object adapt(int code, SparkWebContext context) { logger.debug("requires HTTP action: {}", code); if (code == HttpConstants.UNAUTHORIZED) { stop(HttpConstants.UNAUTHORIZED, "authentication required"); } else if (code == HttpConstants.FORBIDDEN) { stop(HttpConstants.FORBIDDEN, "forbidden"); } else if (code == HttpConstants.OK) { stop(HttpConstants.OK, context.getSparkResponse().body()); } else if (code == HttpConstants.NO_CONTENT) { stop(HttpConstants.NO_CONTENT, ""); } else if (code == HttpConstants.TEMP_REDIRECT) { context.getSparkResponse().redirect(context.getLocation()); } return null; }
public void defineEndpoints() { /** * Settings page */ Spark.get("/settings", this::getSettingsPage, new HomeDashTemplateEngine()); Spark.post("/settings", this::saveSettings); /** * Login form */ Spark.get("/login", (req, res) -> new ModelAndView(new HashMap<String, String>(), "login"), new HomeDashTemplateEngine()); Spark.post("/login", this::login, new HomeDashTemplateEngine()); Spark.get("/export-config", this::exportConfig); /** * Loging out ! */ Spark.get("/logout", (req, res) -> { res.removeCookie(AUTH_KEY); req.session().removeAttribute(AUTH_KEY); res.redirect("/"); return null; }); }
response.redirect("/api/help"); return response; });
before((request, response) -> { if (!request.pathInfo().endsWith("/")) { response.redirect(request.pathInfo() + "/");