Skip to content

Commit 1d9cd1d

Browse files
committed
Upgrade to v8.1
1 parent 47f3627 commit 1d9cd1d

21 files changed

+3217
-1979
lines changed

MyApp.ServiceInterface/EmailServices.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public class SmtpConfig
4848
/// <summary>
4949
/// Uses a configured SMTP client to send emails
5050
/// </summary>
51-
public class EmailServices(SmtpConfig config, ILogger<EmailServices> log) : Service
51+
public class EmailServices(SmtpConfig config, ILogger<EmailServices> log)
52+
// TODO: Uncomment to enable sending emails with SMTP
53+
// : Service
5254
{
5355
public object Any(SendEmail request)
5456
{

MyApp.ServiceModel/Hello.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
namespace MyApp.ServiceModel;
44

5-
[Route("/hello")]
65
[Route("/hello/{Name}")]
7-
public class Hello : IReturn<HelloResponse>
6+
public class Hello : IGet, IReturn<HelloResponse>
87
{
9-
public string? Name { get; set; }
8+
public required string Name { get; set; }
109
}
1110

1211
public class HelloResponse
1312
{
14-
public string Result { get; set; } = default!;
13+
public required string Result { get; set; }
1514
}

MyApp/Areas/Identity/Pages/Account/ExternalLogin.cshtml.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public class ExternalLoginModel : PageModel
2828
private readonly UserManager<ApplicationUser> _userManager;
2929
private readonly IUserStore<ApplicationUser> _userStore;
3030
private readonly IUserEmailStore<ApplicationUser> _emailStore;
31-
private readonly IEmailSender _emailSender;
31+
private readonly IEmailSender<ApplicationUser> _emailSender;
3232
private readonly ILogger<ExternalLoginModel> _logger;
3333

3434
public ExternalLoginModel(
3535
SignInManager<ApplicationUser> signInManager,
3636
UserManager<ApplicationUser> userManager,
3737
IUserStore<ApplicationUser> userStore,
3838
ILogger<ExternalLoginModel> logger,
39-
IEmailSender emailSender)
39+
IEmailSender<ApplicationUser> emailSender)
4040
{
4141
_signInManager = signInManager;
4242
_userManager = userManager;
@@ -172,10 +172,9 @@ public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null
172172
"/Account/ConfirmEmail",
173173
pageHandler: null,
174174
values: new { area = "Identity", userId = userId, code = code },
175-
protocol: Request.Scheme);
175+
protocol: Request.Scheme)!;
176176

177-
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
178-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
177+
await _emailSender.SendConfirmationLinkAsync(user, Input.Email, callbackUrl);
179178

180179
// If account confirmation is required, we need to show the link if we don't have a real email sender
181180
if (_userManager.Options.SignIn.RequireConfirmedAccount)

MyApp/Areas/Identity/Pages/Account/ForgotPassword.cshtml.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ namespace MyApp.Areas.Identity.Pages.Account
2020
public class ForgotPasswordModel : PageModel
2121
{
2222
private readonly UserManager<ApplicationUser> _userManager;
23-
private readonly IEmailSender _emailSender;
23+
private readonly IEmailSender<ApplicationUser> _emailSender;
2424

25-
public ForgotPasswordModel(UserManager<ApplicationUser> userManager, IEmailSender emailSender)
25+
public ForgotPasswordModel(UserManager<ApplicationUser> userManager, IEmailSender<ApplicationUser> emailSender)
2626
{
2727
_userManager = userManager;
2828
_emailSender = emailSender;
@@ -69,12 +69,11 @@ public async Task<IActionResult> OnPostAsync()
6969
"/Account/ResetPassword",
7070
pageHandler: null,
7171
values: new { area = "Identity", code },
72-
protocol: Request.Scheme);
72+
protocol: Request.Scheme)!;
7373

