예제 #1
0
        public Response<User> RegisterUser(string username, string password, string confirmPassword, UserDetails userDetails)
        {
            var response = new Response<User>();

            if(_userRepository.GetByUsername(username)!= null)
            {
                response.Error = ErrorCode.DuplicateEntity;
            }
            if(password!=confirmPassword || password.Length<6)
            {
                response.Error = ErrorCode.InvalidState;
            }
            if(response.Success)
            {
                byte[] salt;
                byte[] hash;

                _passwordHandler.SaltAndHash(password, out salt, out hash);

                var user = _userRepository.CreateUser(username, salt, hash, userDetails);
                response.Entity = user;
            }

            return response;
        }
예제 #2
0
        public ActionResult CreateUser(RegisterViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return View("~/Views/Home/LogIn/CreateUser.cshtml");
            }

            var userDetails = new UserDetails()
            {
                FirstName = viewModel.UserDetails.FirstName,
                LastName = viewModel.UserDetails.LastName,
                Company = viewModel.UserDetails.Company,
                Address = viewModel.UserDetails.Address,
                Phone = viewModel.UserDetails.Phone
            };

            var response = _userService.RegisterUser(viewModel.Username,
                viewModel.Password, viewModel.ConfirmPassword, userDetails);

            if (response.Success)
            {
                return RedirectToAction("Index");
            }

            ModelState.AddModelError("username", response.Error.ToString());

            return View("~/Views/Home/LogIn/CreateUser.cshtml");
        }
예제 #3
0
        public User CreateUser(string username, byte[] passwordSalt, byte[] passwordHash, UserDetails userDetails)
        {
            var user = new User()
            {
                Hash = passwordHash,
                Salt = passwordSalt,
                UserName = username,
                IsAdmin = false,
                UserDetails = userDetails
            };

            _context.Users.Add(user);
            _context.SaveChanges();

            return user;
        }
예제 #4
0
 public User()
 {
     UserDetails = new UserDetails();
 }
예제 #5
0
 public User()
 {
     UserDetails = new UserDetails();
 }