| Code with Finding: |
class ServerInputProcessor {
private void processRemoveParticipants() throws ConnectionException {
Connection conn = DBManager.getConnection();
String command = participantsError(conn);
if (!command.equals("")) {
sendWithNonce(command);
} else {
String board = currentPath[0];
String region = currentPath[1];
List<String> removables = DatabaseAdmin.getParticipantsOne(
conn, board, region);
List<String> usersToRemove = null;
// Validity check
command = "";
boolean validParticip = false;
while (!validParticip) {
command += SocialNetworkAdmin.displayRemoveParticip(conn, board, region);
sendWithNonce(command);
String input = recvWithNonce().toLowerCase();
if (input.equals("cancel")) {
sendWithNonce(CANCEL);
return;
}
usersToRemove = Arrays.asList(Utils.getValue(input).split(" *, *"));
validParticip = removables.containsAll(usersToRemove);
if (!validParticip) {
command = "print You do not have permission to remove all the " +
"users you specified.;print ;";
}
}
// Participants to remove are valid
command = "";
for (String u: usersToRemove) {
command += SocialNetworkAdmin.removeParticipant(conn, board, region, u);
}
sendWithNonce(command);
}
DBManager.closeConnection(conn);
}
}
class ServerInputProcessor {
private void processPost() throws ConnectionException {
/* Verify the user is in the right place to create a post */
String boardName = currentPath[0];
boolean canPost = false;
if (boardName == null) {
sendWithNonce("print Must be within a board's region or in the freeforall board to create a post");
} else if (boardName.equals("freeforall")) {
String postNum = currentPath[1];
if (postNum == null) {
canPost = true;
} else {
sendWithNonce("print Must go back to the board page to create a post (not inside a post)");
}
} else { // in a regular board
String regionName = currentPath[1];
if (regionName == null) {
sendWithNonce("print Must be within a board's region or in the freeforall board to create a post");
} else {
String postNum = currentPath[2];
if (postNum == null) { // in a board, region, not in a post
canPost = true;
} else {
sendWithNonce("print Must go back to the region page to create a post (not inside a post)");
}
}
}
if (canPost) {
//AUTHORIZATION FUNCTION and EXISTS CHECK
String authToPost = SocialNetworkPosts.authorizedToPost(user, currentPath[0], currentPath[1]);
if (!authToPost.equals("true")) {
sendWithNonce(authToPost);
return ;
}
sendWithNonce("print Start typing your content. Type 'cancel' after any new line to cancel.;print "
+ "Press enter once to insert a new line.;print Press enter twice to submit.;askForInput ");
String content = recvWithNonce();
while (content.equals("")) {
sendWithNonce("print Content is empty. Please try again. Type 'cancel' to cancel.;askForInput ");
content = recvWithNonce();
}
boolean cancelled = content.trim().equals("cancel");
String additionalContent = "";
while (!cancelled) {
sendWithNonce("print ;askForInput ");
additionalContent = recvWithNonce();
if (additionalContent.equals("")) {
break;
} else if (additionalContent.trim().equals("cancel")) {
cancelled = true;
} else {
content += ";print \t" + additionalContent;
}
}
if (cancelled) {
sendWithNonce("print Post Creation cancelled");
} else {
sendWithNonce(SocialNetworkPosts.createPost(user, content,
currentPath[0], currentPath[1]));
}
}
}
}
|