1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-18 11:08:22 -05:00

Branch for IW4X practically everything refactored

This commit is contained in:
RaidMax
2017-05-26 17:49:27 -05:00
parent 85a658b987
commit 10075b0d3f
107 changed files with 7426 additions and 3995 deletions

View File

@ -0,0 +1,43 @@
using System;
using System.Security.Cryptography;
using System.Text;
//http://codereview.stackexchange.com/questions/96494/user-password-encryption-in-c + SCrypt
namespace MessageBoard.Encryption
{
public static class PasswordHasher
{
public static byte[] ComputeHash(string password, byte[] salt)
{
byte[] pwBytes = Encoding.UTF8.GetBytes(password);
byte[] hashBytes = new byte[64];
CryptSharp.Utility.SCrypt.ComputeKey(pwBytes, salt, 16384, 8, 1, null, hashBytes);
return hashBytes;
}
public static byte[] GenerateSalt(int saltByteSize = 24)
{
RNGCryptoServiceProvider saltGenerator = new RNGCryptoServiceProvider();
byte[] salt = new byte[saltByteSize];
saltGenerator.GetBytes(salt);
return salt;
}
public static bool VerifyPassword(String password, byte[] passwordSalt, byte[] passwordHash)
{
byte[] computedHash = ComputeHash(password, passwordSalt);
return AreHashesEqual(computedHash, passwordHash);
}
//Length constant verification - prevents timing attack
private static bool AreHashesEqual(byte[] firstHash, byte[] secondHash)
{
int minHashLength = firstHash.Length <= secondHash.Length ? firstHash.Length : secondHash.Length;
var xor = firstHash.Length ^ secondHash.Length;
for (int i = 0; i < minHashLength; i++)
xor |= firstHash[i] ^ secondHash[i];
return 0 == xor;
}
}
}

