public async Task ResendInvitationAsync(Employee employee, ServerSettings server, string invitationId) { if (employee == null) { throw new ArgumentNullException(nameof(employee)); } if (server == null) { throw new ArgumentNullException(nameof(server)); } if (invitationId == null) { throw new ArgumentNullException(nameof(invitationId)); } var invitation = await _softwareVaultInvitationRepository.GetByIdAsync(invitationId); if (invitation == null) { throw new NotFoundException("Invitation not found."); } var activationCode = GenerateActivationCode(); invitation.Status = SoftwareVaultInvitationStatus.Pending; invitation.ValidTo = DateTime.Now.AddDays(2); invitation.ActivationCode = activationCode; var prop = new string[] { nameof(SoftwareVaultInvitation.Status), nameof(SoftwareVaultInvitation.ValidTo), nameof(SoftwareVaultInvitation.ActivationCode) }; await _softwareVaultInvitationRepository.UpdateOnlyPropAsync(invitation, prop); var activation = new SoftwareVaultActivation() { ServerAddress = server.Url, ActivationId = invitation.Id, ActivationCode = activationCode }; await _emailSenderService.SendSoftwareVaultInvitationAsync(employee, activation, invitation.ValidTo); }
public async Task SendSoftwareVaultInvitationAsync(Employee employee, SoftwareVaultActivation activation, DateTime validTo) { if (employee.Email == null) { throw new ArgumentNullException(nameof(employee.Email)); } var emailSettings = await GetEmailSettingsAsync(); var htmlMessage = GetTemplate("mail-software-vault-invitation"); htmlMessage = htmlMessage.Replace("{{employeeName}}", employee.FirstName) .Replace("{{validTo}}", validTo.Date.ToShortDateString()) .Replace("{{serverAddress}}", activation.ServerAddress) .Replace("{{activationId}}", activation.ActivationId) .Replace("{{activationCode}}", activation.ActivationCode.ToString()); AlternateView htmlView = AlternateView.CreateAlternateViewFromString( htmlMessage, Encoding.UTF8, MediaTypeNames.Text.Html); var code = $"{activation.ServerAddress}\n{activation.ActivationId}\n{activation.ActivationCode}"; var qrCode = GetQRCode(code); string mediaType = MediaTypeNames.Image.Jpeg; LinkedResource img = new LinkedResource(qrCode, mediaType); img.ContentId = "QRCode"; img.ContentType.MediaType = mediaType; img.TransferEncoding = TransferEncoding.Base64; img.ContentType.Name = img.ContentId; img.ContentLink = new Uri("cid:" + img.ContentId); htmlView.LinkedResources.Add(img); MailMessage mailMessage = new MailMessage(emailSettings.UserName, employee.Email); mailMessage.AlternateViews.Add(htmlView); mailMessage.IsBodyHtml = true; mailMessage.Subject = "Hideez Software Vault application"; await SendAsync(mailMessage, emailSettings); }
public async Task CreateAndSendInvitationAsync(Employee employee, ServerSettings server, DateTime validTo) { if (employee == null) { throw new ArgumentNullException(nameof(employee)); } if (employee.Id == null) { throw new ArgumentNullException(nameof(employee.Id)); } if (employee.Email == null) { throw new ArgumentNullException(nameof(employee.Email)); } var activationCode = GenerateActivationCode(); var invitation = new SoftwareVaultInvitation() { EmployeeId = employee.Id, Status = SoftwareVaultInvitationStatus.Pending, CreatedAt = DateTime.UtcNow, ValidTo = validTo.Date, AcceptedAt = null, SoftwareVaultId = null, ActivationCode = activationCode }; var created = await _softwareVaultInvitationRepository.AddAsync(invitation); var activation = new SoftwareVaultActivation() { ServerAddress = server.Url, ActivationId = created.Id, ActivationCode = activationCode }; await _emailSenderService.SendSoftwareVaultInvitationAsync(employee, activation, validTo); }