예제 #1
0
        private void ValidateInput(UserViewModel viewModel)
        {
            if (viewModel.ConfirmPassword == null)
                viewModel.ConfirmPassword = "";
            if (viewModel.Password == null)
                viewModel.Password = "";
            if (!viewModel.Password.Equals(viewModel.ConfirmPassword))
            {
                ModelState.AddModelError("ConfirmPassword", "Пароли должны совпадать");
            }

            var user = daoTemplate.FindUniqueByField<User>(Models.User.EmailProperty, viewModel.Email);
            if (user != null)
            {
                ModelState.AddModelError("Email", "Пользователь с таким email уже существует");
            }
        }
예제 #2
0
        public ActionResult Register(UserViewModel viewModel)
        {
            ValidateInput(viewModel);

            if (ModelState.IsValid)
            {
                User user = new User();
                user.Contact = Contact.From(viewModel.Contact);
                user.Email = viewModel.Email;
                user.IsSignedForNews = viewModel.IsSignForNews;
                user.PasswordHash = UserService.CalculateHash(viewModel.Password);

                daoTemplate.Save(user);
                FormsAuthentication.SetAuthCookie(user.Email, true);
                return Redirect("/");
            }
            return View(viewModel);
        }