예제 #1
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"));
        }
예제 #2
0
        /// <summary>
        /// 增加一条回帖
        /// </summary>
        /// <param name="post">帖子实体</param>
        /// <param name="topic">主题实体</param>
        /// <param name="parentPost">回复的帖子实体</param>
        /// <param name="postip">发布者IP</param>
        /// <param name="link">当前页面地址</param>
        /// <returns>是否成功增加</returns>
        public static Boolean InsertForumPost(ForumPostEntity post, ForumTopicEntity topic, ForumPostEntity parentPost, String postip, String link)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(post.Title))
            {
                throw new InvalidInputException("Reply title can not be NULL!");
            }

            if (post.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Reply title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(post.Title))
            {
                throw new InvalidInputException("Reply title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(post.Content) || post.Content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Reply content is too short!");
            }

            if (post.Content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Reply content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(post.Content))
            {
                throw new InvalidInputException("Reply content can not contain illegal keywords!");
            }

            if (parentPost.Deepth + 1 < ForumPostRepository.DEEPTH_MIN)
            {
                throw new InvalidInputException("Reply deepth is INVALID!");
            }

            if (parentPost.Deepth + 1 > ForumPostRepository.DEEPTH_MAX)
            {
                throw new InvalidInputException("Reply deepth is too deep!");
            }

            if (topic.IsLocked)
            {
                throw new NoPermissionException("You have no privilege to reply the post!");
            }

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

            post.TopicID      = parentPost.TopicID;
            post.Title        = HtmlEncoder.HtmlEncode(post.Title);
            post.Content      = HtmlEncoder.HtmlEncode(post.Content);
            post.UserName     = UserManager.CurrentUserName;
            post.Deepth       = parentPost.Deepth + 1;
            post.ParentPostID = parentPost.PostID;
            post.PostDate     = DateTime.Now;
            post.PostIP       = postip;

            Boolean success = ForumPostRepository.Instance.InsertEntity(post) > 0;

            if (success && !String.Equals(parentPost.UserName, post.UserName))
            {
                if (ConfigurationManager.ReplyPostMailNotification)
                {
                    try
                    {
                        UserMailEntity mail = new UserMailEntity();
                        String         url  = ConfigurationManager.DomainUrl + ((link[0] == '/') ? link.Substring(1) : link);

                        mail.FromUserName = ConfigurationManager.SystemAccount;
                        mail.ToUserName   = parentPost.UserName;
                        mail.Title        = "Your post has new reply!";
                        mail.Content      =
                            String.Format("Your post \"{0}\" has new reply, <br/>", parentPost.Title) +
                            String.Format("Please visit <a href=\"{0}\" target=\"_blank\">{0}</a>", url);

                        UserMailManager.InternalSendUserMail(mail);
                    }
                    catch { }
                }
            }

            return(success);
        }
예제 #3
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"));
        }
예제 #4
0
        /// <summary>
        /// 发布新主题
        /// </summary>
        /// <param name="topic">主题实体</param>
        /// <param name="cid">竞赛ID</param>
        /// <param name="pid">题目ID</param>
        /// <param name="content">主题帖内容</param>
        /// <param name="postip">发布者IP</param>
        /// <returns>是否成功发布</returns>
        public static Boolean InsertForumTopic(ForumTopicEntity topic, String cid, String pid, String content, String postip)
        {
            if (!UserManager.IsUserLogined)
            {
                throw new UserUnLoginException();
            }

            if (String.IsNullOrEmpty(topic.Title))
            {
                throw new InvalidInputException("Topic title can not be NULL!");
            }

            if (topic.Title.Length > ForumPostRepository.TITLE_MAXLEN)
            {
                throw new InvalidInputException("Topic title is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(topic.Title))
            {
                throw new InvalidInputException("Topic title can not contain illegal keywords!");
            }

            if (String.IsNullOrEmpty(content) || content.Length < ForumPostRepository.POST_MINLEN)
            {
                throw new InvalidInputException("Topic content is too short!");
            }

            if (content.Length > ForumPostRepository.POST_MAXLEN)
            {
                throw new InvalidInputException("Topic content is too long!");
            }

            if (!KeywordsFilterManager.IsForumPostContentLegal(content))
            {
                throw new InvalidInputException("Topic content can not contain illegal keywords!");
            }

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

            topic.Type       = ForumTopicManager.GetForumTopicType(cid, pid);
            topic.RelativeID = (topic.Type == ForumTopicType.Default ? 0 : ForumTopicManager.GetRelativeID(cid, pid));

            if (topic.Type == ForumTopicType.Problem && !ProblemManager.InternalExistsProblem(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Problem);
            }
            else if (topic.Type == ForumTopicType.Contest && !ContestManager.InternalExistsContest(topic.RelativeID))
            {
                throw new InvalidRequstException(RequestType.Contest);
            }

            topic.UserName = UserManager.CurrentUserName;
            topic.LastDate = DateTime.Now;
            topic.Title    = HtmlEncoder.HtmlEncode(topic.Title);
            content        = HtmlEncoder.HtmlEncode(content);

            Boolean success = ForumTopicRepository.Instance.InsertEntity(topic, content, postip) > 0;

            if (success)
            {
                ForumTopicCache.IncreaseForumTopicCountCache(topic.Type, topic.RelativeID);//更新缓存

                if (topic.Type == ForumTopicType.Problem)
                {
                    ForumTopicCache.IncreaseForumTopicCountCache(ForumTopicType.Default, 0);//更新缓存
                }
            }

            return(success);
        }