74-
await _emailSender.SendEmailAsync(
74+
await _emailSender.SendPasswordResetLinkAsync(user,
7575
Input.Email,
76-
"Reset Password",
77-
$"Please reset your password by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
76+
callbackUrl);
7877

7978
return RedirectToPage("./ForgotPasswordConfirmation");
8079
}

MyApp/Areas/Identity/Pages/Account/Manage/Email.cshtml.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ public class EmailModel : PageModel
2020
{
2121
private readonly UserManager<ApplicationUser> _userManager;
2222
private readonly SignInManager<ApplicationUser> _signInManager;
23-
private readonly IEmailSender _emailSender;
23+
private readonly IEmailSender<ApplicationUser> _emailSender;
2424

2525
public EmailModel(
2626
UserManager<ApplicationUser> userManager,
2727
SignInManager<ApplicationUser> signInManager,
28-
IEmailSender emailSender)
28+
IEmailSender<ApplicationUser> emailSender)
2929
{
3030
_userManager = userManager;
3131
_signInManager = signInManager;
@@ -123,11 +123,10 @@ public async Task<IActionResult> OnPostChangeEmailAsync()
123123
"/Account/ConfirmEmailChange",
124124
pageHandler: null,
125125
values: new { area = "Identity", userId = userId, email = Input.NewEmail, code = code },
126-
protocol: Request.Scheme);
127-
await _emailSender.SendEmailAsync(
126+
protocol: Request.Scheme)!;
127+
await _emailSender.SendConfirmationLinkAsync(user,
128128
Input.NewEmail,
129-
"Confirm your email",
130-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
129+
callbackUrl);
131130

132131
StatusMessage = "Confirmation link to change email sent. Please check your email.";
133132
return RedirectToPage();
@@ -159,11 +158,10 @@ public async Task<IActionResult> OnPostSendVerificationEmailAsync()
159158
"/Account/ConfirmEmail",
160159
pageHandler: null,
161160
values: new { area = "Identity", userId = userId, code = code },
162-
protocol: Request.Scheme);
163-
await _emailSender.SendEmailAsync(
164-
email,
165-
"Confirm your email",
166-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
161+
protocol: Request.Scheme)!;
162+
await _emailSender.SendConfirmationLinkAsync(user,
163+
email!,
164+
callbackUrl);
167165

168166
StatusMessage = "Verification email sent. Please check your email.";
169167
return RedirectToPage();

MyApp/Areas/Identity/Pages/Account/Register.cshtml.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public class RegisterModel : PageModel
2929
private readonly IUserStore<ApplicationUser> _userStore;
3030
private readonly IUserEmailStore<ApplicationUser> _emailStore;
3131
private readonly ILogger<RegisterModel> _logger;
32-
private readonly IEmailSender _emailSender;
32+
private readonly IEmailSender<ApplicationUser> _emailSender;
3333

3434
public RegisterModel(
3535
UserManager<ApplicationUser> userManager,
3636
IUserStore<ApplicationUser> userStore,
3737
SignInManager<ApplicationUser> signInManager,
3838
ILogger<RegisterModel> logger,
39-
IEmailSender emailSender)
39+
IEmailSender<ApplicationUser> emailSender)
4040
{
4141
_userManager = userManager;
4242
_userStore = userStore;
@@ -130,10 +130,11 @@ public async Task<IActionResult> OnPostAsync(string returnUrl = null)
130130
"/Account/ConfirmEmail",
131131
pageHandler: null,
132132
values: new { area = "Identity", userId = userId, code = code, returnUrl = returnUrl },
133-
protocol: Request.Scheme);
133+
protocol: Request.Scheme)!;
134134

135-
await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
136-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
135+
await _emailSender.SendConfirmationLinkAsync(user,
136+
Input.Email,
137+
callbackUrl);
137138

