private async Task SendConfirmEmailAsync(ApplicationUser user) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id); var message = new MailMessage("*****@*****.**", user.Email) { Body = $"Please confirm your account by clicking this link: <a href='{GlobalInfo.ConfirmEmailUrl}?userId={ToBase64(user.Id)}&code={ToBase64(code)}'>link</a>", Subject = "Confirm your account", IsBodyHtml = true }; await _emailSendingService.SendAsync(message); }
private async Task SendConfirmEmail(ApplicationUser user) { var code = await _userManager.GenerateEmailConfirmationTokenAsync(user.Id); var message = new MailMessage("*****@*****.**", user.Email) { Body = $"You have sucessfully registered in the best banking system. To confirm your account, please, follow this link: <a href='{GlobalInfo.ConfirmEmailUrl}?userId={ToBase64(user.Id)}&code={ToBase64(code)}'>link</a>", Subject = "Confirm your account", IsBodyHtml = true }; await _emailSendingService.SendAsync(message); }
public async Task <IActionResult> SendUserTwoFactorToken([FromBody] LoginUserDto logInDto) { var user = await _userManager .Users .FirstOrDefaultAsync(u => u.PhoneNumber == logInDto.PhoneNumber); if (user == null) { return(BadRequest("Incorrect login or password")); } if (!(await _signInManager.CheckPasswordSignInAsync(user, logInDto.Password, true)).Succeeded) { return(BadRequest("Incorrect password")); } var twoFactorToken = await _userManager.GenerateTwoFactorTokenAsync(user, ProviderConstansts.UserTwoFactorTokenProvider); if (twoFactorToken == null) { return(BadRequest("Can't generate new token")); } await _emailSendingService.SendAsync(user.Email, "Code", twoFactorToken); return(Ok(new TwoFactorDto { UserId = user.Id, Roles = (await _userManager.GetRolesAsync(user)).ToList(), ExpiredAfter = int.Parse(_configuration["TwoFactorLifeTime"]) })); }
/// <summary> /// Sends an invite to the recipient's email address. /// </summary> /// <param name="inviteId">An invite token.</param> /// <param name="inviteLink">An invite link.</param> /// <returns>A task of asynchronous invite sending.</returns> /// <exception cref="ArgumentOutOfRangeException">Invite id less than zero.</exception> /// <exception cref="ArgumentNullException">Action link is null.</exception> /// <exception cref="InviteNotFoundException">Invite not found.</exception> /// <exception cref="InvalidOperationException">The invite expired date and time less than current date and time.</exception> public Task SendInviteAsync(int inviteId, string inviteLink) { if (string.IsNullOrWhiteSpace(inviteLink)) { throw new ArgumentNullException(nameof(inviteLink)); } var invite = _context.Invites.SingleOrDefault(i => i.Id == inviteId); if (invite == null) { throw new InviteNotFoundException($"Invite with id {inviteId} is not found."); } if (invite.ExpiredDate < DateTime.Now) { throw new InvalidOperationException($"Invite with id {inviteId} is expired."); } var message = new MailMessage("*****@*****.**", invite.Email) { Body = $"You are invited as a {invite.RoleName}: <a href='{inviteLink}?token={invite.Token}'>accept invite</a>", Subject = "Invite", IsBodyHtml = true }; return(_emailSendingService.SendAsync(message)); }
public async Task SendTicketEmail(Models.DateAndTime dateAndTime) { string time = dateAndTime.time; string date = dateAndTime.date.ToShortDateString(); var currentUser = _userContextService.GetCurrentUser(); var user = await _userManager.FindByIdAsync(currentUser.IdentityId); Guid userGuid = currentUser.Id; var userProfile = await _userManager.GetProfileAsync(userGuid); string firstName = userProfile.FirstName; string lastName = userProfile.LastName; List <string> userName = new List <string>(); userName.Add(firstName); userName.Add(lastName); var message = new MailMessage("*****@*****.**", user.Email) { Body = $"Hi, {userName[0]} {userName[1]}! You have sucessfully ordered a ticket to <b>{date}</b> at <b>{time}</b>. Thank you for using the best bankig system. Hope to see you again!", // Body = $"<table class =\"ticket\" border=\"0\" cellpadding=\"4\" cellspacing=\"4\" style=\"width:300pt; margin: auto; \"><tr><td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >< b > Date:</ b ></ td >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >{date}</ td ></ tr >< tr >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >< b > Time:</ b ></ td >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >{time}</ td ></ tr >< tr >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >< b > Name:</ b ></ td >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >{userName[0]}</ td ></ tr >< tr >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >< b > Surname:</ b ></ td >< td height = \"3\" style = \"border: 1pt solid #000000;\" align = \"left\" >{userName[1]}</ td ></ tr ></ table > ", Subject = "Ticket to bank", IsBodyHtml = true }; await _emailSendingService.SendAsync(message); }