View File

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard.Events
{
public delegate void ActionEventHandler(User origin, EventArgs e);
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard.Exceptions
{
public class ThreadException : Exception
{
public ThreadException(string msg) : base(msg) { }
}
public class UserException : Exception
{
public UserException(string msg) : base(msg) { }
}
public class SessionException : Exception
{
public SessionException(string msg) : base(msg) { }
}
public class CategoryException : Exception
{
public CategoryException(string msg) : base(msg) { }
}
public class PermissionException: Exception
{
public PermissionException(string msg) : base(msg) { }
}
}

1160
MessageboardPlugin/Forum.cs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard
{
interface Identifiable
{
int getID();
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E46C85BD-A99C-484E-BCCE-0F1831C5925E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MessageBoard</RootNamespace>
<AssemblyName>MessageboardPlugin</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SharedLibrary\SharedLibrary.csproj">
<Project>{d51eeceb-438a-47da-870f-7d7b41bc24d6}</Project>
<Name>SharedLibrary</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Encryption.cs" />
<Compile Include="Events.cs" />
<Compile Include="Exceptions.cs" />
<Compile Include="Forum.cs" />
<Compile Include="Identifiable.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Rank.cs" />
<Compile Include="Session.cs" />
<Compile Include="Storage.cs" />
<Compile Include="Thread.cs" />
<Compile Include="User.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="CryptSharp">
<HintPath>..\packages\CryptSharp.1.2.0.1\lib\net35\CryptSharp.dll</HintPath>
</Reference>
<Reference Include="MarkdownDeep, Version=1.5.4615.26275, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MarkdownDeep.NET.1.5\lib\.NetFramework 3.5\MarkdownDeep.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net40\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Security" />
<Reference Include="System.XML" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="forum\category.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\home.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\login.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\postthread.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\register.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\thread.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="forum\user.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>mkdir "$(SolutionDir)Admin\bin\$(ConfigurationName)\forum"
copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Admin\bin\$(ConfigurationName)\plugins\MessageBoardPlugin.dll"
xcopy /E /Y "$(TargetDir)forum" "$(SolutionDir)Admin\bin\$(ConfigurationName)\forum"
copy /Y "$(TargetDir)MarkdownDeep.dll" "$(SolutionDir)Admin\bin\$(ConfigurationName)\lib\MarkdownDeep.dll"
copy /Y "$(TargetDir)CryptSharp.dll" "$(SolutionDir)Admin\bin\$(ConfigurationName)\lib\CryptSharp.dll"
copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)BUILD\plugins\"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,65 @@
using System;
using SharedLibrary;
using SharedLibrary.Extensions;
using System.Threading.Tasks;
namespace MessageBoard.Plugin
{
public class Main : IPlugin
{
public static Forum.Manager forum { get; private set; }
public static Server stupidServer { get; private set; }
public string Author
{
get
{
return "RaidMax";
}
}
public float Version
{
get
{
return 0.1f;
}
}
public string Name
{
get
{
return "Message Board Plugin";
}
}
public async Task OnLoad()
{
await Task.Run(() =>
{
forum = new Forum.Manager();
forum.Start();
});
}
public async Task OnUnload()
{
forum.Stop();
}
public async Task OnTick(Server S)
{
return;
}
public async Task OnEvent(Event E, Server S)
{
if (E.Type == Event.GType.Start)
{
if (stupidServer == null)
stupidServer = S;
}
}
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard
{
public class Rank : Identifiable
{
public string name;
public SharedLibrary.Player.Permission equivalentRank;
public int id;
/// <summary>
/// Initial creation
/// </summary>
/// <param name="name"></param>
/// <param name="equivalentRank"></param>
/// <param name="permissions"></param>
public Rank(string name, SharedLibrary.Player.Permission equivalentRank)
{
this.name = name;
this.equivalentRank = equivalentRank;
id = 0;
}
public Rank(int id, string name, SharedLibrary.Player.Permission equivalentRank)
{
this.name = name;
this.equivalentRank = equivalentRank;
this.id = id;
}
public int getID()
{
return id;
}
}
public class Permission
{
[Flags]
public enum Action
{
NONE = 0x0,
READ = 0x1,
WRITE = 0x2,
MODIFY = 0x4,
DELETE = 0x8
}
public int rankID;
public Action actionable;
public Permission(int rankID, Action actionable)
{
this.rankID = rankID;
this.actionable = actionable;
}
}
}

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard
{
public class Session
{
public User sessionUser;
public string sessionID { get; private set; }
public DateTime sessionStartTime;
public Session(User sessionUser, string sessionID)
{
this.sessionUser = sessionUser;
this.sessionID = sessionID;
sessionStartTime = DateTime.Now;
}
}
}

View File

@ -0,0 +1,554 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace MessageBoard.Storage
{
class Database : SharedLibrary.Database
{
public Database(String FN) : base(FN) { }
public override void Init()
{
if (!System.IO.File.Exists(FileName))
{
string createClientTable = @"CREATE TABLE [USERS] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[ranking] INTEGER DEFAULT 0,
[username] TEXT NOT NULL,
[email] TEXT NOT NULL,
[passwordhash] TEXT NOT NULL,
[passwordsalt] TEXT NOT NULL,
[lastlogin] TEXT NOT NULL,
[creationdate] TEXT NOT NULL,
[subscribedthreads] TEXT DEFAULT 0,
[avatarurl] TEXT
);";
string createSessionTable = @"CREATE TABLE [SESSIONS] (
[sessionid] TEXT NOT NULL,
[sessionuserid] INTEGER NOT NULL,
FOREIGN KEY(sessionuserid) REFERENCES USERS(id)
);";
string createRankingTable = @"CREATE TABLE [RANKS] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[name] TEXT UNIQUE NOT NULL,
[equivalentrank] INTEGER DEFAULT 0
);";
string createCategoryTable = @"CREATE TABLE [CATEGORIES] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[title] TEXT NOT NULL,
[description] TEXT NOT NULL,
[permissions] BLOB
);";
string createThreadTable = @"CREATE TABLE [THREADS] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[title] TEXT NOT NULL,
[categoryid] INTEGER NOT NULL,
[replies] INTEGER DEFAULT 0,
[authorid] INTEGER NOT NULL,
[creationdate] TEXT NOT NULL,
[updateddate] TEXT NOT NULL,
[content] TEXT NOT NULL,
[visible] INTEGER DEFAULT 1,
FOREIGN KEY(authorid) REFERENCES USERS(id),
FOREIGN KEY(categoryid) REFERENCES CATEGORIES(id)
);";
string createReplyTable = @"CREATE TABLE [REPLIES] (
[id] INTEGER PRIMARY KEY AUTOINCREMENT,
[title] TEXT NOT NULL,
[authorid] INT NOT NULL,
[threadid] INT NOT NULL,
[creationdate] TEXT NOT NULL,
[updateddate] TEXT NOT NULL,
[content] TEXT NOT NULL,
[visible] INTEGER DEFAULT 1,
FOREIGN KEY(authorid) REFERENCES USERS(id),
FOREIGN KEY(threadid) REFERENCES THREADS(id)
);";
ExecuteNonQuery(createClientTable);
ExecuteNonQuery(createSessionTable);
ExecuteNonQuery(createRankingTable);
ExecuteNonQuery(createCategoryTable);
ExecuteNonQuery(createThreadTable);
ExecuteNonQuery(createReplyTable);
Rank guestRank = new Rank(1, "Guest", SharedLibrary.Player.Permission.User);
Rank userRank = new Rank(2, "User", SharedLibrary.Player.Permission.Trusted);
Rank modRank = new Rank(3, "Moderator", SharedLibrary.Player.Permission.Moderator);
Rank adminRank = new Rank(4, "Administrator", SharedLibrary.Player.Permission.Owner);
addRank(guestRank);
addRank(userRank);
addRank(modRank);
addRank(adminRank);
List<Permission> defaultCatPerms = new List<Permission> {
new Permission(guestRank.getID(), Permission.Action.READ),
new Permission(userRank.getID(), Permission.Action.READ | Permission.Action.WRITE),
new Permission(modRank.getID(), Permission.Action.READ | Permission.Action.WRITE | Permission.Action.MODIFY),
new Permission(adminRank.getID(), Permission.Action.READ | Permission.Action.WRITE | Permission.Action.MODIFY | Permission.Action.DELETE)
};
Category defaultCat = new Category(1, "Default Category", "This is the default category.", defaultCatPerms);
addCategory(defaultCat);
}
}
#region SESSIONS
public Session getSession(string sessionID)
{
DataTable Result = GetDataTable("SESSIONS", new KeyValuePair<string, object>("sessionid", sessionID));
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
int userID = Int32.Parse(ResponseRow["sessionuserid"].ToString());
User sessionUser = getUser(userID);
// this shouldn't happen.. but it might :c
if (sessionUser == null)
return null;
Session foundSession = new Session(sessionUser, sessionID);
return foundSession;
}
else
return null;
}
public Session setSession(int userID, string sessionID)
{
// prevent duplicated tuples
if (getSession(sessionID) != null)
{
updateSession(sessionID, userID);
return getSession(sessionID);
}
Dictionary<String, object> newSession = new Dictionary<String, object>();
newSession.Add("sessionid", sessionID);
newSession.Add("sessionuserid", userID);
Insert("SESSIONS", newSession);
return getSession(sessionID);
}
public bool updateSession(string sessionID, int userID)
{
if (getSession(sessionID) == null)
return false;
Dictionary<string, object> updatedSession = new Dictionary<string, object>();
updatedSession.Add("sessionuserid", userID);
Update("SESSIONS", updatedSession, new KeyValuePair<string, object>("sessionid", sessionID));
return true;
}
#endregion
#region USERS
private User getUserFromDataTable(DataTable Result)
{
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
int id = Convert.ToInt32(ResponseRow["id"].ToString());
string passwordHash = ResponseRow["passwordhash"].ToString();
string passwordSalt = ResponseRow["passwordsalt"].ToString();
string username = ResponseRow["username"].ToString();
string email = ResponseRow["email"].ToString();
DateTime lastLogon = DateTime.Parse(ResponseRow["lastlogin"].ToString());
DateTime creationDate = DateTime.Parse(ResponseRow["creationdate"].ToString());
Rank ranking = getRank(Convert.ToInt32(ResponseRow["ranking"]));
string avatarURL = ResponseRow["avatarurl"].ToString();
string posts = GetDataTable(String.Format("select (select count(*) from THREADS where authorid = {0}) + (select count(*) from REPLIES where authorid = {0}) as posts;", id)).Rows[0]["posts"].ToString();
User foundUser = new User(id, passwordHash, passwordSalt, username, email, Convert.ToInt32(posts), lastLogon, creationDate, ranking, avatarURL);
return foundUser;
}
return null;
}
private Dictionary<string, object> getDataTableFromUser(User addedUser)
{
Dictionary<String, object> newUser = new Dictionary<String, object>();
newUser.Add("username", addedUser.username);
newUser.Add("email", addedUser.email);
newUser.Add("passwordhash", addedUser.getPasswordHash());
newUser.Add("passwordsalt", addedUser.getPasswordSalt());
newUser.Add("lastlogin", SharedLibrary.Utilities.DateTimeSQLite(addedUser.lastLogin));
newUser.Add("creationdate", SharedLibrary.Utilities.DateTimeSQLite(addedUser.creationDate));
//newUser.Add("subscribedthreads", String.Join<int>(",", addedUser.subscribedThreads));
newUser.Add("ranking", addedUser.ranking.getID());
newUser.Add("avatarurl", addedUser.avatarURL);
return newUser;
}
public User getUser(int userid)
{
DataTable Result = GetDataTable("USERS", new KeyValuePair<string, object>("id", userid));
return getUserFromDataTable(Result);
}
public User getUser(string username)
{
DataTable Result = GetDataTable("USERS", new KeyValuePair<string, object>("username", username));
return getUserFromDataTable(Result);
}
public bool userExists(string username, string email)
{
String Query = String.Format("SELECT * FROM USERS WHERE username = '{0}' or email = '{1}'", username, email);
DataTable Result = GetDataTable(Query);
return Result.Rows.Count > 0;
}
/// <summary>
/// Returns ID of added user
/// </summary>
/// <param name="addedUser"></param>
/// <param name="userSession"></param>
/// <returns></returns>
public User addUser(User addedUser, Session userSession)
{
var newUser = getDataTableFromUser(addedUser);
Insert("USERS", newUser);
// fixme
User createdUser = getUser(addedUser.username);
return createdUser;
}
public bool updateUser(User updatedUser)
{
var user = getDataTableFromUser(updatedUser);
Update("USERS", user, new KeyValuePair<string, object>("id", updatedUser.getID()));
return true;
}
public int getNumUsers()
{
var Result = GetDataTable("SELECT COUNT(id) AS userCount FROM `USERS`;");
return Convert.ToInt32(Result.Rows[0]["userCount"]);
}
#endregion
#region CATEGORIES
private Category getCategoryFromDataTable(DataTable Result)
{
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
int id = Convert.ToInt32(ResponseRow["id"]);
string title = ResponseRow["title"].ToString();
string description = ResponseRow["description"].ToString();
string permissions = Encoding.UTF8.GetString((byte[])ResponseRow["permissions"]);
List<Permission> perms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Permission>>(permissions);
Category requestedCategory = new Category(id, title, description, perms);
return requestedCategory;
}
return null;
}
public void addCategory(Category addingCategory)
{
Dictionary<String, object> newCategory = new Dictionary<string, object>();
newCategory.Add("title", addingCategory.title);
newCategory.Add("description", addingCategory.description);
newCategory.Add("permissions", Newtonsoft.Json.JsonConvert.SerializeObject(addingCategory.permissions));
Insert("CATEGORIES", newCategory);
}
public Category getCategory(int id)
{
string Query = String.Format("SELECT * FROM CATEGORIES WHERE id = {0}", id);
DataTable Result = GetDataTable(Query);
return getCategoryFromDataTable(Result);
}
public List<Category> getAllCategories()
{
string Query = String.Format("SELECT id FROM CATEGORIES");
List<Category> cats = new List<Category>();
DataTable Result = GetDataTable(Query);
if (Result != null && Result.Rows.Count > 0)
{
for (int i = 0; i < Result.Rows.Count; i++)
cats.Add(getCategory(Convert.ToInt32(Result.Rows[i]["id"])));
}
return cats;
}
#endregion
#region THREADS
public Dictionary<string, object> getDataTableFromThread(ForumThread Thread)
{
Dictionary<string, object> newThread = new Dictionary<string, object>();
newThread.Add("title", Thread.title);
newThread.Add("categoryid", Thread.threadCategory.getID());
newThread.Add("replies", Thread.replies);
newThread.Add("authorid", Thread.author.getID());
newThread.Add("creationdate", SharedLibrary.Utilities.DateTimeSQLite(Thread.creationDate));
newThread.Add("updateddate", SharedLibrary.Utilities.DateTimeSQLite(Thread.updatedDate));
newThread.Add("content", Thread.content);
newThread.Add("visible", Convert.ToInt32(Thread.visible));
return newThread;
}
public int addThread(ForumThread Thread)
{
Insert("THREADS", getDataTableFromThread(Thread));
return getThreadID(Thread.creationDate);
}
public bool updateThread(ForumThread updatedThread)
{
var user = getDataTableFromThread(updatedThread);
Update("THREADS", user, new KeyValuePair<string, object>("id", updatedThread.getID()));
return true;
}
public ForumThread getThread(int id)
{
DataTable Result = GetDataTable("THREADS", new KeyValuePair<string, object>("id", id));
return getThreadFromDataTable(Result);
}
private ForumThread getThreadFromDataTable(DataTable Result)
{
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
int id = Convert.ToInt32(ResponseRow["id"].ToString());
int categoryid = Convert.ToInt32(ResponseRow["categoryid"].ToString());
int authorid = Convert.ToInt32(ResponseRow["authorid"].ToString());
int replies = Convert.ToInt32(ResponseRow["replies"].ToString());
string title = ResponseRow["title"].ToString();
var category = getCategory(categoryid);
var author = getUser(authorid);
bool visible = Convert.ToBoolean((Convert.ToInt32(ResponseRow["visible"])));
DateTime creationDate = DateTime.Parse(ResponseRow["creationdate"].ToString());
DateTime updatedDate = DateTime.Parse(ResponseRow["updateddate"].ToString());
string content = ResponseRow["content"].ToString();
ForumThread retrievedThread = new ForumThread(id, title, visible, content, replies, author, category, creationDate, updatedDate);
return retrievedThread;
}
return null;
}
// we have no other unique id yet
private int getThreadID(DateTime creationDate)
{
string Query = String.Format("SELECT * FROM THREADS WHERE creationdate = \"{0}\"", SharedLibrary.Utilities.DateTimeSQLite(creationDate));
DataTable Result = GetDataTable(Query);
if (Result != null && Result.Rows.Count > 0)
return Convert.ToInt32(Result.Rows[0]["id"].ToString());
return 0;
}
public List<ForumThread> getRecentThreads(int categoryID)
{
List<ForumThread> threads = new List<ForumThread>();
string Query = String.Format("SELECT id FROM THREADS WHERE categoryid = {0} AND visible = 1 ORDER BY `updateddate` DESC LIMIT 3", categoryID);
DataTable Result = GetDataTable(Query);
if (Result != null && Result.Rows.Count > 0)
{
for (int i = 0; i < Result.Rows.Count; i++)
threads.Add(getThread(Convert.ToInt32(Result.Rows[i]["id"])));
}
return threads;
}
public List<ForumThread> getCategoryThreads(int categoryID)
{
List<ForumThread> threads = new List<ForumThread>();
string Query = String.Format("SELECT id FROM THREADS WHERE categoryid = {0} and visible = 1 ORDER BY `updateddate` DESC", categoryID);
DataTable Result = GetDataTable(Query);
if (Result != null && Result.Rows.Count > 0)
{
for (int i = 0; i < Result.Rows.Count; i++)
threads.Add(getThread(Convert.ToInt32(Result.Rows[i]["id"])));
}
return threads;
}
#endregion
#region RANKING
public int addRank(Rank newRank)
{
Dictionary<string, object> rank = new Dictionary<string, object>();
rank.Add("name", newRank.name);
rank.Add("equivalentrank", (int)newRank.equivalentRank);
Insert("RANKS", rank);
Rank r = getRank(newRank.name);
if (r == null)
return 0;
return r.getID();
}
public Rank getRank(string rankName)
{
DataTable Result = GetDataTable("RANKS", new KeyValuePair<string, object>("name", rankName));
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
string name = ResponseRow["name"].ToString();
int equivRank = Convert.ToInt32(ResponseRow["equivalentrank"].ToString());
int id = Convert.ToInt32(ResponseRow["id"].ToString());
Rank retrievedRank = new Rank(id, name, (SharedLibrary.Player.Permission)equivRank);
return retrievedRank;
}
return null;
}
public Rank getRank(int rankID)
{
DataTable Result = GetDataTable("RANKS", new KeyValuePair<string, object>("id", rankID));
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
string name = ResponseRow["name"].ToString();
int equivRank = Convert.ToInt32(ResponseRow["equivalentrank"].ToString());
Rank retrievedRank = new Rank(rankID, name, (SharedLibrary.Player.Permission)equivRank);
return retrievedRank;
}
return null;
}
#endregion
#region REPLIES
public int addReply(Post reply)
{
Insert("REPLIES", getDataTableFromReply(reply));
return getReplyID(reply.creationDate);
}
public bool updateReply(Post reply)
{
return Update("REPLIES", getDataTableFromReply(reply), new KeyValuePair<string, object>("id", reply.id));
}
public Post getReply(int id)
{
DataTable Result = GetDataTable("REPLIES", new KeyValuePair<string, object>("id", id));
return getReplyFromDataTable(Result);
}
public List<Post> getRepliesFromThreadID(int threadID)
{
List<Post> replies = new List<Post>();
//var Result = GetDataTable("REPLIES", new KeyValuePair<string, object>("threadid", threadID));
var Result = GetDataTable("SELECT * FROM REPLIES WHERE threadid = " + threadID + " AND visible = 1");
foreach (DataRow row in Result.Rows)
{
replies.Add(getReply(Convert.ToInt32(row["id"].ToString())));
}
return replies;
}
private Dictionary<string, object> getDataTableFromReply(Post reply)
{
Dictionary<string, object> newReply = new Dictionary<string, object>();
newReply.Add("title", reply.title);
newReply.Add("authorid", reply.author.getID());
newReply.Add("threadid", reply.threadid);
newReply.Add("creationdate", SharedLibrary.Utilities.DateTimeSQLite(reply.creationDate));
newReply.Add("updateddate", SharedLibrary.Utilities.DateTimeSQLite(reply.updatedDate));
newReply.Add("content", reply.content);
newReply.Add("visible", Convert.ToInt32(reply.visible));
return newReply;
}
private Post getReplyFromDataTable(DataTable Result)
{
if (Result != null && Result.Rows.Count > 0)
{
DataRow ResponseRow = Result.Rows[0];
int id = Convert.ToInt32(ResponseRow["id"].ToString());
int threadid = Convert.ToInt32(ResponseRow["threadid"].ToString());
int authorid = Convert.ToInt32(ResponseRow["authorid"].ToString());
string title = ResponseRow["title"].ToString();
var author = getUser(authorid);
DateTime creationDate = DateTime.Parse(ResponseRow["creationdate"].ToString());
DateTime updatedDate = DateTime.Parse(ResponseRow["updateddate"].ToString());
string content = ResponseRow["content"].ToString();
bool visible = Convert.ToBoolean((Convert.ToInt32(ResponseRow["visible"])));
Post retrievedPost = new Post(id, threadid, visible, title, content, author, creationDate, updatedDate);
return retrievedPost;
}
return null;
}
// we have no other unique id yet
private int getReplyID(DateTime creationDate)
{
DataTable Result = GetDataTable("REPLIES", new KeyValuePair<string, object>("creationdate", SharedLibrary.Utilities.DateTimeSQLite(creationDate)));
if (Result != null && Result.Rows.Count > 0)
return Convert.ToInt32(Result.Rows[0]["id"].ToString());
return 0;
}
#endregion
}
}

