Exemple #1
0
        public IActionResult Index(Models.ReleaseRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.Title) || requestModel.Title == "")
            {
                return(APIReturnMethod.ReturnFailed("标题不能为空"));
            }
            if (string.IsNullOrEmpty(requestModel.Contents) || requestModel.Contents == "")
            {
                return(APIReturnMethod.ReturnFailed("内容不能为空"));
            }
            //
            Entity.m_CmsContents entity = new Entity.m_CmsContents();
            entity.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            entity.ImgUrl      = string.Empty;
            entity.StateCode   = 1;
            entity.PostTime    = DateTime.Now;
            entity.PlusCount   = 0;
            entity.LastTime    = DateTime.Now;
            entity.Tags        = "";
            entity.ReadCount   = 0;
            entity.Title       = requestModel.Title;
            entity.AccountId   = requestModel.AccountId;
            entity.AnswerCount = 0;
            entity.ChannelId   = requestModel.ChannelId;
            var repository = _unitOfWork.GetRepository <Entity.m_CmsContents>();

            repository.Insert(entity);
            int resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #2
0
        public IActionResult Password(Models.PasswordUpdateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.Password))
            {
                return(APIReturnMethod.ReturnFailed("请输入您的原登录密码!"));
            }
            if (string.IsNullOrEmpty(requestModel.NewPassword))
            {
                return(APIReturnMethod.ReturnFailed("请输入您的新登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query().Where(q => q.AccountId == requestModel.AccountId && q.Password == TextHelper.MD5Encrypt(requestModel.Password)).FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的原登录密码!"));
            }
            accountData.Password = TextHelper.MD5Encrypt(requestModel.NewPassword);
            repository.Update(accountData);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
        public IActionResult Put([FromBody] Models.ThemeEditRequestModel requestModel)
        {
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题内容"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_DocsTheme>();

            Entity.m_DocsTheme model = repository.Query().Where(q => q.ThemeId == requestModel.ThemeId).FirstOrDefault();
            if (model == null)
            {
                return(APIReturnMethod.ReturnFailed("您要编辑的文档主题信息不存在!"));
            }
            if (model.AccountId != requestModel.AccountId)
            {
                return(APIReturnMethod.ReturnFailed("您无权对当前的数据进行编辑操作!"));
            }
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.LastTime    = DateTime.Now;
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.VersionText = "";

            repository.Update(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
        public IActionResult Post([FromBody] Models.ThemeCreateRequestModel requestModel)
        {
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档主题内容"));
            }
            Entity.m_DocsTheme model = new Entity.m_DocsTheme();
            model.AppendTime  = DateTime.Now;
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.IsShow      = true;
            model.LastTime    = DateTime.Now;
            model.PlusCount   = 0;
            model.ReadCount   = 0;
            model.Tags        = "";
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.AccountId   = requestModel.AccountId;
            model.VersionText = "";
            var repository = _unitOfWork.GetRepository <Entity.m_DocsTheme>();

            repository.Insert(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #5
0
        public IActionResult Index(Models.ContentsEditRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.Title) || requestModel.Title == "")
            {
                return(APIReturnMethod.ReturnFailed("标题不能为空"));
            }
            if (string.IsNullOrEmpty(requestModel.Contents) || requestModel.Contents == "")
            {
                return(APIReturnMethod.ReturnFailed("内容不能为空"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_CmsContents>();

            //
            Entity.m_CmsContents entity = repository.Query().Where(q => q.ContentsId == requestModel.ContentsId).FirstOrDefault();
            entity.Contents   = requestModel.Contents;//Framework.Core.HtmlFilter.SanitizeHtml(model.Contents);
            entity.LastTime   = DateTime.Now;
            entity.Title      = requestModel.Title;
            entity.ContentsId = requestModel.ContentsId;
            entity.ChannelId  = requestModel.ChannelId;

            repository.Update(entity);
            int resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #6
0
        public IActionResult Document(Models.EditDocumentRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档内容"));
            }
            var repository = _unitOfWork.GetRepository <Entity.m_Docs>();

            Entity.m_Docs model = repository.Query().Where(q => q.DocsId == requestModel.DocsId).FirstOrDefault();
            if (model == null)
            {
                return(APIReturnMethod.ReturnFailed("您要编辑的文档内容信息不存在!"));
            }
            if (model.AccountId != requestModel.AccountId)
            {
                return(APIReturnMethod.ReturnFailed("您无权对当前的数据进行编辑操作!"));
            }
            model.Contents   = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.LastTime   = DateTime.Now;
            model.Title      = HtmlFilter.StripHtml(requestModel.Title);
            model.ShortTitle = HtmlFilter.StripHtml(requestModel.ShortTitle);

            repository.Update(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
Exemple #7
0
        public IActionResult Document(Models.DocsContentsCreateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);
            if (requestModel.Title.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档标题"));
            }
            if (requestModel.Contents.Trim().Length <= 0)
            {
                return(APIReturnMethod.ReturnFailed("请输入文档内容"));
            }
            Entity.m_Docs model = new Entity.m_Docs();
            model.AppendTime  = DateTime.Now;
            model.Contents    = HtmlFilter.SanitizeHtml(requestModel.Contents);
            model.IsShow      = true;
            model.LastTime    = DateTime.Now;
            model.PlusCount   = 0;
            model.ReadCount   = 0;
            model.Tags        = "";
            model.Title       = HtmlFilter.StripHtml(requestModel.Title);
            model.AccountId   = requestModel.AccountId;
            model.VersionText = "";
            model.ThemeId     = requestModel.ThemeId;
            model.ShortTitle  = HtmlFilter.StripHtml(requestModel.ShortTitle);
            model.IsAudit     = true;
            var repository = _unitOfWork.GetRepository <Entity.m_Docs>();

            repository.Insert(model);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }
        /// <summary>
        /// 邮箱验证码发送
        /// </summary>
        /// <param name="email"></param>
        /// <param name="ticket"></param>
        /// <param name="randstr"></param>
        /// <returns></returns>
        public async Task <IActionResult> SendEmailValidateCode(string email, string ticket, string randstr)
        {
            string userIP = Request.HttpContext.Connection.RemoteIpAddress.ToString();
            bool   tencentCaptchaResult = _tencentCaptcha.QueryTencentCaptcha(ticket, randstr, userIP);

            if (!tencentCaptchaResult)
            {
                return(APIReturnMethod.ReturnFailed("你的验证操作没有通过!"));
            }
            Regex regex = new Regex(@"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)");

            if (!regex.IsMatch(email))
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的电子邮箱!"));
            }
            var repository = _unitOfWork.GetRepository <m_Account>();

            if (repository.Query().Where(q => q.AccountName == email).Count() > 0)
            {
                return(APIReturnMethod.ReturnFailed("该电子邮箱已经注册,请勿重复注册!"));
            }

            //邮件发送处理
            string emailCode = new Random().Next(101326, 985963).ToString();

            _memoryCache.Set <string>(email, emailCode);

            string messageContent = string.Format("感谢您的注册,您的验证码为:{0},您可以继续完成您的注册!", emailCode);
            string subject        = "51Core技术网用户注册验证码邮件";

            bool sendResult = await _emailService.SendEmail(email, subject, messageContent);

            //邮件发送内容保存
            m_Sms model = new m_Sms();

            model.Contents = string.Format("邮箱验证码为:{0} 服务器返回结果:{1}", emailCode, sendResult);
            model.IsOk     = sendResult;
            model.Phone    = email;
            model.SendIP   = userIP;
            model.SendTime = DateTime.Now;
            var smsRepository = _unitOfWork.GetRepository <m_Sms>();

            smsRepository.Insert(model);
            _unitOfWork.SaveChanges();
            if (sendResult)
            {
                return(APIReturnMethod.ReturnSuccess("注册验证码发送成功,请注意查收!"));
            }
            return(APIReturnMethod.ReturnFailed("注册验证码发送失败,请稍后再试!"));
        }
Exemple #9
0
        public IActionResult Index(Models.AccountLoginRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.AccountName) || requestModel.AccountName == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录账号!"));
            }
            if (string.IsNullOrEmpty(requestModel.Password) || requestModel.Password == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query()
                              .Where(q => q.AccountName == requestModel.AccountName && q.Password == TextHelper.MD5Encrypt(requestModel.Password.Trim()))
                              .Select(q => new Models.AccountDataModel()
            {
                AccountId     = q.AccountId.Value,
                AccountName   = q.AccountName,
                AddressInfo   = q.AddressInfo,
                Birthday      = q.Birthday,
                Email         = q.Email,
                GroupId       = q.GroupId.Value,
                HeadUrl       = q.HeadUrl,
                LastLoginDate = q.LastLoginDate.Value,
                NickName      = q.NickName,
                Phone         = q.Phone,
                RegisterDate  = q.RegisterDate.Value,
                Sex           = q.Sex,
                StateCode     = q.StateCode.Value,
                Tags          = q.Tags
            })
                              .FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的账号与密码!"));
            }
            if (accountData.StateCode == 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经被禁止登陆!"));
            }
            //将登陆的用户Id存储到会话中
            HttpContext.Session.SetInt32("AccountId", accountData.AccountId);
            HttpContext.Session.SetInt32("RoleId", accountData.GroupId);
            HttpContext.Session.SetString("AccountName", accountData.AccountName);
            HttpContext.Session.SetString("NickName", accountData.NickName);
            HttpContext.Session.SetString("HeadUrl", accountData.HeadUrl);
            HttpContext.Session.SetString("AccountLoginData", JsonConvert.SerializeObject(accountData));
            return(APIReturnMethod.ReturnSuccess(accountData));
        }
Exemple #10
0
        public IActionResult Index(Models.AccountRegisterRequestModel requestModel)
        {
            string Result     = string.Empty;
            var    repository = _unitOfWork.GetRepository <m_Account>();
            var    codeCache  = _memoryCache.Get <string>(requestModel.AccountName);

            if (codeCache == null)
            {
                return(APIReturnMethod.ReturnFailed("该账号与通过验证的账号不一致"));
            }
            if (requestModel.ValidateCode != codeCache)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的注册验证码!"));
            }

            if (repository.Query().Where(q => q.AccountName == requestModel.AccountName).Count() > 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经注册过!"));
            }
            //注册新用户
            m_Account entity = new m_Account();

            entity.HeadUrl       = "/images/avatar.png";
            entity.GroupId       = 1;
            entity.StateCode     = 1;
            entity.LastLoginDate = DateTime.Now;
            entity.NickName      = requestModel.NickName;
            entity.Password      = TextHelper.MD5Encrypt(requestModel.Password);
            entity.Phone         = "";
            entity.RegisterDate  = DateTime.Now;
            entity.AccountName   = requestModel.AccountName;
            entity.Email         = "";
            entity.AddressInfo   = "";
            entity.Birthday      = "";
            entity.Sex           = "男";
            entity.Tags          = "";
            repository.Insert(entity);
            var resultCount = _unitOfWork.SaveChanges();

            if (resultCount > 0)
            {
                return(APIReturnMethod.ReturnSuccess("恭喜您,您的账户已经注册成功!"));
            }
            return(APIReturnMethod.ReturnFailed("抱歉,您的注册失败,请稍后再尝试!"));
        }
Exemple #11
0
        public IActionResult Post([FromBody] Models.LoginRequestModel requestModel)
        {
            if (string.IsNullOrEmpty(requestModel.AccountName) || requestModel.AccountName == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录账号!"));
            }
            if (string.IsNullOrEmpty(requestModel.Password) || requestModel.Password == "")
            {
                return(APIReturnMethod.ReturnFailed("请输入您的登录密码!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query()
                              .Where(q => q.AccountName == requestModel.AccountName && q.Password == TextHelper.MD5Encrypt(requestModel.Password.Trim()))
                              .Select(q => new Models.AcountDataModel()
            {
                AccountId     = q.AccountId.Value,
                AccountName   = q.AccountName,
                AddressInfo   = q.AddressInfo,
                Birthday      = q.Birthday,
                Email         = q.Email,
                GroupId       = q.GroupId.Value,
                HeadUrl       = q.HeadUrl,
                LastLoginDate = q.LastLoginDate.Value,
                NickName      = q.NickName,
                Phone         = q.Phone,
                RegisterDate  = q.RegisterDate.Value,
                Sex           = q.Sex,
                StateCode     = q.StateCode.Value,
                Tags          = q.Tags
            })
                              .FirstOrDefault();

            if (accountData == null)
            {
                return(APIReturnMethod.ReturnFailed("请输入正确的账号与密码!"));
            }
            if (accountData.StateCode == 0)
            {
                return(APIReturnMethod.ReturnFailed("该账号已经被禁止登陆!"));
            }
            return(APIReturnMethod.ReturnSuccess(accountData));
        }
Exemple #12
0
        public IActionResult Information(Models.InformationUpdateRequestModel requestModel)
        {
            requestModel.AccountId = HttpContext.Session.GetInt32("AccountId").GetValueOrDefault(0);

            if (string.IsNullOrEmpty(requestModel.InformationValue))
            {
                return(APIReturnMethod.ReturnFailed("请输入待修改项的值!"));
            }
            var repository  = _unitOfWork.GetRepository <m_Account>();
            var accountData = repository.Query().Where(q => q.AccountId == requestModel.AccountId).FirstOrDefault();

            switch (requestModel.InformationType)
            {
            case 3:
                accountData.Tags = requestModel.InformationValue;
                break;

            case 4:
                accountData.AddressInfo = requestModel.InformationValue;
                break;

            case 5:
                accountData.Sex = requestModel.InformationValue;
                break;

            case 1:
                accountData.NickName = requestModel.InformationValue;
                break;

            case 2:
                accountData.HeadUrl = requestModel.InformationValue;
                break;
            }
            repository.Update(accountData);
            var resultCount = _unitOfWork.SaveChanges();

            return(resultCount > 0 ? APIReturnMethod.ReturnSuccess() : APIReturnMethod.ReturnFailed());
        }