Esempio n. 1
0
        public ActionResult Reg(UserRegisterViewModel userRegisterViewModel, string retUrl)
        {
            userRegisterViewModel.CreateTime = DateTime.Now;
            if (!ModelState.IsValid)
                return Reg();
            //判断验证码是否正确
            if (string.IsNullOrWhiteSpace(userRegisterViewModel.Validate) || userRegisterViewModel.Validate.ToLowerInvariant().Trim() != Session["regValidateCode"].ToString().ToLowerInvariant())
            {
                ModelState.AddModelError("Validate", "验证码不正确,请重新输入");
                return Reg();
            }

            if (!UserService.CheckUserEmail(userRegisterViewModel.Email))
            {
                ModelState.AddModelError("Email","此邮箱已经被注册");
                return Reg();
            }

            User user = AutoMapperUtility.Map<UserRegisterViewModel, User>(userRegisterViewModel);
            int userId = UserService.SaveUser(user);
            // 注册成功,自动登录
            UserId=userId;
            UserNikename=user.Nikename;
            // 跳转到原页面/首页面
            if (!string.IsNullOrWhiteSpace(retUrl))
               return Redirect(retUrl);
               return RedirectToAction("Index", "Home");
        }
Esempio n. 2
0
 public ActionResult Reg()
 {
     UserRegisterViewModel user = new UserRegisterViewModel();
     return View(user);
 }