Exemplo n.º 1
0
        /// <summary>
        /// 重置用户密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">新密码</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminResetUserPassword(String userName, String passWord)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            if (String.IsNullOrEmpty(passWord))
            {
                return(MethodResult.FailedAndLog("New password can not be NULL!"));
            }
            else
            {
                passWord = PassWordEncrypt.Encrypt(userName, passWord);
            }

            Boolean success = UserRepository.Instance.UpdateEntityPassword(userName, passWord) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No user's password was reset!"));
            }

            return(MethodResult.SuccessAndLog("User reset password, name = {0}", userName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取帖子列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>帖子列表</returns>
        public static PagedList <ForumPostEntity> AdminGetForumPostList(Int32 pageIndex, String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumPostManager.AdminCountForumPosts(fpids, ftids, username, title, content, isHide, startDate, endDate, postip);

            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            fpids = fpids.SearchOptimized();
            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids))
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            return(ForumPostRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount,
                                fpids, ftids, username, title, content,
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip)
                   .ToPagedList(pageSize, recordCount));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 根据用户名获取未通过提交列表
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="solvedList">该用户AC题目ID的列表</param>
        /// <param name="contestID">竞赛ID</param>
        /// <returns>题目ID列表</returns>
        public static List <Int32> GetUnSolvedProblemIDListByUser(String userName, List <Int32> lstSolved, Int32 contestID)
        {
            if (String.IsNullOrEmpty(userName))
            {
                return(new List <Int32>());
            }

            if (!RegexVerify.IsUserName(userName))
            {
                throw new InvalidRequstException(RequestType.User);
            }

            List <Int32> lstUnsolved = (contestID == -1 ? SolutionCache.GetProblemIDListCache(userName, true) : null);//获取缓存

            if (lstUnsolved == null)
            {
                lstUnsolved = SolutionRepository.Instance.GetEntityIDsByUserAndLessResultType(userName, contestID, ResultType.Accepted);

                if (lstUnsolved != null && lstUnsolved.Count > 0 && lstSolved != null && lstSolved.Count > 0)
                {
                    foreach (Int32 pid in lstSolved)
                    {
                        lstUnsolved.Remove(pid);
                    }
                }

                if (contestID == -1)
                {
                    SolutionCache.SetProblemIDListCache(userName, true, lstUnsolved);//设置缓存
                }
            }

            return(lstUnsolved != null ? lstUnsolved : new List <Int32>());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取主题列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题列表</returns>
        public static PagedList <ForumTopicEntity> AdminGetForumTopicList(Int32 pageIndex, String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            Int32 pageSize    = AdminManager.ADMIN_LIST_PAGE_SIZE;
            Int32 recordCount = ForumTopicManager.AdminCountForumTopics(ftids, username, title, type, relativeID, isLocked, isHide, startDate, endDate);

            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .GetEntities(pageIndex, pageSize, recordCount, ftids, username, title,
                                (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()))
                   .ToPagedList(pageSize, recordCount));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取主题总数(无缓存)
        /// </summary>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖人</param>
        /// <param name="title">主题标题</param>
        /// <param name="type">主题类型</param>
        /// <param name="relativeID">相关ID</param>
        /// <param name="isLocked">是否锁定</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <returns>主题总数</returns>
        private static Int32 AdminCountForumTopics(String ftids, String username, String title, String type, String relativeID, String isLocked, String isHide, String startDate, String endDate)
        {
            Byte     topictype = 0;
            Int32    rid = -1;
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            if (!String.IsNullOrEmpty(relativeID) && !Int32.TryParse(relativeID, out rid))
            {
                throw new InvalidInputException("Relative ID is INVALID!");
            }

            return(ForumTopicRepository.Instance
                   .CountEntities(ftids, username, title,
                                  (!String.IsNullOrEmpty(type) && Byte.TryParse(type, out topictype) ? (ForumTopicType)topictype : new Nullable <ForumTopicType>()), rid,
                                  (!String.IsNullOrEmpty(isLocked) ? "1".Equals(isLocked, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                  (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>())));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新竞赛隐藏状态
        /// </summary>
        /// <param name="ids">竞赛ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateContestIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ContestManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.Contest));
            }

            Boolean success = ContestRepository.Instance.UpdateEntityIsHide(ids, isHide) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No contest was {0}!", isHide ? "hided" : "unhided"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ContestCache.RemoveContestCache(id);//删除缓存
            });

            ContestCache.RemoveContestListCountCache();//删除缓存

            return(MethodResult.SuccessAndLog("Admin {1} contest, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
Exemplo n.º 7
0
        /// <summary>
        /// 更新主题锁定状态
        /// </summary>
        /// <param name="ids">主题ID列表</param>
        /// <param name="isLock">是否锁定</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateForumTopicIsLocked(String ids, Boolean isLocked)
        {
            if (!AdminManager.HasPermission(PermissionType.ForumManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.ForumTopic));
            }

            Boolean success = ForumTopicRepository.Instance.UpdateEntityIsLocked(ids, isLocked) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No forum topic was {0}!", isLocked ? "locked" : "unlocked"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ForumTopicCache.RemoveForumTopicCache(id);//删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} forum topic, id = {0}", ids, isLocked ? "lock" : "unlock"));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 根据ID得到一个主题页面实体
        /// </summary>
        /// <param name="name">页面名称</param>
        /// <returns>主题页面实体</returns>
        public static TopicPageEntity GetTopicPage(String name)
        {
            if (!RegexVerify.IsPageName(name))
            {
                throw new InvalidRequstException(RequestType.TopicPage);
            }

            TopicPageEntity topicpage = TopicPageCache.GetTopicPageCache(name);//读取缓存

            if (topicpage == null)
            {
                topicpage = TopicPageManager.GetReplacedContent(TopicPageRepository.Instance.GetEntity(name));
                TopicPageCache.SetTopicPageCache(topicpage);//设置缓存
            }

            if (topicpage == null)
            {
                throw new NullResponseException(RequestType.TopicPage);
            }

            if (topicpage.IsHide && !AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            return(topicpage);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 更新题目隐藏状态
        /// </summary>
        /// <param name="ids">题目ID列表</param>
        /// <param name="isHide">隐藏状态</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateProblemIsHide(String ids, Boolean isHide)
        {
            if (!AdminManager.HasPermission(PermissionType.ProblemManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.Problem));
            }

            Boolean success = ProblemRepository.Instance.UpdateEntityIsHide(ids, isHide) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No problem was {0}!", isHide ? "hided" : "unhided"));
            }

            ids.ForEachInIDs(',', id =>
            {
                ProblemCache.RemoveProblemCache(id);                         //删除缓存
                ProblemCache.RemoveProblemSetCache(GetProblemPageIndex(id)); //删除缓存
            });

            return(MethodResult.SuccessAndLog("Admin {1} problem, id = {0}", ids, isHide ? "hide" : "unhide"));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 根据用户名和提交结果获取通过提交列表
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="contestID">竞赛ID</param>
        /// <returns>题目ID列表</returns>
        public static List <Int32> GetSolvedProblemIDListByUser(String userName, Int32 contestID)
        {
            if (String.IsNullOrEmpty(userName))
            {
                return(new List <Int32>());
            }

            if (!RegexVerify.IsUserName(userName))
            {
                throw new InvalidRequstException(RequestType.User);
            }

            List <Int32> lstSolved = (contestID == -1 ? SolutionCache.GetProblemIDListCache(userName, false) : null);//获取缓存

            if (lstSolved == null)
            {
                lstSolved = SolutionRepository.Instance.GetEntityIDsByUserAndResultType(userName, contestID, ResultType.Accepted);

                if (contestID == -1)
                {
                    SolutionCache.SetProblemIDListCache(userName, false, lstSolved);                 //获取缓存
                }
            }

            return(lstSolved != null ? lstSolved : new List <Int32>());
        }
Exemplo n.º 11
0
        /// <summary>
        /// 获取用户IPv4地址
        /// </summary>
        /// <param name="request">Http请求</param>
        /// <returns>IPv4地址</returns>
        public static String GetRemoteClientIPv4(this HttpRequestBase request)
        {
            if (request == null)
            {
                return(String.Empty);
            }

            String ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (RegexVerify.IsIPv4(ip))
            {
                if (ip.IndexOf(':') >= 0)//有端口的情况
                {
                    ip = ip.Substring(0, ip.IndexOf(':'));
                }

                return(ip);//如果只有一个IP则返回
            }

            if (String.IsNullOrEmpty(ip))
            {
                ip = request.ServerVariables["REMOTE_ADDR"];
            }

            if (String.IsNullOrEmpty(ip))
            {
                ip = request.UserHostAddress;
            }

            if (!String.IsNullOrEmpty(ip) && ip.IndexOf(',') >= 0)//有代理的情况
            {
                String[] ips = ip.Replace(" ", "").Replace("'", "").Split(new Char[] { ',', ';' });

                for (Int32 i = 0; i < ips.Length; i++)
                {
                    if ((RegexVerify.IsIPv4(ips[i])) && (ips[i].Substring(0, 3) != "10.") && (ips[i].Substring(0, 7) != "192.168") && (ips[i].Substring(0, 7) != "172.16."))
                    {
                        ip = ips[i];//获取不是内网的地址
                        break;
                    }
                }
            }

            if (String.Equals(ip, "::1"))
            {
                ip = "127.0.0.1";
            }

            if (!String.IsNullOrEmpty(ip) && ip.IndexOf(':') >= 0)//有端口的情况
            {
                ip = ip.Substring(0, ip.IndexOf(':'));
            }

            return(ip);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 尝试将使用用户名密码登陆系统
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="passWord">密码</param>
        /// <param name="user">若成功返回用户实体</param>
        /// <returns>失败则返回出错信息,成功则不返回任何信息</returns>
        public static String TryGetUserByUsernameAndPassword(String userName, String passWord, out UserEntity user)
        {
            user = null;

            try
            {
                if (String.IsNullOrEmpty(userName))
                {
                    return("Username can not be NULL!");
                }

                if (String.IsNullOrEmpty(passWord))
                {
                    return("Password can not be NULL!");
                }

                if (!RegexVerify.IsUserName(userName) || !SQLValidator.IsNonNullANDSafe(userName))
                {
                    return("Username is INVALID!");
                }

                passWord = PassWordEncrypt.Encrypt(userName, passWord);
                user     = UserRepository.Instance.GetEntityByNameAndPassword(userName, passWord);

                if (user == null)
                {
                    return("No such user or wrong password!");
                }

                if (!String.Equals(user.PassWord, passWord, StringComparison.OrdinalIgnoreCase))
                {
                    return("Password is wrong!");
                }

                if (user.IsLocked)
                {
                    return("The user is locked, please contact the administrator!");
                }

                if ("NULL".Equals(user.PassWord, StringComparison.OrdinalIgnoreCase))
                {
                    return("The user's password is INVALID, please visit \"Forget Password\" and reset your password!");
                }

                return(String.Empty);
            }
            catch (System.Exception ex)
            {
                return(ex.Message);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// 根据题目搜索结果获取题目列表
        /// </summary>
        /// <param name="type">搜索类别</param>
        /// <param name="content">搜索内容</param>
        /// <returns>题目列表</returns>
        public static List <ProblemEntity> GetProblemBySearch(String type, String content)
        {
            List <ProblemEntity> list = null;

            if (String.Equals(type, "category", StringComparison.OrdinalIgnoreCase))
            {
                Int32 typeID = -1;

                if (!Int32.TryParse(content, out typeID) || typeID <= 0)
                {
                    throw new InvalidRequstException(RequestType.ProblemCategory);
                }

                list = ProblemManager.GetProblemListByType(typeID);
            }
            else if (String.Equals(type, "pid", StringComparison.OrdinalIgnoreCase))
            {
                content = content.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(content))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                list = ProblemManager.GetProblemListByID(content);
            }
            else if (String.Equals(type, "title", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Title is INVALID!");
                }

                list = ProblemManager.GetProblemListByTitle(content);
            }
            else if (String.Equals(type, "source", StringComparison.OrdinalIgnoreCase))
            {
                if (String.IsNullOrEmpty(content) || !SQLValidator.IsNonNullANDSafe(content))
                {
                    throw new InvalidInputException("Problem Source is INVALID!");
                }

                list = ProblemManager.GetProblemListBySource(content);
            }

            list = GetUserCanViewProblemList(list);

            return(list);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 根据ID得到一个用户实体
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public static UserEntity GetUserInfo(String userName)
        {
            if (!RegexVerify.IsUserName(userName))
            {
                throw new InvalidRequstException(RequestType.User);
            }

            UserEntity entity = UserRepository.Instance.GetEntityWithBasicInfo(userName);

            if (entity == null)
            {
                throw new NullResponseException(RequestType.User);
            }

            return(entity);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 更新一条主题页面
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="oldname">旧的主题页面名</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateTopicPage(TopicPageEntity entity, String oldname)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(entity.PageName))
            {
                return(MethodResult.InvalidRequest(RequestType.TopicPage));
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Page title can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Page description can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Content))
            {
                return(MethodResult.FailedAndLog("Page content can not be NULL!"));
            }

            entity.LastDate = DateTime.Now;

            Boolean success = TopicPageRepository.Instance.UpdateEntity(entity, oldname) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No page was updated!"));
            }

            TopicPageCache.RemoveTopicPageCache(oldname);//更新缓存

            return(MethodResult.SuccessAndLog("Admin update page, name = {0}{1}", entity.PageName,
                                              (!String.Equals(oldname, entity.PageName, StringComparison.OrdinalIgnoreCase) ? ", previous = " + oldname : "")));
        }
Exemplo n.º 16
0
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public static IMethodResult AdminGetUserInfo(String userName)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            UserEntity entity = UserRepository.Instance.GetEntityWithAllInfo(userName);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.User));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 17
0
        /// <summary>
        /// 更新指定ID的用户通过题目总数
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdateSolvedCount(String userName)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            Boolean success = UserRepository.Instance.UpdateEntitySolvedCount(userName) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No user's solved count was recalculated!"));
            }

            return(MethodResult.SuccessAndLog("Admin update user's solved count, name = {0}", userName));
        }
