Ejemplo n.º 1
0
 public void RegisterUser(User user)
 {
     Process(() =>
     {
         user.Password = Encryption.HashPassword(user.Password);
         var newUser = userRepository.Insert(user);
         unitOfWork.Commit();
     });
 }
Ejemplo n.º 2
0
        public ActionResult SignUp(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var existedUser = authenticationService.GetUserByUsername(model.Email);
                if (existedUser != null)
                {
                    return Json(new { errors = new List<string> { "This email address already exists." } });
                }

                var user = new User
                {
                    Username = model.Email,
                    Email = model.Email,
                    Password = model.Password,
                    IsActive = true
                };

                authenticationService.RegisterUser(user);
                return SignIn(new SignInViewModel { Email = user.Username, Password = model.Password }, string.Empty);
            }

            var errors = ModelState.GetErrors();

            return Json(new { errors = errors });
        }