138139
if (_userManager.Options.SignIn.RequireConfirmedAccount)
139140
{

MyApp/Areas/Identity/Pages/Account/RegisterConfirmation.cshtml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace MyApp.Areas.Identity.Pages.Account
1919
public class RegisterConfirmationModel : PageModel
2020
{
2121
private readonly UserManager<ApplicationUser> _userManager;
22-
private readonly IEmailSender _sender;
22+
private readonly IEmailSender<ApplicationUser> _sender;
2323

24-
public RegisterConfirmationModel(UserManager<ApplicationUser> userManager, IEmailSender sender)
24+
public RegisterConfirmationModel(UserManager<ApplicationUser> userManager, IEmailSender<ApplicationUser> sender)
2525
{
2626
_userManager = userManager;
2727
_sender = sender;

MyApp/Areas/Identity/Pages/Account/ResendEmailConfirmation.cshtml.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ namespace MyApp.Areas.Identity.Pages.Account
2121
public class ResendEmailConfirmationModel : PageModel
2222
{
2323
private readonly UserManager<ApplicationUser> _userManager;
24-
private readonly IEmailSender _emailSender;
24+
private readonly IEmailSender<ApplicationUser> _emailSender;
2525

26-
public ResendEmailConfirmationModel(UserManager<ApplicationUser> userManager, IEmailSender emailSender)
26+
public ResendEmailConfirmationModel(UserManager<ApplicationUser> userManager, IEmailSender<ApplicationUser> emailSender)
2727
{
2828
_userManager = userManager;
2929
_emailSender = emailSender;
@@ -76,11 +76,10 @@ public async Task<IActionResult> OnPostAsync()
7676
"/Account/ConfirmEmail",
7777
pageHandler: null,
7878
values: new { userId = userId, code = code },
79-
protocol: Request.Scheme);
80-
await _emailSender.SendEmailAsync(
79+
protocol: Request.Scheme)!;
80+
await _emailSender.SendConfirmationLinkAsync(user,
8181
Input.Email,
82-
"Confirm your email",
83-
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
82+
callbackUrl);
8483

8584
ModelState.AddModelError(string.Empty, "Verification email sent. Please check your email.");
8685
return Page();

MyApp/Configure.AppHost.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1-
using Funq;
2-
using ServiceStack;
3-
using MyApp.ServiceInterface;
4-
5-
[assembly: HostingStartup(typeof(MyApp.AppHost))]
1+
[assembly: HostingStartup(typeof(MyApp.AppHost))]
62

73
namespace MyApp;
84

9-
public class AppHost : AppHostBase, IHostingStartup
5+
public class AppHost() : AppHostBase("MyApp"), IHostingStartup
106
{
117
public void Configure(IWebHostBuilder builder) => builder
128
.ConfigureServices((context,services) => {
139
// Configure ASP.NET Core IOC Dependencies
1410
});
1511

16-
public AppHost() : base("MyApp", typeof(MyServices).Assembly) { }
17-
1812
// Configure your AppHost with the necessary configuration and dependencies your App needs
19-
public override void Configure(Container container)
13+
public override void Configure()
2014
{
2115
SetConfig(new HostConfig {
2216
});

MyApp/Configure.Auth.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
using System.Security.Claims;
2-
using Microsoft.AspNetCore.Identity;
3-
using ServiceStack;
41
using ServiceStack.Auth;
5-
using MyApp.Data;
6-
using ServiceStack.Configuration;
7-
using ServiceStack.Text;
82

93
[assembly: HostingStartup(typeof(MyApp.ConfigureAuth))]
104

@@ -19,8 +13,9 @@ public void Configure(IWebHostBuilder builder) => builder
1913
.ConfigureAppHost(appHost =>
2014
{
2115
appHost.Plugins.Add(new AuthFeature(IdentityAuth.For<ApplicationUser>(options => {
22-
options.EnableCredentialsAuth = true;
2316
options.SessionFactory = () => new CustomUserSession();
17+
options.CredentialsAuth();
18+
options.AdminUsersFeature();
2419
})));
2520
});
2621
}

0 commit comments

Comments
 (0)