コード例 #1
0
ファイル: UserService.cs プロジェクト: bmeijwaard/TheBlogApi
        public async Task <ServiceResponse> CreateAsync(UserDTO userDTO, string password)
        {
            var checkIfExists = await CheckUserExistsAsync(userDTO).ConfigureAwait(false);

            if (!checkIfExists.Succeeded)
            {
                return(checkIfExists);
            }

            var user = Mapper.Map <User>(userDTO);

            // the decrypted email will be used later
            var email = user.Email;

            user.Email = _cryptoProvider.EncryptPrivate(email);

            var result = await _userManager.CreateAsync(user, password).ConfigureAwait(false);

            if (!result.Succeeded)
            {
                return(new ServiceResponse(string.Join(", ", result.Errors.Select(e => e.Description))));
            }

            var token = await _userManager.GenerateEmailConfirmationTokenAsync(user).ConfigureAwait(false);

            await _emailService
            .ConfirmationEmailNotificationAsync(email, token)
            .ConfigureAwait(false);

            return(new ServiceResponse());
        }