Exemplo n.º 1
0
        public ActionResult Send(FormCollection form)
        {
            String result;
            UserMailEntity mail = new UserMailEntity()
            {
                ToUserName = form["tousername"],
                Title = form["title"],
                Content = form["content"]
            };

            if (UserMailManager.TrySendUserMail(mail, out result))
            {
                return RedirectToSuccessMessagePage("Your mail has been successfully sent!");
            }
            else
            {
                return RedirectToErrorMessagePage(result);
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 发送用户邮件
        /// </summary>
        /// <param name="model">邮件实体</param>
        /// <returns>是否发送成功</returns>
        internal static Boolean InternalSendUserMail(UserMailEntity entity)
        {
            entity.SendDate = DateTime.Now;
            entity.IsRead = false;
            entity.IsDeleted = false;

            Int32 result = UserMailRepository.Instance.InsertEntity(entity);

            if (result > 0)
            {
                UserMailCache.RemoveUserUnReadMailCountCache(entity.ToUserName);//删除缓存
            }

            return (result > 0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新一条邮件的状态
        /// </summary>
        /// <param name="model">对象实体</param>
        /// <returns>是否成功更新</returns>
        private static Boolean UpdateUserMailRead(UserMailEntity entity)
        {
            Boolean success = false;

            try
            {
                entity.IsRead = true;
                success = UserMailRepository.Instance.UpdateEntityIsRead(entity) > 0;
            }
            finally
            {
                if (success)
                {
                    UserMailCache.RemoveUserUnReadMailCountCache(entity.ToUserName);//删除缓存
                }
            }

            return success;
        }
Exemplo n.º 5
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;
        }