View File

@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MessageBoard
{
public class Post : ForumThread
{
/// <summary>
/// Initial creation
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <param name="author"></param>
/// <param name="parentThread"></param>
///
public int threadid;
public Post(string title, int threadid, string content, User author) : base (title, content, author, null)
{
this.threadid = threadid;
}
public Post(int id, int threadid, bool visible, string title, string content, User author, DateTime creationDate, DateTime updatedDate) : base(id, title, visible, content, 0, author, null, creationDate, updatedDate)
{
this.lastModificationString = SharedLibrary.Utilities.timePassed(creationDate);
this.threadid = threadid;
}
}
public class Category : Identifiable
{
public int id { get; private set; }
public string title { get; private set; }
public string description { get; private set; }
public List<Permission> permissions { get; private set; }
public Category(string title, string description)
{
this.title = title;
this.description = description;
this.permissions = new List<Permission>();
id = 0;
}
public Category(int id, string title, string description, List<Permission> permissions)
{
this.title = title;
this.description = description;
this.id = id;
this.permissions = permissions;
}
public int getID()
{
return id;
}
}
public class ForumThread : Identifiable
{
public string title { get; private set; }
public string content { get; private set; }
public User author { get; private set; }
public Category threadCategory { get; private set; }
public DateTime creationDate { get; private set; }
public DateTime updatedDate;
public string lastModificationString { get; protected set; }
public int id { get; private set; }
public int replies;
public bool visible = true;
/// <summary>
/// Initial creation
/// </summary>
/// <param name="title"></param>
/// <param name="content"></param>
/// <param name="author"></param>
public ForumThread(string title, string content, User author, Category threadCategory)
{
if (content.Length == 0)
throw new Exceptions.ThreadException("Post is empty");
if (author == null)
throw new Exceptions.ThreadException("No author of post");
if (title.Length == 0)
throw new Exceptions.ThreadException("Title is empty");
this.title = title;
this.content = content;
this.author = author;
this.threadCategory = threadCategory;
creationDate = DateTime.Now;
updatedDate = DateTime.Now;
replies = 0;
id = 0;
}
/// <summary>
/// Loading from database
/// </summary>
/// <param name="id"></param>
/// <param name="title"></param>
/// <param name="content"></param>
/// <param name="author"></param>
/// <param name="creationDate"></param>
public ForumThread(int id, string title, bool visible, string content, int replies, User author, Category threadCategory, DateTime creationDate, DateTime updatedDate)
{
this.id = id;
this.replies = replies;
this.title = title;
this.content = content;
this.author = author;
this.threadCategory = threadCategory;
this.creationDate = creationDate;
this.updatedDate = updatedDate;
this.lastModificationString = SharedLibrary.Utilities.timePassed(updatedDate);
this.visible = visible;
}
public int getID()
{
return id;
}
public bool updateContent(string content)
{
if (content != null && content.Length > 0)
{
this.content = content;
return true;
}
return false;
}
public bool updateTitle(string title)
{
if (title != null && title.Length > 0)
{
this.title = title;
return true;
}
return false;
}
}
}

