コード例 #1
0
        public async Task <User> RegisterUserAsync(User user, string password)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }
            var existingUser = await _userRepository.FindUser(user.Email);

            if (existingUser != null)
            {
                throw new AppException("User already exists!");
            }

            byte[] passwordHash, passwordSalt;
            _securityService.CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            await _userRepository.CreateUser(user);

            return(user);
        }