package data;

import util.UserAuthUtil;

/** Class to build Login/Logout response objects in JSON format */
public class ResponseBuilder {
  /**
   * @param isLoggedIn user login status
   * @param redirectURL URL to redirect after login/logout
   * @return JSON string with login/logout URL
   *         e.g., logged in: { "isLoggedIn":{"/_ah/logout?continue=%2FLogin"}, "isLoggedOut":{""}}
   *         logged out: { "isLoggedIn":{""}, "isLoggedOut":{"/_ah/login?continue=%2FLogin"}}
   */
  public static String toJson(boolean isLoggedIn, String redirectURL) {
    return "{ \"isLoggedIn\":{\"" + buildLogout(isLoggedIn, redirectURL) + "\"}, " +
            "\"isLoggedOut\":{\"" + buildLogin(isLoggedIn, redirectURL) + "\"}}";
  }

  private static String buildLogin(boolean isLoggedIn, String redirectURL) {
    return isLoggedIn ? "" : UserAuthUtil.getLoginURL(redirectURL);
  }

  private static String buildLogout(boolean isLoggedIn, String redirectURL) {
    return isLoggedIn ? UserAuthUtil.getLogoutURL(redirectURL) : "";
  }
}

@@ -332,16 +332,29 @@
 gedIn%22:%7B
+%22loginURL%22 : 
 %22/_ah/lo
@@ -460,16 +460,30 @@
 edOut%22:%7B
+%22logoutURL%22 : 
 %22/_ah/lo
@@ -862,16 +862,35 @@
 n ? %22%22 :
+ %22%5C%22loginURL%5C%22 :%22 +
  UserAut
@@ -1027,16 +1027,36 @@
 ggedIn ?
+ %22%5C%22logoutURL%5C%22 :%22 +
  UserAut

Add key for JSON string