Example #1
0
        public async Task ChangeEmailAsync(ChangeEmailModel parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            var user = await GetUserByEmailAsync(parameters.CurrentEmail);

            if (user == null)
            {
                throw new HESException(HESCode.UserNotFound);
            }

            var exist = await GetUserByEmailAsync(parameters.NewEmail);

            if (exist != null)
            {
                throw new HESException(HESCode.EmailAlreadyTaken);
            }

            var code = await _userManager.GenerateChangeEmailTokenAsync(user, parameters.NewEmail);

            code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

            await _emailSenderService.SendUserConfirmEmailAsync(user.Id, parameters.NewEmail, code);
        }