Exemplo n.º 18
0
        /// <summary>
        /// 更新指定ID的用户的用户权限
        /// </summary>
        /// <param name="userNames">用户名</param>
        /// <param name="permission">权限类型</param>
        /// <returns>是否成功更新</returns>
        internal static IMethodResult InternalAdminUpdatePermission(String userName, PermissionType permission)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            Boolean success = UserRepository.Instance.UpdateEntityPermision(userName, permission) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("Failed to update user's permission!"));
            }

            return(MethodResult.Success());
        }
Exemplo n.º 19
0
        /// <summary>
        /// 根据ID得到一个主题页面实体
        /// </summary>
        /// <param name="id">主题页面ID</param>
        /// <returns>主题页面实体</returns>
        public static IMethodResult AdminGetTopicPage(String name)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(name))
            {
                return(MethodResult.InvalidRequest(RequestType.TopicPage));
            }

            TopicPageEntity entity = TopicPageRepository.Instance.GetEntity(name);

            if (entity == null)
            {
                return(MethodResult.NotExist(RequestType.TopicPage));
            }

            return(MethodResult.Success(entity));
        }
Exemplo n.º 20
0
        /// <summary>
        /// 增加一条主题页面
        /// </summary>
        /// <param name="model">对象实体</param>
        /// <returns>是否成功增加</returns>
        public static IMethodResult AdminInsertTopicPage(TopicPageEntity entity)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsPageName(entity.PageName))
            {
                return(MethodResult.InvalidRequest(RequestType.TopicPage));
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                return(MethodResult.FailedAndLog("Page title can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Description))
            {
                return(MethodResult.FailedAndLog("Page description can not be NULL!"));
            }

            if (String.IsNullOrEmpty(entity.Content))
            {
                return(MethodResult.FailedAndLog("Page content can not be NULL!"));
            }

            entity.CreateUser = UserManager.CurrentUserName;
            entity.IsHide     = true;
            entity.LastDate   = DateTime.Now;

            Boolean success = TopicPageRepository.Instance.InsertEntity(entity) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No page was added!"));
            }

            return(MethodResult.SuccessAndLog("Admin add page, name = {0}", entity.PageName));
        }
Exemplo n.º 21
0
        /// <summary>
        /// 删除指定ID的公告
        /// </summary>
        /// <param name="ids">逗号分隔的公告ID</param>
        /// <returns>是否成功删除</returns>
        public static IMethodResult AdminDeleteNews(String ids)
        {
            if (!AdminManager.HasPermission(PermissionType.NewsManage))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                return(MethodResult.InvalidRequest(RequestType.News));
            }

            String[] arrids    = ids.Split(',');
            String   defaultID = NewsRepository.DEFAULTID.ToString();

            for (Int32 i = 0; i < arrids.Length; i++)
            {
                if (String.Equals(arrids[i], defaultID))
                {
                    return(MethodResult.FailedAndLog("Can not delete the default news!"));
                }
            }

            Boolean success = NewsRepository.Instance.DeleteEntities(ids) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No news was deleted!"));
            }

            ids.ForEachInIDs(',', id =>
            {
                NewsCache.RemoveNewsCache(id);      //删除缓存
            });
            NewsCache.RemoveLastestNewsListCache(); //删除缓存
            NewsCache.RemoveNewsCountCache();       //删除缓存

            return(MethodResult.SuccessAndLog("Admin delete news, id = {0}", ids));
        }
