Exemplo n.º 1
0
        public Dictionary <string, object> Post(string type, [FromForm] long id, [FromForm] string sessionid)
        {
            Dictionary <string, object> response = new Dictionary <string, object>();

            if (!Program.users.TryGetValue(sessionid, out User user) && user.mod > 0)
            {
                response.Add("status", 1);
                response.Add("msg", "Invalid session");
                return(response);
            }
            if (user.banned)
            {
                response.Add("status", 4);
                response.Add("msg", "You are banned from doing this");
                return(response);
            }

            string column;
            string table;

            switch (type)
            {
            case "thread":
                column = "threadid";
                table  = "threads";
                break;

            case "comment":
                column = "commentid";
                table  = "comments";
                break;

            case "user":
                column = "uid";
                table  = "users";
                break;

            default:
                response.Add("status", 2);
                response.Add("msg", "Invalid report type");
                return(response);
            }

            SqlConnection con     = new SqlConnection(Program.Configuration["connectionStrings:splashConString"]);
            SqlCommand    command = new SqlCommand("UPDATE " + table + " SET reported = 0 WHERE " + column + " = @id;", con);

            command.Parameters.AddWithValue("id", id);
            con.Open();

            if (command.ExecuteNonQuery() > 0)
            {
                ReportLogger.LogAction(type, ReportLogger.RELEASE, id, user.uid);
                response.Add("status", 0);
                response.Add("msg", "Reports cleared");
            }
            else
            {
                response.Add("status", 5);
                response.Add("msg", "Internal error occured");
            }
            con.Close();

            return(response);
        }
        public Dictionary <string, object> Post(string type, [FromForm] long id, [FromForm] string sessionid)
        {
            Dictionary <string, object> response = new Dictionary <string, object>();

            if (!(Program.users.TryGetValue(sessionid, out User user) && user.mod > 0))
            {
                response.Add("status", 1);
                response.Add("msg", "Invalid session");
                return(response);
            }
            if (user.banned)
            {
                response.Add("status", 4);
                response.Add("msg", "You are banned from doing this");
                return(response);
            }
            string cmdText;

            switch (type)
            {
            case "thread":
                cmdText = "UPDATE threads SET locked=0 WHERE threadid=" + id + ";";
                break;

            case "comment":
                cmdText = "UPDATE comments SET locked=0 WHERE commentid=" + id + ";";
                break;

            case "user":
                if (!UserController.CanMod(user.mod, id))
                {
                    response.Add("status", 3);
                    response.Add("msg", "User is in a higher tier or does not exist");
                    return(response);
                }
                cmdText = "UPDATE users SET canpost=1, cancomment=1 WHERE uid=" + id + ";";
                break;

            default:
                response.Add("status", 2);
                response.Add("msg", "Invalid action object type");
                return(response);
            }
            SqlConnection con     = new SqlConnection(Program.Configuration["connectionStrings:splashConString"]);
            SqlCommand    command = new SqlCommand(cmdText, con);

            con.Open();
            if (command.ExecuteNonQuery() > 0)
            {
                ReportLogger.LogAction(type, ReportLogger.UNLOCK, id, user.uid);
                response.Add("status", 0);
                response.Add("msg", "Object locked successfully");
            }
            else
            {
                response.Add("status", 5);
                response.Add("msg", "Internal error occured while locking object");
            }
            con.Close();

            return(response);
        }