2017-05-26 18:49:27 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
using System.Text.RegularExpressions;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using SharedLibrary;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace MessageBoard.Forum
|
|
|
|
|
{
|
|
|
|
|
public class Manager
|
|
|
|
|
{
|
|
|
|
|
private List<IPage> forumPages;
|
|
|
|
|
private List<Session> activeSessions;
|
|
|
|
|
private Storage.Database database;
|
|
|
|
|
|
|
|
|
|
private const int MAX_SESSIONS = 64;
|
|
|
|
|
public const int TITLE_MAXLENGTH = 30;
|
|
|
|
|
public const int CONTENT_MAXLENGTH = 8192;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public const int USERNAME_MAXLENGTH = 30;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public const int PASSWORD_MAXLENGTH = 64;
|
|
|
|
|
|
|
|
|
|
public Rank guestRank;
|
|
|
|
|
public Rank UserRank;
|
|
|
|
|
public Rank ModRank;
|
|
|
|
|
public Rank AdminRank;
|
|
|
|
|
|
|
|
|
|
public enum ErrorCode
|
|
|
|
|
{
|
|
|
|
|
NO_ERROR,
|
|
|
|
|
GLOBAL_PERMISSIONDENIED,
|
|
|
|
|
USER_DUPLICATE,
|
|
|
|
|
USER_INVALID,
|
|
|
|
|
USER_BADCREDENTIALS,
|
|
|
|
|
USER_EMPTYCREDENTIALS,
|
|
|
|
|
USER_NOTAUTHORIZED,
|
|
|
|
|
USER_PASSWORDTOOLONG,
|
|
|
|
|
USER_USERNAMETOOLONG,
|
2017-05-27 00:22:50 -04:00
|
|
|
|
USER_BADPROFILEDATA,
|
2017-05-26 18:49:27 -04:00
|
|
|
|
SESSION_INVALID,
|
|
|
|
|
THREAD_BADDATA,
|
|
|
|
|
THREAD_EMPTYDATA,
|
|
|
|
|
THREAD_CONTENTTOOLONG,
|
|
|
|
|
THREAD_TITLETOOLONG,
|
|
|
|
|
THREAD_INVALID,
|
|
|
|
|
REPLY_SAVEFAILED,
|
|
|
|
|
CATEGORY_INVALID,
|
2017-05-27 00:22:50 -04:00
|
|
|
|
CATEGORY_EMPTY,
|
|
|
|
|
USER_MISMATCHEDPASSWORD
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Manager()
|
|
|
|
|
{
|
|
|
|
|
forumPages = new List<IPage>();
|
|
|
|
|
activeSessions = new List<Session>();
|
2017-11-14 16:36:55 -05:00
|
|
|
|
database = new Storage.Database("Database/forum.db", null);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void startSession(string sessionID)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Session newSession = getSession(sessionID);
|
|
|
|
|
newSession.sessionStartTime = DateTime.Now;
|
|
|
|
|
addSession(newSession);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.SessionException)
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
//Console.WriteLine("No session was found so we are adding a new one");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
Session newSession = new Session(new User(), sessionID);
|
|
|
|
|
addSession(newSession);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Session getSession(string sessionID)
|
|
|
|
|
{
|
|
|
|
|
Session requestedSession = activeSessions.Find(sess => sess.sessionID == sessionID);
|
|
|
|
|
|
|
|
|
|
if (requestedSession == null)
|
|
|
|
|
requestedSession = database.getSession(sessionID);
|
|
|
|
|
|
|
|
|
|
if (requestedSession == null)
|
|
|
|
|
throw new Exceptions.SessionException("Session not found");
|
|
|
|
|
|
|
|
|
|
return requestedSession;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public User getUser(int userID)
|
|
|
|
|
{
|
|
|
|
|
User requestedUser = database.getUser(userID);
|
|
|
|
|
|
|
|
|
|
if (requestedUser == null)
|
|
|
|
|
throw new Exceptions.UserException("User not found");
|
|
|
|
|
|
|
|
|
|
return requestedUser;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public User getUser(string username)
|
|
|
|
|
{
|
|
|
|
|
User requestedUser = database.getUser(username);
|
|
|
|
|
|
|
|
|
|
if (requestedUser == null)
|
|
|
|
|
throw new Exceptions.UserException("User not found");
|
|
|
|
|
|
|
|
|
|
return requestedUser;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public ForumThread getThread(int threadID)
|
|
|
|
|
{
|
|
|
|
|
ForumThread requestedThread = database.getThread(threadID);
|
|
|
|
|
|
|
|
|
|
if (requestedThread == null)
|
|
|
|
|
throw new Exceptions.ThreadException("Thread not found");
|
|
|
|
|
|
|
|
|
|
return requestedThread;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Post getPost(int postID)
|
|
|
|
|
{
|
|
|
|
|
Post requestedPost = database.getReply(postID);
|
|
|
|
|
|
|
|
|
|
if (requestedPost == null)
|
|
|
|
|
throw new Exceptions.ThreadException("Post not found");
|
|
|
|
|
|
|
|
|
|
return requestedPost;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Post> getReplies(int threadID)
|
|
|
|
|
{
|
|
|
|
|
return database.getRepliesFromThreadID(threadID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Post getReply(int replyID)
|
|
|
|
|
{
|
|
|
|
|
Post reply = database.getReply(replyID);
|
|
|
|
|
|
|
|
|
|
if (reply == null)
|
|
|
|
|
throw new Exceptions.ThreadException("Reply not found");
|
|
|
|
|
|
|
|
|
|
return reply;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ErrorCode addPost(ForumThread parentThread, Post newPost)
|
|
|
|
|
{
|
|
|
|
|
int addedPost = database.addReply(newPost);
|
|
|
|
|
if (addedPost > 0)
|
|
|
|
|
{
|
|
|
|
|
parentThread.replies++;
|
|
|
|
|
parentThread.updatedDate = DateTime.Now;
|
|
|
|
|
database.updateThread(parentThread);
|
|
|
|
|
database.updateUser(newPost.author);
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode.REPLY_SAVEFAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ErrorCode addSession(Session sess)
|
|
|
|
|
{
|
|
|
|
|
if (activeSessions.Count >= MAX_SESSIONS)
|
|
|
|
|
activeSessions.RemoveAt(0);
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
activeSessions.RemoveAll(x => x.sessionUser.ranking.name == "Guest" && x.sessionID == sess.sessionID);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
//Console.WriteLine(String.Format("Adding new session [{0}] [{1}]", sess.sessionID, sess.sessionUser.username));
|
|
|
|
|
|
|
|
|
|
if (activeSessions.Find(x => x.sessionID == sess.sessionID) == null)
|
|
|
|
|
activeSessions.Add(sess);
|
|
|
|
|
|
|
|
|
|
// if it's a guest session, we don't want to save them in the database...
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (sess.sessionUser.ranking.name != "Guest")
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
database.setSession(sess.sessionUser.id, sess.sessionID);
|
|
|
|
|
sess.sessionUser.lastLogin = DateTime.Now;
|
|
|
|
|
database.updateUser(sess.sessionUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeSession(string sessID)
|
|
|
|
|
{
|
|
|
|
|
activeSessions.RemoveAll(x => x.sessionID == sessID);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
database.removeSession(sessID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ProfileSettings getProfileSettings(int userid)
|
|
|
|
|
{
|
|
|
|
|
var retrieved = database.getProfileSettings(userid);
|
|
|
|
|
if (retrieved == null)
|
|
|
|
|
{
|
|
|
|
|
if (userid > 0)
|
|
|
|
|
{
|
|
|
|
|
var profile = new ProfileSettings(userid);
|
|
|
|
|
database.addProfileSettings(profile);
|
|
|
|
|
return profile;
|
|
|
|
|
}
|
|
|
|
|
return new ProfileSettings(0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return retrieved;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ErrorCode addUser(User newUser, Session userSession)
|
|
|
|
|
{
|
|
|
|
|
if (database.userExists(newUser.username, newUser.email))
|
|
|
|
|
return ErrorCode.USER_DUPLICATE;
|
|
|
|
|
|
|
|
|
|
// first added user is going to be admin
|
|
|
|
|
if (database.getNumUsers() == 0)
|
|
|
|
|
newUser.ranking = AdminRank;
|
|
|
|
|
|
|
|
|
|
User createdUser = database.addUser(newUser, userSession);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
database.addProfileSettings(new ProfileSettings(createdUser.id));
|
|
|
|
|
removeSession(userSession.sessionID);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return addSession(new Session(createdUser, userSession.sessionID));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateUser(User updatedUser)
|
|
|
|
|
{
|
|
|
|
|
database.updateUser(updatedUser);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public void updateUserProfile(ProfileSettings updatedUserProfile)
|
|
|
|
|
{
|
|
|
|
|
database.updateProfileSettings(updatedUserProfile);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public ErrorCode updateThread(ForumThread newThread)
|
|
|
|
|
{
|
|
|
|
|
if (database.updateThread(newThread))
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
return ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ErrorCode updateReply(Post updatedReply)
|
|
|
|
|
{
|
|
|
|
|
if (database.updateReply(updatedReply))
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
else
|
|
|
|
|
return ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ErrorCode addThread(ForumThread newThread)
|
|
|
|
|
{
|
|
|
|
|
if (database.addThread(newThread) > 0)
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
else
|
|
|
|
|
return ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ErrorCode authorizeUser(string username, string password, string sessionID)
|
|
|
|
|
{
|
2017-10-03 19:17:35 -04:00
|
|
|
|
User toAuth = database.getUser(username);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (toAuth == null)
|
|
|
|
|
return ErrorCode.USER_BADCREDENTIALS;
|
|
|
|
|
|
|
|
|
|
bool validCredentials = Encryption.PasswordHasher.VerifyPassword(password, Convert.FromBase64String(toAuth.getPasswordSalt()), Convert.FromBase64String(toAuth.getPasswordHash()));
|
|
|
|
|
|
|
|
|
|
if (!validCredentials)
|
|
|
|
|
return ErrorCode.USER_BADCREDENTIALS;
|
|
|
|
|
|
|
|
|
|
addSession(new Session(toAuth, sessionID));
|
|
|
|
|
return ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Category> getAllCategories()
|
|
|
|
|
{
|
|
|
|
|
return database.getAllCategories();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ForumThread> getRecentThreads(int catID)
|
|
|
|
|
{
|
|
|
|
|
return database.getRecentThreads(catID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<ForumThread> getCategoryThreads(int categoryID)
|
|
|
|
|
{
|
|
|
|
|
return database.getCategoryThreads(categoryID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Category getCategory(int id)
|
|
|
|
|
{
|
|
|
|
|
Category cat = database.getCategory(id);
|
|
|
|
|
|
|
|
|
|
if (cat == null)
|
|
|
|
|
throw new Exceptions.CategoryException("Category not found");
|
|
|
|
|
|
|
|
|
|
return cat;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Session> getSessions()
|
|
|
|
|
{
|
|
|
|
|
return activeSessions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
var login = new Pages.Login();
|
|
|
|
|
var loginJSON = new Pages.LoginJSON();
|
|
|
|
|
var register = new Pages.Register();
|
|
|
|
|
var registerJSON = new Pages.RegisterJSON();
|
|
|
|
|
var userinfoJSON = new Pages.userinfoJSON();
|
|
|
|
|
var viewUser = new Pages.ViewUser();
|
2017-05-27 00:22:50 -04:00
|
|
|
|
var userCP = new Pages.UserCP();
|
|
|
|
|
var updateUserJSON = new Pages.updateUserJSON();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var categoriesJSON = new Pages.categoriesJSON();
|
|
|
|
|
var category = new Pages.ViewCategory();
|
|
|
|
|
var categorythreadsJSON = new Pages.categorythreadsJSON();
|
|
|
|
|
var home = new Pages.Home();
|
|
|
|
|
var recentthreadsJSON = new Pages.recentthreadsJSON();
|
|
|
|
|
var postthread = new Pages.PostThread();
|
|
|
|
|
var postthreadJSON = new Pages.postthreadJSON();
|
|
|
|
|
var editthreadJSON = new Pages.editthreadJSON();
|
|
|
|
|
var threadJSON = new Pages.threadJSON();
|
|
|
|
|
var viewthread = new Pages.ViewThread();
|
|
|
|
|
var logout = new Pages.LogOut();
|
|
|
|
|
var stats = new Pages.StatsJSON();
|
|
|
|
|
|
|
|
|
|
forumPages.Add(login);
|
|
|
|
|
forumPages.Add(loginJSON);
|
|
|
|
|
forumPages.Add(register);
|
|
|
|
|
forumPages.Add(registerJSON);
|
|
|
|
|
forumPages.Add(userinfoJSON);
|
|
|
|
|
forumPages.Add(viewUser);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
forumPages.Add(userCP);
|
|
|
|
|
forumPages.Add(updateUserJSON);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
forumPages.Add(categoriesJSON);
|
|
|
|
|
forumPages.Add(category);
|
|
|
|
|
forumPages.Add(categorythreadsJSON);
|
|
|
|
|
forumPages.Add(home);
|
|
|
|
|
forumPages.Add(recentthreadsJSON);
|
|
|
|
|
forumPages.Add(postthread);
|
|
|
|
|
forumPages.Add(postthreadJSON);
|
|
|
|
|
forumPages.Add(editthreadJSON);
|
|
|
|
|
forumPages.Add(threadJSON);
|
|
|
|
|
forumPages.Add(viewthread);
|
|
|
|
|
forumPages.Add(logout);
|
|
|
|
|
forumPages.Add(stats);
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
SharedLibrary.WebService.PageList.Add(login);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(loginJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(register);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(registerJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(userinfoJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(viewUser);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(userCP);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(updateUserJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(categoriesJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(category);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(categorythreadsJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(home);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(recentthreadsJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(postthread);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(postthreadJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(editthreadJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(threadJSON);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(viewthread);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(logout);
|
|
|
|
|
SharedLibrary.WebService.PageList.Add(stats);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
guestRank = database.getRank("Guest");
|
|
|
|
|
UserRank = database.getRank("User");
|
|
|
|
|
ModRank = database.getRank("Moderator");
|
|
|
|
|
AdminRank = database.getRank("Administrator");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
|
|
|
|
//session logouts
|
|
|
|
|
//checkme
|
|
|
|
|
foreach (var page in forumPages)
|
2017-06-12 13:50:00 -04:00
|
|
|
|
SharedLibrary.WebService.PageList.Remove(page);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class Pages
|
|
|
|
|
{
|
|
|
|
|
public abstract class JSONPage : IPage
|
|
|
|
|
{
|
|
|
|
|
protected Session currentSession;
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public bool Visible()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public virtual string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "/forum";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "JSONPage";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public virtual HttpResponse GetPage(System.Collections.Specialized.NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
HttpResponse resp = new HttpResponse();
|
|
|
|
|
resp.contentType = "application/json";
|
|
|
|
|
resp.additionalHeaders = new Dictionary<string,string>();
|
|
|
|
|
|
|
|
|
|
if (requestHeaders.ContainsKey("Cookie"))
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
//Console.WriteLine("JSON request contains session header - " + requestHeaders["Cookie"]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
string cookie = requestHeaders["Cookie"].Split('=')[1];
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Plugin.Main.ManagerInstance.startSession(cookie);
|
|
|
|
|
currentSession = Plugin.Main.ManagerInstance.getSession(cookie);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string sessionID = Convert.ToBase64String(Encryption.PasswordHasher.GenerateSalt());
|
|
|
|
|
resp.additionalHeaders.Add("Set-Cookie", "IW4MAdmin_ForumSession=" + sessionID + "; path=/; expires=Sat, 01 May 2025 12:00:00 GMT");
|
|
|
|
|
currentSession = new Session(new User(), sessionID);
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Plugin.Main.ManagerInstance.startSession(sessionID);
|
|
|
|
|
currentSession = Plugin.Main.ManagerInstance.getSession(sessionID);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract public class ForumPage : HTMLPage
|
|
|
|
|
{
|
|
|
|
|
public ForumPage(bool visible) : base(visible) { }
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public abstract override string GetName();
|
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/forum";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override Dictionary<string, string> GetHeaders(IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetHeaders(requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected string templatation(string bodyContent)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder S = new StringBuilder();
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(base.LoadHeader());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
S.Append(bodyContent);
|
2017-06-12 13:50:00 -04:00
|
|
|
|
S.Append(base.LoadFooter());
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
return S.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Login : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public Login() : base(true)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/login";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string,string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return templatation(LoadFile("forum\\login.html"));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Register : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public Register(): base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Register";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/register";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\register.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Home : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public Home() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - Home";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/home";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\home.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PostThread : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public PostThread() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - Post New Thread";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/postthread";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\postthread.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ViewCategory : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public ViewCategory() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - Category View";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/category";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\category.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ViewUser : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public ViewUser() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - View User";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/user";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\user.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
public class UserCP : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public UserCP() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - User Control Panel";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/usercp";
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\usercp.html");
|
2017-05-27 00:22:50 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
public class ViewThread : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public ViewThread() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - View Thread";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/thread";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
string content = LoadFile("forum\\thread.html");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LogOut : ForumPage
|
|
|
|
|
{
|
|
|
|
|
public LogOut() : base(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetName()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
return "Forum - Log Out";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/logout";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override Dictionary<string, string> GetHeaders(IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Plugin.Main.ManagerInstance.removeSession(requestHeaders["Cookie"].Split('=')[1]);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
return new Dictionary<string, string>() { { "Set-Cookie", "IW4MAdmin_ForumSession=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT" } };
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetContent(NameValueCollection querySet, IDictionary<string, string> headers)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
string content = @"<meta http-equiv='refresh' content='0; url = login' />";
|
|
|
|
|
return templatation(content);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RegisterJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_register";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
var result = new ActionResponse();
|
|
|
|
|
result.success = false;
|
2017-06-12 13:50:00 -04:00
|
|
|
|
result.destination = base.GetPath() + "/error";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
try {
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
|
|
|
|
string username = DNA.Text.TextEngine.Text(querySet["username"]);
|
|
|
|
|
string password = DNA.Text.TextEngine.Text(querySet["password"]);
|
|
|
|
|
string email = DNA.Text.TextEngine.Text(querySet["email"]);
|
|
|
|
|
|
|
|
|
|
bool validEmail = Regex.IsMatch(email,
|
|
|
|
|
@"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
|
|
|
|
|
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
|
|
|
|
|
RegexOptions.IgnoreCase) && email.Length < Manager.PASSWORD_MAXLENGTH;
|
|
|
|
|
|
|
|
|
|
if (!validEmail)
|
|
|
|
|
throw new Exceptions.UserException("Email is invalid");
|
|
|
|
|
|
|
|
|
|
if (username.Length > Manager.USERNAME_MAXLENGTH)
|
|
|
|
|
throw new Exceptions.UserException("Username is too long");
|
|
|
|
|
|
|
|
|
|
if (password.Length > Manager.PASSWORD_MAXLENGTH)
|
|
|
|
|
throw new Exceptions.UserException("Password is too long");
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
byte[] passwordSalt = Encryption.PasswordHasher.GenerateSalt();
|
2017-05-27 00:22:50 -04:00
|
|
|
|
string b64PasswordHash = Convert.ToBase64String(Encryption.PasswordHasher.ComputeHash(password, passwordSalt));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
User registeringUser = new User(username, querySet["hiddenUsername"], email, b64PasswordHash, Convert.ToBase64String(passwordSalt), Plugin.Main.ManagerInstance.UserRank);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
currentSession = new Session(registeringUser, currentSession.sessionID);
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var addUserResult = Plugin.Main.ManagerInstance.addUser(registeringUser, currentSession);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (addUserResult != Manager.ErrorCode.NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
result.errorCode = addUserResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
result.destination = base.GetPath() + "/home";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
result.success = true;
|
|
|
|
|
result.errorCode = Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
catch (Exception E)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
2017-05-26 18:49:27 -04:00
|
|
|
|
result.errorCode = Manager.ErrorCode.USER_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(result);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class userinfoJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_userinfo";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
UserInfo info = new UserInfo();
|
|
|
|
|
bool validUserSelection = true;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
int userid = Convert.ToInt32(querySet["id"]);
|
2017-06-13 18:33:47 -04:00
|
|
|
|
info.user = Plugin.Main.ManagerInstance.getUser(userid);
|
|
|
|
|
info.profile = Plugin.Main.ManagerInstance.getProfileSettings(userid);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
// logme
|
|
|
|
|
validUserSelection = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.UserException)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
validUserSelection = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (!validUserSelection)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
info.user = currentSession.sessionUser;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
info.profile = Plugin.Main.ManagerInstance.getProfileSettings(info.user.id);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.UserException)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
/*// this should not be a thing but ok...
|
|
|
|
|
Player matchedPlayer = Plugin.Main.stupidServer.clientDB.getPlayer(querySet["ip"]);
|
|
|
|
|
|
|
|
|
|
if (matchedPlayer != null)
|
|
|
|
|
info.matchedUsername = matchedPlayer.Name;*/
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(info);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class updateUserJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_updateuser";
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-27 00:22:50 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
var aResp = new ActionResponse();
|
|
|
|
|
|
|
|
|
|
bool passwordUpdateRequest = false;
|
|
|
|
|
|
|
|
|
|
if (querySet["username"] == null || currentSession.sessionUser.id == 0)
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_INVALID;
|
|
|
|
|
else if (querySet["bannercolor"] == null)
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_BADPROFILEDATA;
|
|
|
|
|
if (querySet["updatedpassword"] != null && querySet["updatedpasswordrepeat"] != null && querySet["updatedpassword"].Length > 0 && querySet["updatedpasswordrepeat"].Length > 0)
|
|
|
|
|
passwordUpdateRequest = true;
|
|
|
|
|
|
|
|
|
|
if (aResp.errorCode == Manager.ErrorCode.NO_ERROR)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
string username = DNA.Text.TextEngine.Text(querySet["username"]);
|
|
|
|
|
string bannercolor = DNA.Text.TextEngine.Text(querySet["bannercolor"]);
|
|
|
|
|
string avatarURL = DNA.Text.TextEngine.Text(querySet["avatarurl"]);
|
|
|
|
|
string password = null;
|
|
|
|
|
|
|
|
|
|
if (passwordUpdateRequest)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
password = DNA.Text.TextEngine.Text(querySet["updatedpassword"]);
|
|
|
|
|
string passwordRepeat = DNA.Text.TextEngine.Text(querySet["updatedpasswordrepeat"]);
|
|
|
|
|
if (!password.Equals(passwordRepeat))
|
|
|
|
|
{
|
|
|
|
|
password = null;
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_MISMATCHEDPASSWORD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (password.Length > Manager.PASSWORD_MAXLENGTH)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
password = null;
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_PASSWORDTOOLONG;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
User existingUser = null;
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
existingUser = Plugin.Main.ManagerInstance.getUser(username);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.UserException)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (existingUser != null && existingUser.id != currentSession.sessionUser.id)
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_DUPLICATE;
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var profile = Plugin.Main.ManagerInstance.getProfileSettings(currentSession.sessionUser.id);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (username.Length <= Manager.USERNAME_MAXLENGTH)
|
|
|
|
|
currentSession.sessionUser.updateUsername(username);
|
|
|
|
|
else
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_USERNAMETOOLONG;
|
|
|
|
|
currentSession.sessionUser.updateAvatar(avatarURL);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (passwordUpdateRequest && aResp.errorCode == Manager.ErrorCode.NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
byte[] passwordSalt = Encryption.PasswordHasher.GenerateSalt();
|
|
|
|
|
string b64PasswordHash = Convert.ToBase64String(Encryption.PasswordHasher.ComputeHash(password, passwordSalt));
|
|
|
|
|
currentSession.sessionUser.updatePassword(Convert.ToBase64String(passwordSalt), b64PasswordHash);
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Plugin.Main.ManagerInstance.updateUser(currentSession.sessionUser);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (bannercolor.Length == 7)
|
|
|
|
|
profile.bannerColor = bannercolor;
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Plugin.Main.ManagerInstance.updateUserProfile(profile);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
if (aResp.success)
|
|
|
|
|
aResp.destination = "usercp";
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
return resp;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class LoginJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_login";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ActionResponse aResp = new ActionResponse();
|
|
|
|
|
aResp.success = false;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
string username = DNA.Text.TextEngine.Text(querySet["username"]);
|
|
|
|
|
string password = DNA.Text.TextEngine.Text(querySet["password"]);
|
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var result = Plugin.Main.ManagerInstance.authorizeUser(username, password, currentSession.sessionID);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.success = result == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
aResp.errorCode = result;
|
|
|
|
|
aResp.destination = "home";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_EMPTYCREDENTIALS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class categoriesJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_categories";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var categories = Plugin.Main.ManagerInstance.getAllCategories();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categories);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class recentthreadsJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_recentthreads";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
List<HomeThread> threads = new List<HomeThread>();
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var categories = Plugin.Main.ManagerInstance.getAllCategories();
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
foreach (var t in categories)
|
|
|
|
|
{
|
|
|
|
|
if ((t.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
HomeThread thread = new HomeThread();
|
|
|
|
|
thread.categoryTitle = t.title;
|
|
|
|
|
thread.categoryDescription = t.description;
|
|
|
|
|
thread.categoryID = t.id;
|
2017-06-13 18:33:47 -04:00
|
|
|
|
thread.recentThreads = Plugin.Main.ManagerInstance.getRecentThreads(t.id);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
threads.Add(thread);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(threads);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
resp.content = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class categorythreadsJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_categorythreads";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var aResp = new ActionResponse();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var category = Plugin.Main.ManagerInstance.getCategory(Convert.ToInt32(querySet["id"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if ((category.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
|
|
|
|
throw new Exceptions.PermissionException("User cannot view this category");
|
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var categoryThreads = Plugin.Main.ManagerInstance.getCategoryThreads(category.id);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(categoryThreads);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.CATEGORY_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.CategoryException)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.CATEGORY_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.PermissionException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.GLOBAL_PERMISSIONDENIED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class threadJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_thread";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var aResp = new ActionResponse();
|
|
|
|
|
aResp.success = false;
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (querySet.Get("id") != null)
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var thread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet["id"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if ((thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
2017-05-27 00:22:50 -04:00
|
|
|
|
throw new Exceptions.PermissionException("User cannot view this post");
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var replies = Plugin.Main.ManagerInstance.getReplies(thread.id);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(new ThreadView(thread, replies));
|
|
|
|
|
aResp.success = true;
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
|
|
|
|
else if (querySet.Get("replyid") != null)
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var thread = Plugin.Main.ManagerInstance.getReply(Convert.ToInt32(querySet["replyid"]));
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
|
|
|
|
//if ((thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.READ) != Permission.Action.READ)
|
|
|
|
|
// throw new Exceptions.PermissionException("User cannot view this post");
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(thread);
|
|
|
|
|
aResp.success = true;
|
|
|
|
|
}
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.ThreadException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.PermissionException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.GLOBAL_PERMISSIONDENIED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aResp.success == false)
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class editthreadJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_editthread";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
var aResp = new ActionResponse();
|
|
|
|
|
aResp.success = false;
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (querySet.Get("id") != null)
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var thread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet["id"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (thread.author.id != currentSession.sessionUser.id && (thread.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.MODIFY) != Permission.Action.MODIFY)
|
|
|
|
|
throw new Exceptions.PermissionException("User cannot modify this post");
|
|
|
|
|
|
|
|
|
|
if (querySet.Get("delete") != null)
|
|
|
|
|
{
|
|
|
|
|
thread.visible = false;
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.updateThread(thread);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
aResp.destination = "category?id=" + thread.threadCategory.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet.Get("update") != null)
|
|
|
|
|
{
|
|
|
|
|
if (querySet.Get("content") == null || querySet.Get("title") == null)
|
|
|
|
|
throw new Exceptions.ThreadException("Invalid update data");
|
|
|
|
|
|
|
|
|
|
if (querySet.Get("content").Length > Manager.CONTENT_MAXLENGTH)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_CONTENTTOOLONG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet.Get("title").Length > Manager.TITLE_MAXLENGTH)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_TITLETOOLONG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//fixsecurity
|
2017-05-27 00:22:50 -04:00
|
|
|
|
var fmtr = new DNA.Text.BBCodeFormatter();
|
|
|
|
|
string content = fmtr.Format(Uri.UnescapeDataString(querySet["content"]));
|
|
|
|
|
string title = DNA.Text.TextEngine.Text(Uri.UnescapeDataString(querySet["title"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
if (thread.updateTitle(title) && thread.updateContent(content))
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.updateThread(thread);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
2017-05-27 00:22:50 -04:00
|
|
|
|
aResp.destination = "thread?id=" + thread.id;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_EMPTYDATA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet.Get("replyid") != null)
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var reply = Plugin.Main.ManagerInstance.getReply(Convert.ToInt32(querySet["replyid"]));
|
2017-05-27 00:22:50 -04:00
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
if (currentSession.sessionUser.id == 0 || reply.author.id != currentSession.sessionUser.id && (reply.threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.MODIFY) != Permission.Action.MODIFY)
|
|
|
|
|
throw new Exceptions.PermissionException("User cannot modify this reply");
|
|
|
|
|
|
|
|
|
|
if (querySet.Get("delete") != null)
|
|
|
|
|
{
|
|
|
|
|
reply.visible = false;
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.updateReply(reply);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
aResp.destination = "thread?id=" + reply.threadid;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
else if (querySet.Get("content") != null)
|
|
|
|
|
{
|
|
|
|
|
if (querySet.Get("content") == null || querySet.Get("title") == null)
|
|
|
|
|
throw new Exceptions.ThreadException("Invalid update data");
|
|
|
|
|
|
|
|
|
|
if (querySet.Get("content").Length > Manager.CONTENT_MAXLENGTH)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_CONTENTTOOLONG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet.Get("title").Length > Manager.TITLE_MAXLENGTH)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_TITLETOOLONG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int threadID = Convert.ToInt32(querySet["threadid"]);
|
|
|
|
|
//fixsecurity
|
|
|
|
|
var fmtr = new DNA.Text.BBCodeFormatter();
|
|
|
|
|
string content = fmtr.Format(Uri.UnescapeDataString(querySet["content"]));
|
|
|
|
|
string title = DNA.Text.TextEngine.Text(Uri.UnescapeDataString(querySet["title"]));
|
|
|
|
|
|
|
|
|
|
if (reply.updateTitle(title) && reply.updateContent(content))
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.updateReply(reply);
|
2017-05-27 00:22:50 -04:00
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
aResp.destination = "thread?id=" + threadID;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_EMPTYDATA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.ThreadException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.PermissionException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.GLOBAL_PERMISSIONDENIED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (aResp.success == false)
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class postthreadJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_postthread";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
ActionResponse aResp = new ActionResponse();
|
|
|
|
|
|
|
|
|
|
if (currentSession.sessionUser.ranking.equivalentRank < Player.Permission.Trusted)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_NOTAUTHORIZED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (querySet["content"].Length < Manager.CONTENT_MAXLENGTH && querySet["title"].Length <= Manager.TITLE_MAXLENGTH)
|
|
|
|
|
{
|
|
|
|
|
|
2017-05-27 00:22:50 -04:00
|
|
|
|
var fmtr = new DNA.Text.BBCodeFormatter();
|
|
|
|
|
string content = fmtr.Format(Uri.UnescapeDataString(querySet["content"]));
|
|
|
|
|
string title = DNA.Text.TextEngine.Text(Uri.UnescapeDataString(querySet["title"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if (querySet.Get("threadid") != null)
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
var replyThread = Plugin.Main.ManagerInstance.getThread(Convert.ToInt32(querySet.Get("threadid")));
|
2017-05-27 00:22:50 -04:00
|
|
|
|
var reply = new Post(title, replyThread.getID(), content, currentSession.sessionUser);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.addPost(replyThread, reply);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.destination = String.Format("thread?id={0}", replyThread.id);
|
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-06-13 18:33:47 -04:00
|
|
|
|
Category threadCategory = Plugin.Main.ManagerInstance.getCategory(Convert.ToInt32(querySet["category"]));
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
if ((threadCategory.permissions.Find(x => x.rankID == currentSession.sessionUser.ranking.id).actionable & Permission.Action.WRITE) == Permission.Action.WRITE)
|
|
|
|
|
{
|
2017-05-27 00:22:50 -04:00
|
|
|
|
ForumThread newThread = new ForumThread(title, content, currentSession.sessionUser, threadCategory);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
aResp.errorCode = Plugin.Main.ManagerInstance.addThread(newThread);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
aResp.destination = String.Format("category?id={0}", threadCategory.id);
|
|
|
|
|
aResp.success = aResp.errorCode == Manager.ErrorCode.NO_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.USER_NOTAUTHORIZED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if (querySet["title"].Length > Manager.TITLE_MAXLENGTH)
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_TITLETOOLONG;
|
|
|
|
|
else
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_CONTENTTOOLONG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (Exceptions.ThreadException)
|
|
|
|
|
{
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_BADDATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (NullReferenceException)
|
|
|
|
|
{
|
|
|
|
|
//logme
|
|
|
|
|
aResp.errorCode = Manager.ErrorCode.THREAD_EMPTYDATA;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(aResp);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class StatsJSON : JSONPage
|
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override string GetPath()
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
return base.GetPath() + "/_stats";
|
2017-05-26 18:49:27 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-12 13:50:00 -04:00
|
|
|
|
public override HttpResponse GetPage(NameValueCollection querySet, IDictionary<string, string> requestHeaders)
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
2017-06-12 13:50:00 -04:00
|
|
|
|
var resp = base.GetPage(querySet, requestHeaders);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
StatView stats = new StatView();
|
|
|
|
|
|
|
|
|
|
stats.onlineUsers = new List<User>();
|
|
|
|
|
|
2017-06-13 18:33:47 -04:00
|
|
|
|
foreach (Session s in Plugin.Main.ManagerInstance.getSessions())
|
2017-05-26 18:49:27 -04:00
|
|
|
|
{
|
|
|
|
|
if (s.sessionUser.ranking.id > 0 && (DateTime.Now - s.sessionStartTime).TotalMinutes < 5 && s.sessionUser.username != "Guest")
|
|
|
|
|
stats.onlineUsers.Add(s.sessionUser);
|
|
|
|
|
}
|
2017-05-27 00:22:50 -04:00
|
|
|
|
stats.onlineUsers.OrderByDescending(x => x.ranking.equivalentRank);
|
2017-05-26 18:49:27 -04:00
|
|
|
|
|
|
|
|
|
resp.content = Newtonsoft.Json.JsonConvert.SerializeObject(stats);
|
|
|
|
|
return resp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected struct StatView
|
|
|
|
|
{
|
|
|
|
|
public List<User> onlineUsers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected struct ActionResponse
|
|
|
|
|
{
|
|
|
|
|
public bool success;
|
|
|
|
|
public string destination;
|
|
|
|
|
public Manager.ErrorCode errorCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected struct HomeThread
|
|
|
|
|
{
|
|
|
|
|
public string categoryTitle;
|
|
|
|
|
public string categoryDescription;
|
|
|
|
|
public int categoryID;
|
|
|
|
|
public List<ForumThread> recentThreads;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected struct ThreadView
|
|
|
|
|
{
|
|
|
|
|
public ForumThread Thread;
|
|
|
|
|
public List<Post> Replies;
|
|
|
|
|
|
|
|
|
|
public ThreadView(ForumThread t, List<Post> r)
|
|
|
|
|
{
|
|
|
|
|
Thread = t;
|
|
|
|
|
Replies = r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|