Example #1
0
 protected override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     base.OnActionExecuting(filterContext);
     SysUser user = null;
     if (Request.IsAuthenticated)
     {
         try
         {
             user = User.Identity.GetUserName().FromJsonString<SysUser>();
             var singleOrDefault = UserInfoRepo.GetByPredicate(x => x.SysUser.Id == user.Id).SingleOrDefault();
             if (singleOrDefault != null)
             {
                 Uid = singleOrDefault.Id;
                 HeadPic = singleOrDefault.HeadPic;
                 LoginName = singleOrDefault.SysUser.NickName;
                 UserTypes = singleOrDefault.SysUser.UserType;
                 ViewBag.UserId = Uid;
                 ViewBag.NickName = LoginName;
             }
         }
         catch
         {
         }
     }
     ViewBag.HeadPic = HeadPic;
     ViewBag.Uid = Uid;
 }
        /// <summary>
        /// 邮箱绑定
        /// </summary>
        /// <param name="validateCode"></param>
        /// <param name="nweEmail"></param>
        /// <param name="userName"></param>
        /// <returns></returns>
        public OperationResult ChangeEmail(string validateCode, string nweEmail, string userName)
        {
            var severCode = GetValidateCode(userName, CodeType.找回密码);

            if (severCode == null || severCode.Code != validateCode)
            {
                return(new OperationResult(OperationResultType.ValidError, "验证码错误", 0));
            }
            var userInfo  = UserInfoRepo.GetByPredicate(x => x.SysUser.UserName == userName);
            var userInfos = userInfo as UserInfo[] ?? userInfo.ToArray();

            if (!userInfos.Any())
            {
                return(new OperationResult(OperationResultType.ValidError, "身份信息错误", 0));
            }
            //smtp.163.com
            string senderServerIp = "123.125.50.133";
            //string senderServerIp = "smtp.163.com";
            //smtp.gmail.com
            //string senderServerIp = "74.125.127.109";
            //string senderServerIp = "smtp.qq.com";
            //string senderServerIp = "58.251.149.147";
            //string senderServerIp = "smtp.sina.com";
            string url = ConfigurationManager.AppSettings["ServerHost"] + "Web/Home/EmailBack?e=" + DataCode.Base64Encrypt(nweEmail, Encoding.UTF8) + "&u=" + userInfos.Single().Id + "&p=" + userInfos.Single().SysUser.PasswordHash + "";

            url = url.Replace("+", "%2B");
            string fromMailAddress = ConfigurationManager.AppSettings["Email"];//"*****@*****.**";
            string subjectInfo     = "邮箱绑定【西部鞋都】";
            string bodyInfo        = "你正在进行邮箱绑定操作,如果是你本人操作,请点击下面的链接完成邮箱绑定。【西部鞋都】<br/> <a href=\"" + url + "\">" + url + "</a>";
            string mailUsername    = "******";
            string mailPassword    = ConfigurationManager.AppSettings["EmailPwd"]; //发送邮箱的密码
            string mailPort        = "25";

            MailSender emailSender = new MailSender(senderServerIp, nweEmail, fromMailAddress, subjectInfo, bodyInfo, mailUsername, mailPassword, mailPort, false, false);

            emailSender.Send();
            return(new OperationResult(OperationResultType.Success, "请到邮箱完成验证", 0));
        }