public static String main()

in prs/webapp/src/main/java/org/netbeans/jackpot/prs/webapp/WebAppMainPage.java [46:103]


    public static String main(@Context HttpServletRequest request) {
        String userName = (String) request.getSession().getAttribute("user_name");
        if (userName != null) {
            Set<String> allowedUsers = new HashSet<>(Arrays.asList(Config.getDefault().getPreferences().node("app").get("allowed_users", "").split(",")));
            String userLogin = (String) request.getSession().getAttribute("user_login");
            if (!allowedUsers.contains(userLogin)) {
                StringBuilder page = new StringBuilder();
                page.append("<html>");
                page.append("<body>");
                page.append("    Sorry, this site is only for invited users at this point.");
                page.append("</body>");
                return page.toString();
            }
            StringBuilder page = new StringBuilder();
            page.append("<html>");
            try {
                String accessToken = (String) request.getSession().getAttribute("access_token");
                page.append("<body>");
                page.append("<script>");
                page.append("function enableDisable(repo) {");
                page.append("    var xhr = new XMLHttpRequest();");
                page.append("    xhr.open('GET', '/github/enableDisable?repo=' + repo, true);");
                page.append("    xhr.send();");
                page.append("}");
                page.append("</script>");
                page.append("    <a href=\"\">" + userName + "</a>");
                page.append("Repositories:");
                page.append("<ul>");
                GitHub github = GitHub.connectUsingOAuth(accessToken);
                Preferences repositories = Config.getDefault().getPreferences().node("users").node(userLogin).node("repositories");
                for (Entry<String, GHRepository> e : github.getMyself().getRepositories().entrySet()) {//TODO: use list
                    String checked;
                    if (repositories.getBoolean(e.getValue().getName(), false)) {
                        checked = " checked='true'";
                    } else {
                        checked = "";
                    }
                    page.append("<li><input type='checkbox' onclick='enableDisable(\"" + userLogin + "/" + e.getValue().getName() + "\")'" + checked + "/><a href=\"/github/repopullrequests?repositoryName=" + userLogin + "/" + e.getValue().getName() + "\">" + e.getValue().getName() + "</a></li>");
                }
                page.append("</ul>");
                Set<String> admins = Set.of(Config.getDefault().getPreferences().node("app").get("admins", "").split(","));
                if (admins.contains(userLogin)) {
                    page.append("Remaining rate limit: " + github.rateLimit().toString());
                }
            } catch (IOException ex) {
                //TODO: handle
                ex.printStackTrace();
            }
            page.append("</body>");
            return page.toString();
        } else {
            String clientId = Config.getDefault().getPreferences().node("app").get("client_id", null);
            return "<html>" +
                   "<body>" +
                   "    <a href=\"https://github.com/login/oauth/authorize?client_id=" + clientId + "&scope=write:repo_hook%20repo:status&state=9843759384\">Login with GitHub.</a>" +
                   "</body>";
        }
    }