Ejemplo n.º 1
0
        public ActionResult Create(RegisterModel model)
        {
            if (_userRepository.Insert(model, _validation))
            {
                _unitOfWork.Save();
                return RedirectToAction("Index");
            }

            return View(model);
        }
Ejemplo n.º 2
0
        public bool Insert(RegisterModel model, IValidationDictionary validation)
        {
            ValidateNewUser(model, validation);

            if (validation.IsValid)
            {
                var salt = GenerateSalt(20);

                var user = new User
                {
                    UserName = model.UserName,
                    PasswordSalt = salt,
                    Password = HashPassword(model.Password, salt),
                    Email = model.Email,
                    DisplayName = model.DisplayName
                };

                _context.Users.Add(user);
                return true;
            }

            return false;
        }
Ejemplo n.º 3
0
        private void ValidateNewUser(RegisterModel model, IValidationDictionary validation)
        {
            var existingUser = _context.Users.SingleOrDefault(x => x.UserName == model.UserName);

            if (existingUser != null)
                validation.AddError("UserName", "This user name is already in use.");
        }