");
out.print("");
if (type.charAt(0) == 'f') {
out.print("
");
} else if (type.charAt(0) == 'v') {
out.print("
");
} else if (type.charAt(0) == 'x') {
out.print("
");
}
out.println(account + "
");
out.println("" + rb.getString("Link with existing") + "
");
out.println("");
out.println("
");
out.println("" + rb.getString("Create new") + "
");
out.println("");
out.println("");
PageTemplates.pageFooter(request, out, locale, visitor, false);
PageTemplates.pageEnd(out);
} finally {
out.close();
}
}
protected void doPost(Connection sql, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
com.juick.User visitor = Utils.getVisitorUser(sql, request, response);
int uid = 0;
String type = request.getParameter("type");
String hash = request.getParameter("hash");
if (type == null || type.isEmpty() || hash == null || hash.isEmpty() || hash.length() > 36 || !type.matches("^[a-zA-Z0-9\\-]+$") || !hash.matches("^[a-zA-Z0-9\\-]+$")) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
String action = request.getParameter("action");
if (action.charAt(0) == 'l') {
if (visitor == null) {
String username = request.getParameter("username");
String password = request.getParameter("password");
if (username == null || password == null || username.length() > 32 || password.isEmpty()) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
uid = com.juick.server.UserQueries.checkPassword(sql, username, password);
} else {
uid = visitor.UID;
}
if (uid <= 0) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
if (!(type.charAt(0) == 'f' && setFacebookUser(sql, hash, uid))
&& !(type.charAt(0) == 'v' && setVKUser(sql, hash, uid))
&& !(type.charAt(0) == 'x' && setJIDUser(sql, hash, uid))) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
} else { // Create new account
String username = request.getParameter("username");
String password = request.getParameter("password");
String lang = request.getParameter("lang");
if (username == null || password == null || lang == null || username.length() < 2 || username.length() > 16 || !username.matches("^[a-zA-Z0-9\\-]+$") || password.length() < 6 || password.length() > 32 || lang.length() != 2) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
return;
}
// CHECK USERNAME
uid = UserQueries.createUser(sql, username, password, lang);
if (uid <= 0) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
if (!(type.charAt(0) == 'f' && setFacebookUser(sql, hash, uid))
&& !(type.charAt(0) == 'v' && setVKUser(sql, hash, uid))
&& !(type.charAt(0) == 'x' && setJIDUser(sql, hash, uid))) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
visitor = null;
}
if (visitor == null) {
hash = com.juick.server.UserQueries.getHashByUID(sql, uid);
Cookie c = new Cookie("hash", hash);
c.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(c);
}
response.sendRedirect("/");
}
private String getFacebookNameByHash(Connection sql, String hash) {
String ret = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = sql.prepareStatement("SELECT fb_name,fb_link FROM facebook WHERE loginhash=?");
stmt.setString(1, hash);
rs = stmt.executeQuery();
if (rs.first()) {
ret = "