Example #1
0
        public ActionResult ChangePassword(ChangePassword pwdForm)
        {
            UserModel userModel = new UserModel();
            UserInfo userInfo = userModel.GetUserInfo(User.Identity.Name);

            userInfo.Password = userModel.PasswordEncrypt(pwdForm.NewPassword);
            userModel.Save();

            userModel.SignOut();

            return RedirectToAction("Login");
        }
Example #2
0
        public ActionResult Register(RegisterModel registerInfo, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            if (ModelState.IsValid)
            {
                if (Session["ValidateCode"] == null || registerInfo.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return View(registerInfo);
                }

                UserModel userModel = new UserModel();
                UserInfo userInfo = new UserInfo();

                userInfo.Name = registerInfo.UserName;
                userInfo.Password = userModel.PasswordEncrypt(registerInfo.Password);
                userInfo.Email = registerInfo.Email;
                userInfo.GradeId = 1;
                userInfo.CreateTime = DateTime.Now;
                userInfo.Photo = "/Contents/Images/default_user_photo.png";

                userModel.Add(userInfo);

                UserMessage userMsg = new UserMessage();
                userMsg.UserId = userInfo.Id;
                userMsg.MsgTitle = "系统通知";
                userMsg.MsgContent = userInfo.Name + "欢迎您来到宅食府,希望能为您提供优质的服务。";
                userMsg.CreateTime = DateTime.Now;
                userMsg.Readed = false;
                userModel.Add(userMsg);

                userModel.SignIn(userInfo, false);
            }

            if (!string.IsNullOrWhiteSpace(returnUrl))
                return Redirect(returnUrl);

            return RedirectToAction("Index", "Shop");
        }
Example #3
0
        public ActionResult FindPassword(FindPassword formValues)
        {
            if (User.Identity.IsAuthenticated)
                return RedirectToAction("index");

            if (ModelState.IsValid)
            {
                var emailReg = new System.Text.RegularExpressions.Regex("^(\\w)+(\\.\\w+)*@[\\w\\d]+((\\.\\w+)+)$");
                if (formValues.UserEmail == null || !emailReg.IsMatch(formValues.UserEmail))
                {
                    ModelState.AddModelError("UserEmail", "邮箱格式不正确");
                    return View(formValues);
                }
                else if (Session["ValidateCode"] == null
                   || formValues.ValidateCode == null
                   || formValues.ValidateCode.ToLower() != Session["ValidateCode"].ToString().ToLower())
                {
                    ModelState.AddModelError("ValidateCode", "验证码错误");
                    return View(formValues);
                }

                UserModel userModel = new UserModel();
                UserInfo userInfo = userModel.GetUserInfo(formValues.UserEmail);
                string newPwd = ImageValidate.CreateCode(6);//生生6位数的随机密码
                userInfo.Password = userModel.PasswordEncrypt(newPwd);
                userModel.Save();
                //发送新密码
                ZsfProject.Tools.SendEmail.ResetPassword(formValues.UserEmail, newPwd);
            }

            return RedirectToAction("FindPassword", new { step = 2 });
        }