108
MessageboardPlugin/User.cs Normal file
View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLibrary;
namespace MessageBoard
{
public class User : Identifiable
{
private string passwordHash; // byte array -> b64 string
private string passwordSalt; // byte array -> b64 string
public DateTime lastLogin;
public string lastLoginString;
public readonly DateTime creationDate;
public int id { get; private set; }
public string avatarURL;
public string username { get; private set; }
public string email { get; private set; }
public Rank ranking;
public int posts;
public int privateMessages;
public int warnings;
public List<int> subscribedThreads { get; private set; }
public User()
{
username = "Guest";
ranking = Plugin.Main.forum.guestRank;
}
/// <summary>
/// When creating a new user
/// </summary>
/// <param name="username"></param>
/// <param name="email"></param>
/// <param name="passwordHash"></param>
/// <param name="passwordSalt"></param>
/// <param name="posts"></param>
/// <param name="privateMessage"></param>
/// <param name="warnings"></param>
public User(string username, string matchedUsername, string email, string passwordHash, string passwordSalt, Rank ranking)
{
if (username.Length < 1)
throw new Exceptions.UserException("Username is empty");
if (email.Length < 1)
throw new Exceptions.UserException("Email is empty");
lastLogin = DateTime.Now;
subscribedThreads = new List<int>();
this.username = username;
this.email = email;
this.posts = 0;
this.privateMessages = 0;
this.warnings = 0;
this.ranking = ranking;
this.passwordHash = passwordHash;
this.passwordSalt = passwordSalt;
this.creationDate = DateTime.Now;
this.avatarURL = "";
id = 0;
}
public User(int id, string passwordHash, string passwordSalt, string username, string email, int posts, DateTime lastLogin, DateTime creationDate, Rank ranking, string avatarURL)
{
this.id = id;
this.passwordHash = passwordHash;
this.passwordSalt = passwordSalt;
this.username = username;
this.email = email;
this.lastLogin = lastLogin;
this.creationDate = creationDate;
this.ranking = ranking;
this.avatarURL = avatarURL;
this.posts = posts;
this.lastLoginString = SharedLibrary.Utilities.timePassed(lastLogin);
}
public int getID()
{
return this.id;
}
public string getPasswordSalt()
{
return this.passwordSalt;
}
public string getPasswordHash()
{
return this.passwordHash;
}
}
public struct UserInfo
{
public string username;
public string email;
public string matchedUsername;
public Rank rank;
}
}

