Ejemplo n.º 1
0
        public async Task <AuthResult> Register(UserDTO userDTO)
        {
            //var existingUser = _userManager.Users.Where(x => x.UserLogin == userDTO.Login);
            var existingUser = await _userStorage.FindByName(userDTO.Login);

            if (existingUser != null)
            {
                return(new AuthResult
                {
                    Success = false,
                    ErrorMessage = "User with this login already exists"
                });
            }

            var newUser = _mapper.Map <UserEntity>(userDTO);

            var createdUser = await _userStorage.Create(newUser, userDTO.Password);

            if (!createdUser.Succeeded)
            {
                return(new AuthResult
                {
                    Success = false,
                    ErrorMessage = "Smth went wrong"
                });
            }

            return(new AuthResult
            {
                Success = true,
            });
        }
Ejemplo n.º 2
0
 public bool Register(User user)
 {
     if (Validate())
     {
         //Create the salt value with a cryptographic PRNG:
         new RNGCryptoServiceProvider().GetBytes(user.Salt = new byte[16]);
         user.HashedPassword = PasswordUtils.HashPassword(user.Salt, user.Password);
         _storage.Create(user);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Invoke the command
        /// </summary>
        /// <param name="command">Command</param>
        public void Invoke(CreateUser command)
        {
            var user = _storage.Create(command.UserName);

            user.FullName    = command.FullName;
            user.DisplayName = command.DisplayName;
            _storage.Save(user);

            // Note that the command and not the repository
            // generates the event now.
            //
            // imho it's poor practice to let non business related classes
            // to generate events. But I did it for simplicity in the last example project.
            DomainEvent.Publish(new UserCreated(user.Id));

            Console.WriteLine("All done.");
        }