Exemplo n.º 22
0
        /// <summary>
        /// 删除指定ID的邮件
        /// </summary>
        /// <param name="ids">逗号分隔的邮件ID</param>
        /// <returns>是否成功删除</returns>
        public static Boolean DeleteUserMails(String ids)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (!RegexVerify.IsNumericIDs(ids))
            {
                throw new InvalidRequstException(RequestType.UserMail);
            }

            String  userName = UserManager.CurrentUserName;
            Boolean success  = UserMailRepository.Instance.DeleteEntities(userName, ids) > 0;

            if (success)
            {
                UserMailCache.RemoveUserUnReadMailCountCache(userName);//删除缓存
            }

            return(success);
        }
Exemplo n.º 23
0
        /// <summary>
        /// 更新指定ID的用户的用户权限
        /// </summary>
        /// <param name="userNames">用户名</param>
        /// <param name="permissions">权限类型</param>
        /// <returns>是否成功更新</returns>
        public static IMethodResult AdminUpdatePermision(String userName, String permissions)
        {
            if (!AdminManager.HasPermission(PermissionType.SuperAdministrator))
            {
                throw new NoPermissionException();
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            PermissionType permission = AdminManager.GetPermission(permissions);
            Boolean        success    = UserRepository.Instance.UpdateEntityPermision(userName, permission) > 0;

            if (!success)
            {
                return(MethodResult.FailedAndLog("No user's permission was updated!"));
            }

            return(MethodResult.SuccessAndLog("Admin update permission, name = {0}, permission = {1}", userName, ((Int32)permission).ToString()));
        }
Exemplo n.º 24
0
        /// <summary>
        /// 获取提交列表
        /// </summary>
        /// <param name="pageIndex">页面索引</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="languageType">提交语言</param>
        /// <param name="resultType">提交结果</param>
        /// <param name="order">排序顺序</param>
        /// <returns>提交列表</returns>
        public static PagedList <SolutionEntity> GetSolutionList(Int32 pageIndex, Int32 cid, Int32 pid, String userName, String languageType, String resultType, String order)
        {
            Int32 pageSize             = SolutionManager.STATUS_PAGE_SIZE;
            Int32 recordCount          = 0;
            List <SolutionEntity> list = null;

            if (pid <= 0 && String.IsNullOrEmpty(userName) && String.IsNullOrEmpty(languageType) && String.IsNullOrEmpty(resultType))
            {
                recordCount = SolutionManager.CountSolutions(cid, -1, null, null, null);
                list        = SolutionRepository.Instance.GetEntities(cid, -1, null, LanguageType.Null, new Nullable <ResultType>(), -1,
                                                                      pageIndex, pageSize, recordCount);
            }
            else
            {
                if (!String.IsNullOrEmpty(userName) && (!RegexVerify.IsUserName(userName) || !SQLValidator.IsSafe(userName)))
                {
                    throw new InvalidInputException("Username is INVALID!");
                }
                if (!String.IsNullOrEmpty(languageType) && !RegexVerify.IsNumeric(languageType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }
                if (!String.IsNullOrEmpty(resultType) && !RegexVerify.IsNumeric(resultType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                recordCount = SolutionManager.CountSolutions(cid, pid, userName, languageType, resultType);
                list        = SolutionRepository.Instance.GetEntities(
                    cid, pid, userName,
                    (String.IsNullOrEmpty(languageType) ? LanguageType.Null : LanguageType.FromLanguageID(Convert.ToByte(languageType))),
                    (String.IsNullOrEmpty(resultType) ? new Nullable <ResultType>() : (ResultType)Convert.ToByte(resultType)),
                    (String.IsNullOrEmpty(order) ? -1 : Convert.ToInt32(order)),
                    pageIndex, pageSize, recordCount);
            }

            return(list.ToPagedList(pageSize, recordCount));
        }
Exemplo n.º 25
0
        /// <summary>
        /// 获取帖子总数(无缓存)
        /// </summary>
        /// <param name="fpids">帖子ID列表</param>
        /// <param name="ftids">主题ID列表</param>
        /// <param name="username">发帖用户名</param>
        /// <param name="title">帖子标题</param>
        /// <param name="content">帖子内容</param>
        /// <param name="isHide">是否隐藏</param>
        /// <param name="startDate">发帖开始时间</param>
        /// <param name="endDate">发帖结束时间</param>
        /// <param name="postip">发帖IP</param>
        /// <returns>帖子总数</returns>
        private static Int32 AdminCountForumPosts(String fpids, String ftids, String username, String title, String content, String isHide, String startDate, String endDate, String postip)
        {
            DateTime dtStart = DateTime.MinValue, dtEnd = DateTime.MinValue;

            fpids = fpids.SearchOptimized();
            ftids = ftids.SearchOptimized();

            if (!String.IsNullOrEmpty(fpids) && !RegexVerify.IsNumericIDs(fpids))
            {
                throw new InvalidRequstException(RequestType.ForumPost);
            }

            if (!String.IsNullOrEmpty(ftids) && !RegexVerify.IsNumericIDs(ftids))
            {
                throw new InvalidRequstException(RequestType.ForumTopic);
            }

            return(ForumPostRepository.Instance
                   .CountEntities(fpids, ftids, username, title, content,
                                  (!String.IsNullOrEmpty(isHide) ? "1".Equals(isHide, StringComparison.OrdinalIgnoreCase) : new Nullable <Boolean>()),
                                  (!String.IsNullOrEmpty(startDate) && DateTime.TryParse(startDate, out dtStart) ? dtStart : new Nullable <DateTime>()),
                                  (!String.IsNullOrEmpty(endDate) && DateTime.TryParse(endDate, out dtEnd) ? dtEnd : new Nullable <DateTime>()), postip));
        }
Exemplo n.º 26
0
        private static Boolean AdminGetSolutionParams(String sids, String cid, String pid, String name, String lang, String type, String startDate, String endDate,
                                                      out String solutionIDs, out Int32 problemID, out Int32 contestID, out String userName, out LanguageType languageType, out ResultType?resultType, out DateTime?dtStart, out DateTime?dtEnd)
        {
            Boolean noCondition = true;
            String  dateFormat  = "yyyy-MM-dd HH:mm:ss";

            solutionIDs  = String.Empty;
            contestID    = -1;
            problemID    = -1;
            userName     = String.Empty;
            languageType = LanguageType.Null;
            resultType   = new Nullable <ResultType>();
            dtStart      = null;
            dtEnd        = null;

            if (!String.IsNullOrEmpty(sids))
            {
                solutionIDs = sids.SearchOptimized();

                if (!RegexVerify.IsNumericIDs(solutionIDs))
                {
                    throw new InvalidRequstException(RequestType.Solution);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(cid))
            {
                if (!Int32.TryParse(cid, out contestID))
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                if (contestID < ContestRepository.NONECONTEST)
                {
                    throw new InvalidRequstException(RequestType.Contest);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(pid))
            {
                if (!Int32.TryParse(pid, out problemID))
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                if (problemID < ConfigurationManager.ProblemSetStartID)
                {
                    throw new InvalidRequstException(RequestType.Problem);
                }

                noCondition = false;
            }

            if (!String.IsNullOrEmpty(name))
            {
                if (!RegexVerify.IsUserName(name))
                {
                    throw new InvalidRequstException(RequestType.User);
                }

                userName    = name;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(lang))
            {
                Byte langType = Byte.MaxValue;

                if (!Byte.TryParse(lang, out langType))
                {
                    throw new InvalidInputException("Language Type is INVALID!");
                }

                languageType = LanguageType.FromLanguageID(langType);
                noCondition  = false;
            }

            if (!String.IsNullOrEmpty(type))
            {
                Byte resType = Byte.MaxValue;

                if (!Byte.TryParse(type, out resType))
                {
                    throw new InvalidInputException("Result Type is INVALID!");
                }

                resultType  = (ResultType)resType;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(startDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(startDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtStart     = temp;
                noCondition = false;
            }

            if (!String.IsNullOrEmpty(endDate))
            {
                DateTime temp;
                if (!DateTime.TryParseExact(endDate, dateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out temp))
                {
                    throw new InvalidInputException("Datetime is INVALID!");
                }

                dtEnd = temp;

                if (dtStart.HasValue && dtStart.Value >= dtEnd.Value)
                {
                    throw new InvalidInputException("Start date CANNOT be later than end date!");
                }

                noCondition = false;
            }

            return(noCondition);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 尝试注册用户
        /// </summary>
        /// <param name="entity">用户实体</param>
        /// <param name="password">密码</param>
        /// <param name="password2">重复密码</param>
        /// <param name="checkCode">验证码</param>
        /// <param name="userip">用户IP</param>
        /// <returns>执行结果</returns>
        public static IMethodResult SignUp(UserEntity entity, String password, String password2, String checkCode, String userip)
        {
            if (!CheckCodeStatus.VerifyCheckCode(checkCode))
            {
                return(MethodResult.Failed("The verification code you input didn't match the picture, Please try again!"));
            }

            if (String.IsNullOrEmpty(entity.UserName))
            {
                return(MethodResult.Failed("Username can not be NULL!"));
            }

            if (!RegexVerify.IsUserName(entity.UserName) || !SQLValidator.IsNonNullANDSafe(entity.UserName))
            {
                return(MethodResult.Failed("Username can not contain illegal characters!"));
            }

            if (!KeywordsFilterManager.IsUserNameLegal(entity.UserName))
            {
                return(MethodResult.Failed("Username can not contain illegal keywords!"));
            }

            if (entity.UserName.Length > UserRepository.USERNAME_MAXLEN)
            {
                return(MethodResult.Failed("Username is too long!"));
            }

            if (String.IsNullOrEmpty(password))
            {
                return(MethodResult.Failed("Password can not be NULL!"));
            }

            if (!String.Equals(password, password2))
            {
                return(MethodResult.Failed("Two passwords are not match!"));
            }

            if (String.IsNullOrEmpty(entity.Email))
            {
                return(MethodResult.Failed("Email address can not be NULL!"));
            }

            if (!RegexVerify.IsEmail(entity.Email))
            {
                return(MethodResult.Failed("Email address is INVALID!"));
            }

            if (entity.Email.Length > UserRepository.EMAIL_MAXLEN)
            {
                return(MethodResult.Failed("Email address is too long!"));
            }

            if (!String.IsNullOrEmpty(entity.NickName) && entity.NickName.Length > UserRepository.NICKNAME_MAXLEN)
            {
                return(MethodResult.Failed("Nick Name is too long!"));
            }

            if (!KeywordsFilterManager.IsUserNameLegal(entity.NickName))
            {
                return(MethodResult.Failed("Nick Name can not contain illegal keywords!"));
            }

            if (!String.IsNullOrEmpty(entity.School) && entity.School.Length > UserRepository.SCHOOL_MAXLEN)
            {
                return(MethodResult.Failed("School Name is too long!"));
            }

            if (UserRepository.Instance.ExistsEntity(entity.UserName))
            {
                return(MethodResult.Failed("The username \"{0}\" has already existed!", entity.UserName));
            }

            if (!UserIPStatus.CheckLastRegisterTime(userip))
            {
                return(MethodResult.Failed("You can only register one user from single ip in {0} seconds!", ConfigurationManager.RegisterInterval.ToString()));
            }

            entity.PassWord   = PassWordEncrypt.Encrypt(entity.UserName, password);
            entity.NickName   = HtmlEncoder.HtmlEncode(entity.NickName);
            entity.Permission = PermissionType.None;
            entity.CreateIP   = userip;
            entity.CreateDate = DateTime.Now;

            try
            {
                if (UserRepository.Instance.InsertEntity(entity) == 0)
                {
                    return(MethodResult.Failed("User Registration Failed!"));
                }
            }
            catch (System.Exception ex)
            {
                return(MethodResult.Failed(ex.Message));
            }

            UserCache.RemoveRanklistUserCountCache();//删除缓存

            return(MethodResult.SuccessAndLog("User sign up"));
        }
Exemplo n.º 28
0
        /// <summary>
        /// 尝试更新用户信息
        /// </summary>
        /// <param name="entity">对象实体</param>
        /// <param name="currentPassword">当前密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="newPassword2">重复新密码</param>
        /// <param name="result">执行结果</param>
        /// <returns>执行结果</returns>
        public static IMethodResult UpdateUserInfo(UserEntity entity, String currentPassword, String newPassword, String newPassword2)
        {
            if (String.IsNullOrEmpty(currentPassword))
            {
                return(MethodResult.Failed("Current password can not be NULL!"));
            }
            else
            {
                entity.UserName = UserManager.CurrentUserName;
                entity.NickName = HtmlEncoder.HtmlEncode(entity.NickName);
                currentPassword = PassWordEncrypt.Encrypt(entity.UserName, currentPassword);
            }

            if (!String.Equals(newPassword, newPassword2))
            {
                return(MethodResult.Failed("Two new passwords are not match!"));
            }

            if (String.IsNullOrEmpty(entity.Email))
            {
                return(MethodResult.Failed("Email address can not be NULL!"));
            }

            if (!RegexVerify.IsEmail(entity.Email))
            {
                return(MethodResult.Failed("Email address is INVALID!"));
            }

            if (entity.Email.Length > UserRepository.EMAIL_MAXLEN)
            {
                return(MethodResult.Failed("Email address is too long!"));
            }

            if (!String.IsNullOrEmpty(entity.NickName) && entity.NickName.Length > UserRepository.NICKNAME_MAXLEN)
            {
                return(MethodResult.Failed("Nick Name is too long!"));
            }

            if (!KeywordsFilterManager.IsUserNameLegal(entity.NickName))
            {
                return(MethodResult.Failed("Nick Name can not contain illegal keywords!"));
            }

            if (!String.IsNullOrEmpty(entity.School) && entity.School.Length > UserRepository.SCHOOL_MAXLEN)
            {
                return(MethodResult.Failed("School Name is too long!"));
            }

            if (!String.IsNullOrEmpty(newPassword))
            {
                entity.PassWord = PassWordEncrypt.Encrypt(entity.UserName, newPassword);
            }

            try
            {
                if (UserRepository.Instance.UpdateEntityForUser(entity, currentPassword) <= 0)
                {
                    return(MethodResult.Failed("Current password is wrong!"));
                }
            }
            catch (System.Exception ex)
            {
                return(MethodResult.Failed(ex.Message));
            }

            return(MethodResult.SuccessAndLog("User update info"));
        }
Exemplo n.º 29
0
        /// <summary>
        /// 申请找回密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="email">电子邮箱</param>
        /// <param name="userip">用户IP</param>
        /// <param name="checkCode">验证码</param>
        /// <param name="link">找回密码链接</param>
        /// <returns>是否可以申请</returns>
        public static async Task <IMethodResult> RequestResetUserPassword(String userName, String email, String userip, String checkCode, String link)
        {
            if (!CheckCodeStatus.VerifyCheckCode(checkCode))
            {
                return(MethodResult.Failed("The verification code you input didn't match the picture, Please try again!"));
            }

            if (!RegexVerify.IsUserName(userName))
            {
                return(MethodResult.InvalidRequest(RequestType.User));
            }

            if (!RegexVerify.IsEmail(email))
            {
                return(MethodResult.Failed("Email address is INVALID!"));
            }

            UserEntity user = UserManager.InternalGetUserByNameAndEmail(userName, email);

            if (user == null)
            {
                return(MethodResult.Failed("The username \"{0}\" doesn't exist or the email is wrong!", userName));
            }

            if (user.IsLocked)
            {
                return(MethodResult.Failed("The user is locked, please contact the administrator!"));
            }

            if (String.IsNullOrEmpty(user.Email) || "NULL".Equals(user.Email, StringComparison.OrdinalIgnoreCase))
            {
                return(MethodResult.Failed("The user has no email, please contact the administrator!"));
            }

            Random rand = new Random(DateTime.Now.Millisecond);

            UserForgetPasswordEntity ufp = new UserForgetPasswordEntity()
            {
                UserName   = userName,
                SubmitDate = DateTime.Now,
                SubmitIP   = userip,
                HashKey    = MD5Encrypt.EncryptToHexString(String.Format("{0}-{1}-{2}", userName, DateTime.Now.Ticks.ToString(), rand.Next(DateTime.Now.Millisecond)), true)
            };

            Boolean success = UserForgetPasswordRepository.Instance.InsertEntity(ufp) > 0;

            if (!success)
            {
                return(MethodResult.Failed("Failed to process your request!"));
            }

            String url         = ConfigurationManager.DomainUrl + ((link[0] == '/') ? link.Substring(1) : link);
            String mailSubject = ConfigurationManager.OnlineJudgeName + " Password Recovery";
            String mailContent = UserForgetPasswordManager.GetMailContent(userName, url + ufp.HashKey.ToLowerInvariant());

            try
            {
                await MailClient.SendMailAsync(ConfigurationManager.EmailSMTPServer, ConfigurationManager.EmailAddresser, email, mailSubject, mailContent, true, true, ConfigurationManager.EmailUsername, ConfigurationManager.EmailPassword);
            }
            catch
            {
                return(MethodResult.Failed("Failed to send a password reset link to your email address."));
            }

            return(MethodResult.SuccessAndLog("User forget password, name = {0}", userName));
        }
Exemplo n.º 30
0
        /// <summary>
        /// 尝试发送邮件
        /// </summary>
        /// <param name="model">邮件实体</param>
        /// <param name="error">出错信息</param>
        /// <returns>是否发送成功</returns>
        public static Boolean TrySendUserMail(UserMailEntity entity, out String error)
        {
            if (!UserManager.IsUserLogined)
            {
                error = "Please login first!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.Title))
            {
                error = "Title can not be NULL!";
                return(false);
            }

            if (entity.Title.Length > UserMailRepository.TITLE_MAXLEN)
            {
                error = "Title is too long!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.Content) || entity.Content.Length < UserMailRepository.CONTENT_MINLEN)
            {
                error = "Content is too short!";
                return(false);
            }

            if (entity.Content.Length > UserMailRepository.CONTENT_MAXLEN)
            {
                error = "Content is too long!";
                return(false);
            }

            if (String.IsNullOrEmpty(entity.ToUserName))
            {
                error = "Username can not be NULL!";
                return(false);
            }

            if (!RegexVerify.IsUserName(entity.ToUserName))
            {
                error = "Username is INVALID!";
                return(false);
            }

            if (String.Equals(ConfigurationManager.SystemAccount, entity.ToUserName, StringComparison.OrdinalIgnoreCase))
            {
                error = "You can not send mail to system account!";
                return(false);
            }

            if (String.Equals(UserManager.CurrentUserName, entity.ToUserName, StringComparison.OrdinalIgnoreCase))
            {
                error = "You can not send mail to yourself!";
                return(false);
            }

            if (!UserSubmitStatus.CheckLastSubmitUserMailTime(UserManager.CurrentUserName))
            {
                throw new InvalidInputException(String.Format("You can not submit user mail more than twice in {0} seconds!", ConfigurationManager.SubmitInterval.ToString()));
            }

            if (!UserManager.InternalExistsUser(entity.ToUserName))
            {
                error = String.Format("The username \"{0}\" doesn't exist!", entity.ToUserName);
                return(false);
            }

            entity.Title        = HtmlEncoder.HtmlEncode(entity.Title);
            entity.Content      = HtmlEncoder.HtmlEncode(entity.Content);
            entity.FromUserName = UserManager.CurrentUserName;

            if (!UserMailManager.InternalSendUserMail(entity))
            {
                error = "Failed to send your mail";
                return(false);
            }

            error = String.Empty;
            return(true);
        }