View File

@ -0,0 +1,86 @@
<div id="view">
<div style="float: left;" id="categoryHeader">
</div>
<a href="home"><i class="fa fa-reply themeBlue" aria-hidden="true" style="padding: 0 0.5em; font-size: 24pt; cursor: pointer; margin-top: -5px;"></i></a>
<a href="" id="postThreadButton">
<div style="float: right;" id="postThreadCaption">
<i class="fa fa-plus" aria-hidden="true"></i>
Post
</div>
</a>
<div style="clear: both;"></div>
<hr class="simple"/>
<div id="categoryContainer">
</div>
<hr/>
</div>
<script>
$('#postThreadButton').attr("href", "postthread?id=" + parseGet("id"));
$( document ).on("actionEventLoad", function() {
$.getJSON("_categorythreads?id=" + parseGet("id"), function(response) {
var result = "";
if (response.errorCode != null)
{
if (response.errorCode == 1)
$('#categoryHeader').append('Permission Denied');
else if (response.errorCode == 13)
{
$('#categoryHeader').html("Invalid Category");
$('#postThreadButton').hide();
}
return;
}
if (response.length == 0)
{
$('#categoryHeader').append('No Posts');
return;
}
$.each(response, function(i, thread) {
result +=
"<div class=\"categoryThread table\"> \
<i class=\"fa fa-circle-o themeBlue tableCell\" aria-hidden=\"true\"></i> \
<div class=\"threadTitle tableCell\"><a href=\"thread?id=" + thread["id"] + "\">" + decodeURIComponent(thread["title"]) + "</a><span class=\"threadAuthor tableCell\"><a href=\"user?id=" + thread["author"].id + "\">" + thread["author"].username + "</a></span></div> \
<div class=\"threadTime tableCell\">Last response " + checkJustNow(thread["lastModificationString"]) + "</div> \
<div class=\"threadReplyCount tableCell\"><div class=\"threadReplyBG\">"+ thread.replies +"</div></div> \
<div class=\"threadActions tableCell\" style='vertical-align: middle; " + shouldHideAction(thread.author) +"'><i postid='"+ thread.id + "' class=\"fa fa-times actionHover actionDelete\" aria-hidden=\"true\"></i></div>\
</div>";
});
$('#categoryHeader').html(response[0]["threadCategory"].title);
$('#categoryContainer').append(result);
});
});
$('#content').on('click', '.actionDelete', function(e) {
$.getJSON("_editthread",
{
id : $(this).attr("postid"),
delete : true
},
function(response) {
if (response.success)
window.location.replace(response.destination);
});
});
</script>
<!--
<div id="categoryContainer">
<div class="categoryThread table">
<i class="fa fa-circle-o themeBlue tableCell" aria-hidden="true"></i>
<div class="threadTitle tableCell"><a href="#">This is the particular thread title</a><span class="threadAuthor tableCell"><a href="#">Example Author</a></span></div>
<div class="threadTime tableCell">5 minutes ago</div>
<div class="threadReplyCount tableCell"><div class="threadReplyBG">0</div></div>
</div>-->

