/// <summary> /// 尝试将使用用户名密码登陆系统 /// </summary> /// <param name="userName">用户名</param> /// <param name="passWord">密码</param> /// <param name="userip">用户IP</param> /// <returns>返回是否成功登陆,若失败则返回出错信息</returns> public static IMethodResult SignIn(String userName, String passWord, String userip) { UserEntity user = null; String error = TryGetUserByUsernameAndPassword(userName, passWord, out user); if (!String.IsNullOrEmpty(error)) { return(MethodResult.FailedAndLog(error)); } if (AdminManager.InternalCheckPermission(user.Permission, PermissionType.HttpJudge)) { return(MethodResult.FailedAndLog("You can not login a httpjudge account!")); } try { Int32 unreadMailCount = UserMailManager.InternalCountUserUnReadMails(user.UserName); UserBrowserStatus.SetCurrentUserBrowserStatus(user.UserName, user.Permission, unreadMailCount); UserSubmitStatus.InitLastSubmitTime(user.UserName); UserCurrentStatus.SetCurrentUserStatus(user); UpdateLoginInfomation(userName, userip); } catch (System.Exception ex) { return(MethodResult.Failed(ex.Message)); } return(MethodResult.SuccessAndLog("User sign in")); }
/// <summary> /// 根据ID得到一个邮件实体 /// </summary> /// <param name="id">邮件ID</param> /// <returns>邮件实体</returns> public static UserMailEntity GetUserMail(Int32 id) { if (!UserManager.IsUserLogined) { throw new UserUnLoginException(); } if (id <= 0) { throw new InvalidRequstException(RequestType.UserMail); } String userName = UserManager.CurrentUserName; UserMailEntity entity = UserMailRepository.Instance.GetEntity(userName, id); if (entity == null) { throw new NullResponseException(RequestType.UserMail); } if (!entity.IsRead) { UserMailManager.UpdateUserMailRead(entity); } return(entity); }
/// <summary> /// 获取用户邮件 /// </summary> /// <param name="pageIndex">页面索引</param> /// <returns>用户邮件列表</returns> public static PagedList <UserMailEntity> GetUserMails(Int32 pageIndex) { if (!UserManager.IsUserLogined) { throw new UserUnLoginException(); } Int32 pageSize = UserMailManager.MAILBOX_PAGE_SIZE; Int32 recordCount = UserMailManager.CountUserMails(); String userName = UserManager.CurrentUserName; UserMailCache.RemoveUserUnReadMailCountCache(userName);//删除缓存 return(UserMailRepository.Instance .GetEntities(userName, pageIndex, pageSize, recordCount) .ToPagedList(pageSize, recordCount)); }
/// <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); }
/// <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); }