The base class for Http request server entry point
Inheritance: System.Web.UI.Page
Exemple #1
0
        public static void SetUserName(AjaxBase ajax, string value)
        {
            if (value == null)
            {
                value = "";
            }

            Set(ajax, "username", value);
        }
Exemple #2
0
        public static void SetFinderData(AjaxBase ajax, string token, string[][] finderData)
        {
            Dictionary<string, string[][]> dict = (Dictionary<string, string[][]>)Get(ajax, "finder");
            if (dict == null)
            {
                dict = new Dictionary<string, string[][]>();
            }

            dict[token] = finderData;

            Set(ajax, "finder", dict);
        }
Exemple #3
0
 public static string GetUserName(AjaxBase ajax)
 {
     object username = Get(ajax, "username");
     if (username == null)
     {
         return "";
     }
     else
     {
         return Convert.ToString(username);
     }
 }
Exemple #4
0
        /// <summary>
        /// Get whether the current request can access the collection
        /// </summary>
        /// <param name="ajax">The AjaxBase object which received the request</param>
        /// <returns>True if accessible</returns>
        public bool Accessible(AjaxBase ajax)
        {
            string where = "`id`=" + Database.Quote(Id.ToString());
            User user = User.GetCurrentUser(ajax);
            string collectionSelect = "FALSE";
            if (Settings.AllowGuest || user != null)
            {
                collectionSelect += " OR `public`='1'";
            }

            if (user != null)
            {
                collectionSelect += " OR `id` IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='1')";
                where += " AND `id` NOT IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='0')";
            }

            where += " AND (" + collectionSelect + ")";

            return Database.Select("collection", where, null, null, "`id`").Length > 0;
        }
Exemple #5
0
        /// <summary>
        /// Get a list of collections from database which is accessible by the current user
        /// </summary>
        /// <param name="ajax">The AjaxBase object which received the request</param>
        /// <returns>A list of collections</returns>
        public static Collection[] GetAccessible(AjaxBase ajax)
        {
            User user = User.GetCurrentUser(ajax);
            string where = "FALSE";
            if (Settings.AllowGuest || user != null)
            {
                where += " OR `public`='1'";
            }

            if (user != null)
            {
                where += " OR `id` IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='1')";
                where = "(" + where + ") AND `id` NOT IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='0')";
            }

            Dictionary<string, object>[] resultSet = Database.Select("collection", where);
            List<Collection> collections = new List<Collection>();

            foreach (Dictionary<string, object> result in resultSet)
            {
                collections.Add(FromData(result));
            }

            return collections.ToArray();
        }
Exemple #6
0
 public static bool IsAdminLoggedIn(AjaxBase ajax)
 {
     User currentUser = GetCurrentUser(ajax);
     return currentUser != null && currentUser.Admin;
 }
Exemple #7
0
 public static User GetCurrentUser(AjaxBase ajax)
 {
     return GetUser(SessionWrapper.GetUserName(ajax), null);
 }
Exemple #8
0
 private static void Set(AjaxBase ajax, string name, object value)
 {
     ajax.Session["afung.MangaWeb3.Server.Session." + name] = value;
 }
Exemple #9
0
 private static object Get(AjaxBase ajax, string name)
 {
     return ajax.Session["afung.MangaWeb3.Server.Session." + name];
 }
Exemple #10
0
        public static Manga[] GetMangaList(AjaxBase ajax, MangaFilter filter)
        {
            string where = "`status`='0'";
            User user = User.GetCurrentUser(ajax);
            string collectionSelect = "FALSE";
            if (Settings.AllowGuest || user != null)
            {
                collectionSelect += " OR `cid` IN (SELECT `id` FROM `collection` WHERE `public`='1')";
            }

            if (user != null)
            {
                collectionSelect += " OR `cid` IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='1')";
                where += " AND `cid` NOT IN (SELECT `cid` FROM `collectionuser` WHERE `uid`=" + Database.Quote(user.Id.ToString()) + " AND `access`='0')";
            }

            where += " AND (" + collectionSelect + ")";

            if (filter != null)
            {
                if (filter.tag != null && filter.tag != "")
                {
                    where += " AND `id` IN (SELECT `mid` FROM `mangatag` WHERE `tid` IN (SELECT `id` FROM `tag` WHERE `name`=" + Database.Quote(filter.tag) + "))";
                }

                string folder = null;
                int folderSetting = 2;

                if (filter.search != null)
                {
                    string metaSelect = "TRUE";

                    if (filter.search.title != null && filter.search.title != "")
                    {
                        string title = Database.Quote(filter.search.title);
                        title = Database.Quote(title.Substring(1, title.Length - 2));
                        title = title.Substring(1, title.Length - 2).Replace("%", "\\%");
                        where += " AND `title` LIKE '%" + title + "%'";
                    }

                    if (filter.search.author != null && filter.search.author != "")
                    {
                        metaSelect += " AND `author`=" + Database.Quote(filter.search.author);
                    }

                    if (filter.search.series != null && filter.search.series != "")
                    {
                        metaSelect += " AND `series`=" + Database.Quote(filter.search.series);
                    }

                    if (filter.search.year >= 0)
                    {
                        metaSelect += " AND `year`=" + Database.Quote(filter.search.year.ToString());
                    }

                    if (filter.search.publisher != null && filter.search.publisher != "")
                    {
                        metaSelect += " AND `publisher`=" + Database.Quote(filter.search.publisher);
                    }

                    if (metaSelect != "TRUE")
                    {
                        where += " AND `id` IN (SELECT `mid` FROM `meta` WHERE " + metaSelect + ")";
                    }

                    if (filter.search.folderSetting > 0 && filter.search.folder != null && filter.search.folder != "")
                    {
                        folder = filter.search.folder;
                        folderSetting = filter.search.folderSetting;
                    }
                }

                if (folder == null && filter.folder != null && filter.folder != "")
                {
                    folder = filter.folder;
                }

                if (folderSetting > 0 && folder != null && folder != "")
                {
                    int index;
                    string collectionName = (index = folder.IndexOf("\\")) == -1 ? folder : folder.Substring(0, index);
                    string relativePath = folder.Substring(index + 1);
                    Collection collection = Collection.GetByName(collectionName);

                    if (collection == null)
                    {
                        where += " AND FALSE";
                    }
                    else
                    {
                        string actualPath = Database.Quote(index == -1 ? collection.Path.Substring(0, collection.Path.Length - 1) : collection.Path + relativePath);
                        actualPath = Database.Quote(actualPath.Substring(1, actualPath.Length - 2));
                        actualPath = actualPath.Substring(1, actualPath.Length - 2).Replace("%", "\\%");
                        where += " AND `cid`=" + Database.Quote(collection.Id.ToString());
                        where += " AND `path` LIKE '" + actualPath + "\\\\\\\\%'" + (folderSetting == 2 ? " AND `path` NOT LIKE '" + actualPath + "\\\\\\\\%\\\\\\\\%'" : "");
                    }
                }
            }

            return GetMangas(where);
        }