View File

@ -0,0 +1,60 @@
<div id="view" class="table">
<div id="threadView" class="tableCell">
<div class="threadBox">
</div>
<hr/>
</div>
<div id="recentView" class="tableCell">
<div id="recentTitle">
Online Users
</div>
<div id="onlineUsers">
</div>
</div>
</div>
<script>
$( document ).ready(function() {
$.getJSON("_recentthreads", function(response) {
var result = "";
$.each(response, function(i, category) {
result += "<div class=\"categoryTitle datThing\"> \
<div class=\"title\"><a href=\"category?id=" + category["categoryID"] + "\">" + category["categoryTitle"] + "</a></div> \
<div class=\"categoryDescription\">" + category["categoryDescription"] + "</div>" +
"</div> \
<div class=\"threadPreview table\">";
$.each(category["recentThreads"], function(i, thread)
{
result += "<div class=\"individualThreadInfo\">";
result += "<i class=\"fa fa-comment\" aria-hidden=\"true\"></i>";
result += "<span class=\"threadTitle tableCell\"><a href=\"thread?id=" + thread.id + "\">" + decodeURIComponent(thread.title) + "</a> &mdash; <a style='opacity: 0.5;' href=\"user?id=" + thread.author.id + "\">" + thread.author['username'] + "</a></span>";
result += "<span class=\"threadInfo tableCell\"><a class=\"themeOrange\" href=\"" + "user?id=" + thread.author['id'] + "\"></a><span class=\"light\">" + checkJustNow(thread.lastModificationString) + "</span></span>";
result += "<div style=\"display: table-row;\"></div>";
result += "</div>";
});
result += "</div>"
});
$('.threadBox').append(result);
});
$.getJSON("_stats", function(response) {
$.each(response.onlineUsers, function(i, user) {
$('#onlineUsers').append('<a href="user?id=' + user.id + '"><p>' + getColorForLevel(user.ranking.name, user.username) + '<p></a>');
});
});
});
</script>

