public async Task <IActionResult> Post([FromBody] RegistrationViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = mapper.Map <AppUser>(model); var result = await userManager.CreateAsync(userIdentity, model.Password); if (result.Succeeded) { var code = await userManager.GenerateEmailConfirmationTokenAsync(userIdentity); var callbackUrl = Url.Action( "ConfirmEmail", "Account", new { userId = userIdentity.Id, code = code }, protocol: HttpContext.Request.Scheme); await emailService.SendEmailAsync(model.Email, "Confirm your account", $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a>"); } else { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } await db.Customers.AddAsync(new Customer { IdentityId = userIdentity.Id, Location = model.Location }); await db.SaveChangesAsync(); return(new OkObjectResult("Account created. To validate your account, please check your mail")); }
public override async Task <IdentityResult> CreateAsync(ApplicationUser user) { await _imageify(user); _slugify(user); var result = await base.CreateAsync(user); if (result.Succeeded) { try { await _mailSender.SendEmailAsync( "*****@*****.**", "New user signup", new MailDropin { username = "******", title = "New User Signup", message = $"{user.Email}\n{user.FirstName} {user.LastName}" }); } catch (Exception) { } } else { Logger.LogError($"Error signing up user: {user.Email}"); foreach (var error in result.Errors) { Logger.LogError(error.Description); } } return(result); }
public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByNameAsync(model.Email); if (user is null) { _logger.LogWarning($"Password reset requested for {model.Email}"); return(Ok(model)); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = $"{_appSettings.SiteUrl}/auth/reset?token={WebUtility.UrlEncode(code)}&email={WebUtility.UrlEncode(user.Email)}"; await _emailSender.SendEmailAsync( model.Email, "PodNoms Reset Password Request", new MailDropin { username = user.GetBestGuessName(), title = "Password Rest Request", message = @"Someone told us you forgot your password?<br /> <span style='color: #a8bf6f; font-size: 14px; line-height: 21px;'>Don't worry, it happens.</span>", buttonaction = callbackUrl, buttonmessage = "Reset Password" }); return(Ok(model)); } return(BadRequest(model)); }
public async Task <bool> Execute(PerformContext context) { var unfound = new StringBuilder(); var items = _entryRepository.GetAll(); var storageAccount = CloudStorageAccount.Parse(_storageSettings.ConnectionString); var blobClient = storageAccount.CreateCloudBlobClient(); var container = blobClient.GetContainerReference(_audioStorageSettings.ContainerName); foreach (var item in items) { var key = $"{item.Id}.mp3"; _logger.LogDebug($"Checking for: {key}"); var exists = await container .GetBlockBlobReference(key) .ExistsAsync(); if (!exists) { //check for audio in backup container if (!string.IsNullOrEmpty(item.AudioUrl)) { var backedUp = item.AudioUrl.Replace("audio/", "backup/"); if (await container .GetBlockBlobReference(backedUp) .ExistsAsync()) { await container.RenameAsync(backedUp, key); continue; } //check for one in audio container where filename doesn't match <id>.mp3 var oldUrl = item.AudioUrl.Replace("audio/", ""); if (await container .GetBlobReference(oldUrl) .ExistsAsync()) { await container.RenameAsync(oldUrl, key); continue; } } unfound.Append($"Id: {item.Id} - AudioUrl: {item.AudioUrl} - SourceUrl: {item.SourceUrl}{Environment.NewLine}"); } } await _mailSender.SendEmailAsync( "*****@*****.**", "Missing audio found", new MailDropin { username = "******", title = "Missing audio found", message = unfound.ToString() }); return(true); }
private async Task HandleMailMessageAsync(SendMailMessage message) { try { await _mailSender.SendEmailAsync(message); } catch (Exception ex) { Logger.Error(ex, "Error while sending message"); } }
public async Task <IActionResult> SendEmail(string email) { await _mailSender.SendEmailAsync( email, "Debug Message", new MailDropin { username = "******", message = "Hello Sailor" }); return(Ok()); }
public async Task <object> SendPasswordResetMail([FromBody] ForgotPasswordModel model) { var user = await _userManager.FindByEmailAsync(model.Email); if (user.Email != model.Email) { return(new ObjectResult(new { resetToken = "", Succeeded = false, Error = "User does not exist" })); } var resetToken = await _userManager.GeneratePasswordResetTokenAsync(user); GenericAttributeViewModel genericAttributeViewModel = new GenericAttributeViewModel() { EntityId = user.Id, KeyGroup = "User", Key = "PasswordToken", Value = resetToken }; bool isSuccess = _DbService.AddGenericAttribute(genericAttributeViewModel); var urlEncodedToken = System.Net.WebUtility.UrlEncode(resetToken); StringBuilder body = new StringBuilder("<p>Merhaba,</p>"); body.Append("<p>"); body.Append("<br>MedByte hesabının şifresini aşağıdaki linki kullanarak yenileyebilirsin."); body.Append("</p>"); body.Append("<p>"); body.Append($"<p><a href=\"http://localhost:5000/Account/ResetPassword?t={urlEncodedToken}\">Şifre yenileme sayfasına yönlendirilmek için tıklayın.</a> </p>"); body.Append("</p>"); body.Append("<p>Sevgiler, MadByte işe giriş projesi.</p>"); body.Append("<p>"); body.Append("<br>"); body.Append("</p>"); await _mailSender.SendEmailAsync("MedByte | Şifre Yenileme", model.Email, body.ToString()); return(new ObjectResult(new { resetToken, Succeeded = true, })); }
public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel model) { User user = await userManager.FindByEmailAsync(model.Email); if (user != null && await userManager.IsEmailConfirmedAsync(user)) { var token = await userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPassword", "Account", new { userId = user.Id, token }, protocol: HttpContext.Request.Scheme); await mailSender.SendEmailAsync(model.Email, "Password reset", $"To reset your password please follow the <a href='{callbackUrl}'>link</a>"); return(View("ForgotPasswordConfirmation")); } else { ModelState.AddModelError(string.Empty, "Either user with such an email doesn't exist or email hasn't been confirmed"); return(View()); } }
public override async Task <string> SendNotification(Guid notificationId, string userName, string title, string message, string url) { var config = await _getConfiguration(notificationId); if (config is null || !(config.ContainsKey("To"))) { return("\"To\" not found in config"); } var response = await _emailSender.SendEmailAsync( config["To"], config["Subject"] ?? "New Podcast", new MailDropin { username = userName, title = title, message = $"Title: {title}\n\n{message}\n\n\n{url}" }); return("Email succesfully sent to {config[\"To\"]}"); }
private async Task <bool> _sendEmail(string userId, string title, string body, string target, string image, NotificationOptions notificationType) { try { _logger.LogDebug($"Locating services"); using (IServiceScope scope = _provider.CreateScope()) { _logger.LogDebug($"Finding user"); var userManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >(); var user = await userManager.FindByIdAsync(userId); if (user != null && (user.EmailNotificationOptions & notificationType) != 0) { _logger.LogDebug($"User is {user.Email}"); //user has allowed this kinds of emails. await _mailSender.SendEmailAsync( user.Email, $"New notification from PodNoms", new MailDropin { username = user.GetBestGuessName(), title = title, message = body, buttonaction = target, buttonmessage = "Check it out" } ); } else { _logger.LogError($"Unable to find user"); } } return(true); } catch (Exception ex) { _logger.LogError(119157, ex, $"Error sending Notification email"); } return(false); }
public async Task SendAsync(string content) { await _mailSender.SendEmailAsync(new MailMessage(_options.Subject, content, _options.Tos.ToList())); }
public async Task <IActionResult> HandleExternalLogin(string returnUrl = null, string remoteError = null) { if (remoteError != null) { return(BadRequest($"Error while login via external provider. Message = {remoteError}")); } var info = await loginService.GetExternalLoginInfoAsync(); var result = await loginService.CheckExternalProviderSignIn(info.LoginProvider, info.ProviderKey); await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); if (result) { var signedUser = await loginService.FindByEmailAsync(info.Principal.FindFirstValue(ClaimTypes.Email)); return(new OkObjectResult(await jwtService.GetJwtToken(signedUser))); } var userEmail = info.Principal.FindFirstValue(ClaimTypes.Email); if (string.IsNullOrEmpty(userEmail)) { return(BadRequest($"Email scope access is required to add {info.ProviderDisplayName} provider")); } var user = await loginService.FindByEmailAsync(userEmail); if (user != null) { if (!user.EmailConfirmed) { var token = await loginService.GenerateEmailConfirmationTokenAsync(user); var callbackUrl = Url.Action("ConfirmExternalProvider", "Account", values: new { userId = user.Id, code = token, loginProvider = info.LoginProvider, providerDisplayName = info.LoginProvider, providerKey = info.ProviderKey }, protocol: HttpContext.Request.Scheme); await emailService.SendEmailAsync(user.Email, $"Confirm {info.ProviderDisplayName} external login", $"Please confirm association of your {info.ProviderDisplayName} " + $"account by clicking <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>here</a>"); return(new OkObjectResult($"External account association with {info.ProviderDisplayName} is pending. Please check your email")); } await loginService.AddLoginAsync(user, info); return(new OkObjectResult(await jwtService.GetJwtToken(user))); } return(new OkObjectResult(new { Message = "Use this to associate your account with external provider", associate = userEmail, loginProvider = info.LoginProvider, providerDisplayName = info.ProviderDisplayName, providerKey = info.ProviderKey })); }