/**
   * Generates the error json required for ajax calls calls when the user is not authenticated
   *
   * @return
   */
  protected static Promise<Result> notAuthenticatedResult(Http.Context ctx) {
    Http.Request req = ctx.request();
    Result result;

    if (req.accepts("text/html")) {
      ctx.flash().put("error", play.i18n.Messages.get("securesocial.loginRequired"));
      ctx.session().put(ORIGINAL_URL, ctx.request().uri());
      result = redirect(env().routes().loginPageUrl(ctx._requestHeader()));
    } else if (req.accepts("application/json")) {
      ObjectNode node = Json.newObject();
      node.put("error", "Credentials required");
      result = unauthorized(node);
    } else {
      result = unauthorized("Credentials required");
    }
    return Promise.pure(result);
  }
Esempio n. 2
0
 public static Result hello() {
   return ok(play.i18n.Messages.get("hello"));
 }