Exemplo n.º 1
0
        public async Task <OperationResult> ResendEmailVerification([FromBody] ResendEmailVerification dto)
        {
            if (dto == null || string.IsNullOrEmpty(dto.Email))
            {
                return(BadRequest());
            }

            var token = await passport.GenerateEmailVerificationTokenAsync(dto.Email);

            if (!string.IsNullOrEmpty(token))
            {
                var result = await email.SendWelcomeEmailAsync(token, dto.Email);

                if (!result.Successful)
                {
                    logger.LogError($"Failed to send verification email.");
                }
            }
            else
            {
                logger.LogError($"Failed to generate an email verification token for {dto.Email}");
            }

            return(Ok());
        }
Exemplo n.º 2
0
        public async Task <ServiceResult> ResendEmailVerification(string email)
        {
            var result = new ServiceResult();
            var token  = await GetBackchannelToken();

            using (var client = Backchannel)
            {
                var request = new HttpRequestMessage(HttpMethod.Get, Configuration.ResendEmailVerificationEndpoint);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);

                var dto     = new ResendEmailVerification(email);
                var payload = JsonConvert.SerializeObject(dto);
                request.Content = new StringContent(payload, Encoding.UTF8, "application/json");

                var response = await client.SendAsync(request);

                try
                {
                    response.EnsureSuccessStatusCode();
                }
                catch (Exception e)
                {
                    logger.LogError(e, "Failed to resend the email verification token");
                    result.Error = Shared.ErrorKey.UserProfile.ResendVerificationFailed;
                    return(result);
                }
            }

            result.Succeed();
            return(result);
        }