View File

@ -0,0 +1,59 @@
<div class="infoBox" style="display : none;">
<div class="header">
<i class="fa fa-user" aria-hidden="true"></i>
Login</div>
<div class="alertBox">
</div>
<form id="login" method="get">
<input id="username" name="username" type="text"/>
<label for="username">Username</label>
<input id="password" name="password" type="password"/>
<label for="password">Password</label>
<input id="loginButton" value="Login" type="submit"/>
<a href="register">Register</a>
</form>
</div>
<script>
$( document ).ready(function() {
checkPrivilege();
});
function validateInput()
{
var password = $('form #password');
var username = $('form #username');
if (password.val().length < 1) {
showErrorMessage("Password is required!");
return false;
}
if (username.val().length < 1) {
showErrorMessage("Username is required!");
return false;
}
return true;
}
$("#loginButton").click(function(e) {
e.preventDefault();
if (validateInput())
$.getJSON("_login",
{
username : $('form #username').val(),
password : $('form #password').val()
},
function(result) {
if (result["errorCode"] == 0)
window.location.replace(result["destination"]);
else {
showErrorMessage(result["errorCode"]);
}
}
);
});
</script>

View File

@ -0,0 +1,56 @@
<div id="postThreadContainer">
<div class="infoBox" style="width: 80%;">
<div class="header">
<i class="fa fa-commenting" aria-hidden="true"></i>
<span>Post New Thread</span>
</div>
<div class="alertBox">
</div>
<form>
<div class="table" style="width: 100%;">
<select id="threadCategory" class="tableCell">
</select>
<input placeholder="Enter thread title..." type="text" id="threadTitle" class="tableCell"/>
</div>
<textarea id="threadContent" placeholder="Enter thread content..."/></textarea>
<input type="submit" value="Post" id="submitThreadButton"/>
</form>
</div>
</div>
<script>
$( document ).ready(function() {
$.getJSON("_categories", function(response) {
$.each(response, function(i, category) {
$('select').append("<option value='" + category.id + "'>" + category.title + "</option>");
});
$('select option[value="'+ parseGet("id") +'"]').attr("selected",true);
});
});
$("#submitThreadButton").click(function(e) {
e.preventDefault();
$.getJSON("_postthread",
{
title : $('form #threadTitle').val(),
content : $('form #threadContent').val(),
category : $('select').val(),
},
function(result) {
if (result["errorCode"] == 0)
window.location.replace(result["destination"]);
else {
showErrorMessage(result["errorCode"]);
}
}
);
});
</script>

View File

@ -0,0 +1,92 @@
<div class="infoBox" style="display:none;">
<div class="header">
<i style="" class="fa fa-user-plus" aria-hidden="true"></i>
Register
</div>
<div class="alertBox">
</div>
<form id="registration" method="get">
<input id="username" name="username" type="text"/>
<input id="hiddenUsername" type="text" name="hiddenUsername" style="display: none;"/>
<label for="username">Username</label>
<input id="password" name="password" type="password"/>
<label for="password">Password</label>
<input id="passwordRepeat" name="passwordRepeat" type="password"/>
<label for="passwordRepeat">Verify Password</label>
<input id="email" name="email" type="text"/>
<label for="email">Email</label>
<input id="registerButton" value="Register" type="submit"/>
</form>
</div>
<script>
$( document ).ready(function() {
checkPrivilege();
});
function validateInput()
{
var password = $('form #password');
var repeatPassword = $('form #passwordRepeat');
var username = $('form #username');
var email = $('form #email');
if (password.val().length < 5) {
showErrorMessage("Passwords must be at least 5 characters!");
return false;
}
if (password.val() != repeatPassword.val()) {
showErrorMessage("Passwords must match!");
return false;
}
if (username.val().length < 3) {
showErrorMessage("Username must contain at least 3 characters!");
return false;
}
if (email.val().length < 3) {
showErrorMessage("Invalid email address!");
return false;
}
return true;
}
$("#registerButton").click(function(e) {
e.preventDefault();
if (validateInput())
$.getJSON("_register",
{
username : $('form #username').val(),
password : $('form #password').val(),
hiddenUsername : $('form #hiddenUsername').val(),
passwordRepeat : $('form #passwordRepeat').val(),
email : $('form #email').val()
},
function(result) {
if (result["errorCode"] == 0)
window.location.replace(result["destination"]);
else {
showErrorMessage(result["errorCode"]);
}
}
);
});
$('input[type="text"], input[type="password"]').click(function() { $('.alertBox').slideUp("fast"); });
$( document ).ready(function() {
$.getJSON("_userinfo", function(result) {
if (result["matchedName"] != "null")
$('#username, #hiddenUsername').val(result["matchedUsername"]);
});
});
</script>

View File

