private async Task SendRecoverEmail(string email, string userName)
 {
     var expires     = DateTime.Now.AddHours(2);
     var issuer      = _configuration["Issuer"];
     var securityKey = _awsSecretManagerService.GetSecret(_configuration["SecretName_RecoverEmail"]);
     var claims      = new[]
     {
         new System.Security.Claims.Claim(JwtRegisteredClaimNames.Sub, email),
         new System.Security.Claims.Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString("N")),
         new System.Security.Claims.Claim(JwtRegisteredClaimNames.UniqueName, email)
     };
     var serializedToken = _securityTokenHandler.WriteToken(email, claims, issuer, securityKey, expires);
     var url             = _configuration["PLAYERS2_URL"] + "newpassword?u17=";
     var template        = ForgotPasswordTemplate.GetForgotPasswordBody(url + serializedToken);
     var emailTopic      = _configuration["EMAIL_TOPIC"];
     var message         = new Message()
     {
         From    = "*****@*****.**",
         Body    = template,
         To      = email,
         Subject = $"{userName}, change your password of PLAYER2 here!"
     };
     await _snsClient.Send(emailTopic, JsonConvert.SerializeObject(new
     {
         Message = message
     })).ConfigureAwait(false);
 }
Пример #2
0
        public async Task SendForgotPassword(SendForgotPasswordRequest request)
        {
            var resetToken = string.Empty;

            UserEntity user;

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                user = await uow.UserRepo.GetUserByEmail(new Repositories.DatabaseRepos.UserRepo.Models.GetUserByEmailRequest()
                {
                    Email_Address = request.EmailAddress
                });

                if (user == null)
                {
                    return;
                }

                resetToken = GenerateUniqueUserToken(uow);

                await uow.UserRepo.CreateUserToken(new Repositories.DatabaseRepos.UserRepo.Models.CreateUserTokenRequest()
                {
                    User_Id    = user.Id,
                    Token      = new Guid(resetToken),
                    Type_Id    = (int)TokenTypeEnum.ForgotPassword,
                    Created_By = ApplicationConstants.SystemUserId,
                });

                uow.Commit();
            }

            var configuration = await _cache.Configuration();

            var baseUrl = _httpContextAccessor.HttpContext.Request.GetBaseUrl();

            var templateHtml = await _emailTemplateRepo.GetForgotPasswordHTML();

            var template = new ForgotPasswordTemplate(templateHtml)
            {
                ResetPasswordUrl = $"{baseUrl}/Account/ResetPassword?token={resetToken}",
                ApplicationUrl   = baseUrl
            };

            await _emailProvider.Send(new Infrastructure.Email.Models.SendRequest()
            {
                FromAddress = configuration.System_From_Email_Address,
                ToAddress   = request.EmailAddress,
                Subject     = template.Subject,
                Body        = template.GetHTMLContent()
            });
        }
Пример #3
0
        public async Task SendResetPassword(SendResetPasswordRequest request)
        {
            var resetToken = string.Empty;

            UserEntity user;

            using (var uow = _uowFactory.GetUnitOfWork())
            {
                user = await uow.UserRepo.GetUserById(new Infrastructure.Repositories.UserRepo.Models.GetUserByIdRequest()
                {
                    Id = request.UserId
                });

                resetToken = GenerateUniqueUserToken(uow);

                await uow.UserRepo.CreateUserToken(new Infrastructure.Repositories.UserRepo.Models.CreateUserTokenRequest()
                {
                    User_Id    = request.UserId,
                    Token      = new Guid(resetToken),
                    Type_Id    = (int)TokenTypeEnum.ResetPassword,
                    Created_By = ApplicationConstants.SystemUserId,
                });

                uow.Commit();
            }

            var configuration = await _cache.Configuration();

            var baseUrl = _httpContextAccessor.HttpContext.Request.GetBaseUrl();

            var templates = await _cache.EmailTemplates();

            var templateEntity = templates.FirstOrDefault(t => t.Key == EmailTemplateKeys.ForgotPassword);

            var template = new ForgotPasswordTemplate(templateEntity.Body)
            {
                ResetPasswordUrl = $"{baseUrl}/reset-password?token={resetToken}",
                ApplicationUrl   = baseUrl
            };

            await _emailProvider.Send(new Infrastructure.Email.Models.SendRequest()
            {
                FromAddress = configuration.System_From_Email_Address,
                ToAddress   = user.Email_Address,
                Subject     = template.Subject,
                Body        = template.GetHTMLContent()
            });
        }
Пример #4
0
        public async Task <IHttpActionResult> ForgotPassword(ForgotPasswordBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var participant = await UserManager.FindByEmailAsync(model.Email);

            if (participant != null)
            {
                if (participant.SecurityStamp == null)
                {
                    var ir = await UserManager.UpdateSecurityStampAsync(participant.Id);

                    if (!ir.Succeeded)
                    {
                        throw new FieldAccessException("Could not UpdateSecurityStampAsync - following errors:" + string.Join("\r\n", ir.Errors));
                    }
                }
                var resetEmail = new ForgotPasswordTemplate
                {
                    Token    = await UserManager.GeneratePasswordResetTokenAsync(participant.Id),
                    UserId   = participant.Id,
                    UserName = participant.UserName
                };

                using (var mail = new MailMessage())
                {
                    mail.To.Add(model.Email);
                    mail.CreateHtmlBody(resetEmail);
                    using (var client = new SmtpClient())
                    {
                        client.Send(mail);
                    }
                }
            }
            //return GetErrorResult(result);

            return(Ok());
        }
Пример #5
0
        public void SendForgotPassword(UserDto userDto)
        {
            using (HttpClient client = new HttpClient())
            {
                try
                {
                    client.BaseAddress = new Uri("http://www.acgelektronik.com/evarlikMailSend.php?token=ae7635abfe63772042f1965d50f07d09");

                    var temmplate = ForgotPasswordTemplate.Replace("__name__", userDto.Name);
                    temmplate = temmplate.Replace("__surname__", userDto.Surname);
                    temmplate = temmplate.Replace("__password__", userDto.Password);

                    var mailDto = new MailDto()
                    {
                        Body    = temmplate,
                        Name    = userDto.Name,
                        Subject = "E-Varlik Şifre Yenileme Talebi",
                        To      = userDto.Mail
                    };

                    var clientDtoJson = JsonConvert.SerializeObject(mailDto);
                    var content       = new StringContent(clientDtoJson, Encoding.UTF8, "application/json");

                    var responseMessageR = client
                                           .PostAsync("evarlikMailSend.php?token=ae7635abfe63772042f1965d50f07d09", content)
                                           .ContinueWith((postTask) => postTask.Result.EnsureSuccessStatusCode());
                    responseMessageR.Wait();
                    HttpResponseMessage responseMessage = responseMessageR.Result;
                    var resR = responseMessage.Content.ReadAsStringAsync();
                    resR.Wait();
                    var res = resR.Result;
                }
                catch (Exception e)
                {
                }
            }
        }