Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added service that use Razor. Added the email templates path structure #624

Merged
merged 6 commits into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
using OutOfSchool.EmailSender;
using OutOfSchool.IdentityServer.Services.Intefaces;
using OutOfSchool.IdentityServer.Services.Password;
using OutOfSchool.RazorTemplatesData.Models.Emails;
using OutOfSchool.RazorTemplatesData.Services;
using OutOfSchool.Services;
using OutOfSchool.Services.Enums;
using OutOfSchool.Services.Models;
Expand All @@ -29,21 +31,24 @@ public class ProviderAdminService : IProviderAdminService

private readonly UserManager<User> userManager;
private readonly OutOfSchoolDbContext context;
private readonly IRazorViewToStringRenderer renderer;

public ProviderAdminService(
IMapper mapper,
IProviderAdminRepository providerAdminRepository,
ILogger<ProviderAdminService> logger,
IEmailSender emailSender,
UserManager<User> userManager,
OutOfSchoolDbContext context)
OutOfSchoolDbContext context,
IRazorViewToStringRenderer renderer)
{
this.mapper = mapper;
this.userManager = userManager;
this.context = context;
this.providerAdminRepository = providerAdminRepository;
this.logger = logger;
this.emailSender = emailSender;
this.renderer = renderer;
}

public async Task<ResponseDto> CreateProviderAdminAsync(
Expand Down Expand Up @@ -148,11 +153,13 @@ await providerAdminRepository.Create(providerAdmin)
new {userId = user.Id, token},
"https");
var subject = "Запрошення!";
var htmlMessage = $"Для реєстрації на платформі перейдіть " +
$"за посиланням та заповність ваші данні в особистому кабінеті.<br>" +
$"{confirmationLink}<br><br>" +
$"Логін: {user.Email}<br>" +
$"Пароль: {password}";
var adminInvitationViewModel = new AdminInvitationViewModel
{
ConfirmationUrl = confirmationLink,
Email = user.Email,
Password = password,
};
var htmlMessage = await renderer.GetHtmlStringAsync(EmailTemplates.NewAdminInvitation, adminInvitationViewModel);

await emailSender.SendAsync(user.Email, subject, htmlMessage);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace OutOfSchool.RazorTemplatesData.Models.Emails
{
public class AdminInvitationViewModel
{
public string Email { get; set; }
public string Password { get; set; }
public string ConfirmationUrl { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
public static class EmailTemplates
{
/// <summary>
/// Bass path to the html email templates
/// Base path to the html email templates
/// </summary>
private static string MainPath => "/Views/Emails/";

/// <summary>
/// Bass path to the plain text email templates
/// Base path to the plain text email templates
/// </summary>
private static string MainPathPlainText => "/ViewsPlainText/Emails/";

/// <summary>
/// Supported email templates
/// </summary>
// Supported email templates
public static string ConfirmEmail => "ConfirmEmail";
public static string ChangeEmail => "ChangeEmail";
public static string ResetPassword => "ResetPassword";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@

<p>
If you have any questions, just reply to this email—we're always happy to help out.
</p>

<br />

<p>
The Contoso Team
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@
<p>
If you have any questions, just reply to this email—we're always happy to help out.
</p>

<br />

<p>
The Contoso Team
</p>
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using OutOfSchool.RazorTemplatesData.Models.Emails
@using OutOfSchool.RazorTemplatesData.Models.Shared
@model AdminInvitationViewModel

@{
ViewData["EmailTitle"] = "Welcome!";
}

<p>Для реєстрації на платформі перейдіть за посиланням та заповність ваші данні в особистому кабінеті.</p>

<br />

<p>Логін: @Model.Email</p>

<br />

<p>Пароль: @Model.Password</p>

<br />

@await Html.PartialAsync("EmailButton", new EmailButtonViewModel("Confirm Email", Model.ConfirmationUrl))

<br />

<p>If you have any questions, just reply to this email—we're always happy to help out.</p>
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,4 @@

<p>
If you have any questions, just reply to this email—we're always happy to help out.
</p>

<br />

<p>
The Contoso Team
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<style type="text/css">
/* FONTS */
/* CLIENT-SPECIFIC STYLES */
/* RESET STYLES */
/* iOS BLUE LINKS */
/* MOBILE STYLES */
/* ANDROID CENTER FIX */
</style>
</head>
<body style="background-color: #f4f4f4; margin: 0 !important; padding: 0 !important;">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
@Model.ActionUrl


If you have any questions, just reply to this email—we're always happy to help out.


The Contoso Team
If you have any questions, just reply to this email—we're always happy to help out.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
@Model.ActionUrl


If you have any questions, just reply to this email—we're always happy to help out.


The Contoso Team
If you have any questions, just reply to this email—we're always happy to help out.
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@using OutOfSchool.RazorTemplatesData.Models.Emails
@model AdminInvitationViewModel

@{
ViewData["EmailTitle"] = "Welcome!";
}

Для реєстрації на платформі перейдіть за посиланням та заповність ваші данні в особистому кабінеті.

@Model.ConfirmationUrl

Логін: @Model.Email

Пароль: @Model.Password

If you have any questions, just reply to this email—we're always happy to help out.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@


If you have any questions, just reply to this email—we're always happy to help out.


The Contoso Team