@ -0,0 +1,126 @@
<div id="threadContainer">
<div id="textNav"><a class="themeBlue" href="home">Home</a> &raquo; </div>
<hr/>
<div class="threadStart table" style="width: 100%;">
<div class="userInfo tableCell">
<div class="userAvatar">
<i class="fa fa-user-secret" aria-hidden="true" style="font-size: 8em;"></i>
</div>
<a class="userProfileLink" href=""><span class="userTitle">_</span></a><br/>
<span style="font-size: 9pt;" class="timePosted">_</span>
</div>
<div class="threadInfo tableCell">
<div class="threadTitle" style="float: left;">_</div>
<div style="float: right;" id="replyThreadCaption">
<i class="fa fa-reply" aria-hidden="true"></i>
Reply
</div>
<div style="clear: both;"></div>
<div class="threadContent">_</div>
</div>
</div>
</div>
<div id="postReplyContainer" style="display: none;">
<hr/>
<div id="postReplyClose">
<i class="fa fa-times" aria-hidden="true"></i>
</div>
<div id="replyContentContainer">
<div class="alertBox">
</div>
<textarea placeholder="Reply content..." id="replyContentBox"></textarea>
<div id="submitReplyButton">
<i class="fa fa-reply" aria-hidden="true"></i>
</div>
</div>
</div>
<script>
$( document ).on("actionEventLoad", function() {
$.getJSON("_thread?id=" + parseGet('id'), function(Response) {
if (Response.errorCode != null)
{
alert('error!');
}
$('#textNav').append('<a class="themeBlue" href="category?id=' + Response.Thread.threadCategory.id + '">' + Response.Thread.threadCategory.title + '</a> &raquo; ' + decodeURIComponent(Response.Thread.title));
$('.threadStart .userTitle').html(Response.Thread.author.username);
$('.threadStart .timePosted').html(getDate(Response.Thread.creationDate));
$('.threadStart .threadTitle').html(decodeURIComponent(Response.Thread.title));
$('.threadStart a.userProfileLink').attr("href", "user?id=" + Response.Thread.author.id);
$('.threadStart .threadContent').html(decodeURIComponent(Response.Thread.content));
if (Response.Thread.author.avatarURL != "")
$('.threadStart .userAvatar').html("").attr("style", "background-image:url('" + Response.Thread.author.avatarURL + "');'");
$('#replyThreadButton').attr("href", "postthread?threadid=" + Response.Thread.id);
$.each(Response.Replies, function(i, eachReply) {
var cat = "<div class='threadStart table' style='width: 100%;'> \
<div class='userInfo tableCell'>";
if (eachReply.author.avatarURL == "")
cat += "<div class='userAvatar'><i class='fa fa-user-secret' aria-hidden='true' style='font-size: 8em;'></i>";
else
cat += "<div class='userAvatar' style=\"background-image:url('" + eachReply.author.avatarURL + "');\">";
cat +=
"</div> \
<a class='userProfileLink' href='user?id="+ eachReply.author.id +"'><span class='userTitle'>" + getColorForLevel(eachReply.author.ranking.name, eachReply.author.username) + "</span></a><br/> \
<span style='font-size: 9pt;' class='timePosted'>" + checkJustNow(eachReply.lastModificationString) + "</span> \
</div> \
<div class='threadInfo tableCell'> \
<i style=\"" + shouldHideAction(eachReply.author) + "\" replyid='" + eachReply.id + "' class=\"fa fa-times actionHover actionDelete\" aria-hidden=\"true\"></i> \
<div class='threadContent'>" + decodeURIComponent(eachReply.content) + "</div> \
</div> \
</div>";
$("#threadContainer").append(cat);
});
});
});
$('#replyThreadCaption').click(function(e) {
e.preventDefault();
$('#postReplyContainer').slideDown('fast');
});
$('#postReplyClose').click(function(e) {
$(this).parent().slideUp('fast');
});
$("#submitReplyButton").click(function(e) {
e.preventDefault();
$.getJSON("_postthread",
{
content : $('#replyContentBox').val(),
title : "Reply",
threadid : parseGet("id")
},
function(result) {
if (result["errorCode"] == 0)
window.location.replace(result["destination"]);
else {
showErrorMessage(result["errorCode"]);
}
});
});
$('#content').on('click', '.actionDelete', function(e) {
$.getJSON("_editthread",
{
replyid : $(this).attr("replyid"),
delete : true
},
function(response) {
if (response.success)
window.location.replace(response.destination);
});
});
</script>

View File

@ -0,0 +1,56 @@
<div id="userCover" style="display:none;">
</div>
<div id="userInfoBox">
<div class="table" style="width: 100%;">
<div class="tableCell" style="vertical-align:middle; width: 70%;">
<div class="userInfoField table">
<i class="fa fa-user tableCell" aria-hidden="true"></i> <span class="tableCell" id="userCreated">_</span>
</div>
<div class="userInfoField table">
<i class="fa fa-clock-o tableCell" aria-hidden="true"></i> <span class="tableCell" id="userLogon">_</span>
</div>
<div class="userInfoField table">
<i class="fa fa-comment tableCell" aria-hidden="true"></i> <span class="tableCell" id="userPostCount">_</span>
</div>
<div class="userInfoField table">
<i class="fa fa-envelope-o tableCell" aria-hidden="true"></i> <span class="tableCell" id="userEmail"><a href="#" class="themeBlue">_</a></span>
</div>
<div class="userInfoField table">
<i class="fa fa-users tableCell" aria-hidden="true"></i> <span class="tableCell" id="userRank">_</span>
</div>
</div>
<div class="tableCell" style="vertical-align:middle;">
<div id="userAvatar" class="">
<i class="fa fa-user-secret" aria-hidden="true" style="font-size: 19em; margin-top: -56px;"></i>
</div>
</div>
</div>
<hr style="width: calc(100% + 2em); margin-bottom: -1em; margin-left: -1em;"/>
</div>
<script>
$.getJSON("_userinfo?id=" + parseGet('id'), function(user) {
if (user == null)
return false;
$('#userCover').html(user.username);
var creationDate = new Date(user.creationDate);
$('#userCreated').html("Joined " + (creationDate.getMonth() + 1) + '-' + creationDate.getDate() + '-' + creationDate.getFullYear());
$('#userLogon').html("Last seen " + checkJustNow(user.lastLoginString));
$('#userPostCount').html(user.posts + " Posts");
$('#userEmail a').html(user.email);
$('#userEmail a').attr("href", "mailto:" + user.email);
$('#userAvatar').html('');
$('#userAvatar').attr("style", "background-image:url('" + user.avatarURL + "');'");
$('#userRank').html(user.ranking.name);
$('#userCover').slideDown('fast');
});
</script>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="CryptSharp" version="1.2.0.1" targetFramework="net40" />
<package id="MarkdownDeep.NET" version="1.5" targetFramework="net40" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net40" requireReinstallation="true" />
</packages>