Skip to content

Commit 0ddd808

Browse files
committed
Upgrade to latest template
1 parent 3b2babf commit 0ddd808

26 files changed

+131
-218
lines changed

MyApp.ServiceInterface/AppConfig.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
public class AppConfig
44
{
5-
public string? AppBaseUrl { get; set; }
6-
public string? ApiBaseUrl { get; set; }
5+
public string? BaseUrl { get; set; }
76
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
1+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
22
using Microsoft.EntityFrameworkCore;
33

44
namespace MyApp.Data;
55

6-
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
6+
public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
77
: IdentityDbContext<ApplicationUser>(options)
88
{
99
}

MyApp.ServiceInterface/Data/ApplicationUser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Microsoft.AspNetCore.Identity;
1+
using Microsoft.AspNetCore.Identity;
22

33
namespace MyApp.Data;
44

@@ -9,4 +9,4 @@ public class ApplicationUser : IdentityUser
99
public string? LastName { get; set; }
1010
public string? DisplayName { get; set; }
1111
public string? ProfileUrl { get; set; }
12-
}
12+
}

MyApp.ServiceInterface/Data/CustomUserSession.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Security.Claims;
1+
using System.Security.Claims;
22
using Microsoft.AspNetCore.Identity;
33
using Microsoft.Extensions.Options;
44
using ServiceStack;
@@ -19,9 +19,9 @@ public override void PopulateFromClaims(IRequest httpReq, ClaimsPrincipal princi
1919
/// Add additional claims to the Identity Auth Cookie
2020
/// </summary>
2121
public class AdditionalUserClaimsPrincipalFactory(
22-
UserManager<ApplicationUser> userManager,
23-
RoleManager<IdentityRole> roleManager,
24-
IOptions<IdentityOptions> optionsAccessor)
22+
UserManager<ApplicationUser> userManager,
23+
RoleManager<IdentityRole> roleManager,
24+
IOptions<IdentityOptions> optionsAccessor)
2525
: UserClaimsPrincipalFactory<ApplicationUser,IdentityRole>(userManager, roleManager, optionsAccessor)
2626
{
2727
public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user)
@@ -39,4 +39,4 @@ public override async Task<ClaimsPrincipal> CreateAsync(ApplicationUser user)
3939
identity.AddClaims(claims);
4040
return principal;
4141
}
42-
}
42+
}

MyApp.ServiceInterface/EmailServices.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ public class SmtpConfig
1414
/// <summary>
1515
/// Username of the SMTP Server account
1616
/// </summary>
17-
public string Username { get; set; }
17+
public required string Username { get; set; }
1818
/// <summary>
1919
/// Password of the SMTP Server account
2020
/// </summary>
21-
public string Password { get; set; }
21+
public required string Password { get; set; }
2222
/// <summary>
2323
/// Hostname of the SMTP Server
2424
/// </summary>
25-
public string Host { get; set; }
25+
public required string Host { get; set; }
2626
/// <summary>
2727
/// Port of the SMTP Server
2828
/// </summary>
2929
public int Port { get; set; } = 587;
3030
/// <summary>
3131
/// Which email address to send emails from
3232
/// </summary>
33-
public string FromEmail { get; set; }
33+
public required string FromEmail { get; set; }
3434
/// <summary>
3535
/// The name of the Email Sender
3636
/// </summary>
@@ -47,9 +47,9 @@ public class SmtpConfig
4747

4848
public class SendEmail
4949
{
50-
public string To { get; set; }
50+
public required string To { get; set; }
5151
public string? ToName { get; set; }
52-
public string Subject { get; set; }
52+
public required string Subject { get; set; }
5353
public string? BodyText { get; set; }
5454
public string? BodyHtml { get; set; }
5555
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Microsoft.AspNetCore.Identity;
1+
using Microsoft.AspNetCore.Identity;
22
using Microsoft.AspNetCore.Identity.UI.Services;
3+
using MyApp.Data;
34

4-
namespace MyApp.Data;
5+
namespace MyApp.ServiceInterface;
56

6-
/// <summary>
7-
/// To send real emails, configure SmtpConfig in appsettings.json and register EmailSender instead
8-
/// </summary>
7+
// Remove the "else if (EmailSender is IdentityNoOpEmailSender)" block from RegisterConfirmation.razor after updating with a real implementation.
98
public sealed class IdentityNoOpEmailSender : IEmailSender<ApplicationUser>
109
{
1110
private readonly IEmailSender emailSender = new NoOpEmailSender();
@@ -18,4 +17,4 @@ public Task SendPasswordResetLinkAsync(ApplicationUser user, string email, strin
1817

1918
public Task SendPasswordResetCodeAsync(ApplicationUser user, string email, string resetCode) =>
2019
emailSender.SendEmailAsync(email, "Reset your password", $"Please reset your password using the following code: {resetCode}");
21-
}
20+
}
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
5-
<Nullable>enable</Nullable>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
</PropertyGroup>
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
88

9-
<ItemGroup>
10-
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />
11-
</ItemGroup>
9+
<ItemGroup>
10+
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />
11+
</ItemGroup>
1212

13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.*" />
15-
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.*" />
16-
<PackageReference Include="ServiceStack" Version="8.*" />
17-
<PackageReference Include="ServiceStack.Extensions" Version="8.*" />
18-
<PackageReference Include="ServiceStack.Ormlite" Version="8.*" />
19-
</ItemGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore"
15+
Version="10.*" />
16+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="10.*" />
17+
<PackageReference Include="ServiceStack" Version="8.*" />
18+
<PackageReference Include="ServiceStack.Extensions" Version="8.*" />
19+
<PackageReference Include="ServiceStack.Ormlite" Version="8.*" />
20+
</ItemGroup>
2021

2122
</Project>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using ServiceStack;
22
using MyApp.ServiceModel;
3-
using ServiceStack.OrmLite;
43

54
namespace MyApp.ServiceInterface;
65

@@ -9,5 +8,5 @@ public class MyServices : Service
98
public object Any(Hello request)
109
{
1110
return new HelloResponse { Result = $"Hello, {request.Name}!" };
12-
}
11+
}
1312
}

MyApp.ServiceInterface/RegisterService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ public IdentityRegistrationValidator()
5050
public class RegisterService(UserManager<ApplicationUser> userManager, IEmailSender<ApplicationUser> emailSender, AppConfig appConfig)
5151
: IdentityRegisterServiceBase<ApplicationUser>(userManager)
5252
{
53-
string AppBaseUrl => appConfig.AppBaseUrl ?? Request.GetBaseUrl();
54-
string ApiBaseUrl => appConfig.ApiBaseUrl ?? Request.GetBaseUrl();
55-
private string AppErrorUrl => AppBaseUrl.CombineWith("/error");
53+
string BaseUrl => appConfig.BaseUrl ?? Request.GetBaseUrl();
54+
private string AppErrorUrl => BaseUrl.CombineWith("/error");
5655

5756
public async Task<object> PostAsync(Register request)
5857
{
@@ -62,6 +61,7 @@ public async Task<object> PostAsync(Register request)
6261
var newUser = request.ConvertTo<ApplicationUser>();
6362
newUser.UserName ??= newUser.Email;
6463
newUser.Email = request.Email;
64+
newUser.ProfileUrl ??= SvgCreator.CreateSvgDataUri(char.ToUpper(newUser.UserName![0]));
6565

6666
//TODO: Remove to use force email confirmation
6767
//newUser.EmailConfirmed = emailNotSetup;
@@ -75,7 +75,7 @@ public async Task<object> PostAsync(Register request)
7575
var userId = await UserManager.GetUserIdAsync(newUser);
7676
var code = await UserManager.GenerateEmailConfirmationTokenAsync(newUser);
7777
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
78-
var callbackUrl = ApiBaseUrl.CombineWith(new ConfirmEmail
78+
var callbackUrl = BaseUrl.CombineWith(new ConfirmEmail
7979
{
8080
UserId = userId,
8181
Code = code,
@@ -89,7 +89,7 @@ public async Task<object> PostAsync(Register request)
8989

9090
if (response is RegisterResponse registerResponse)
9191
{
92-
var signupConfirmUrl = AppBaseUrl.CombineWith("/signup-confirm");
92+
var signupConfirmUrl = BaseUrl.CombineWith("/signup-confirm");
9393
if (emailNotSetup)
9494
signupConfirmUrl = signupConfirmUrl.AddQueryParam("confirmLink", callbackUrl);
9595

@@ -110,6 +110,6 @@ public async Task<object> Any(ConfirmEmail request)
110110
if (!result.Succeeded)
111111
return HttpResult.Redirect(AppErrorUrl.AddQueryParam("message", "Error confirming your email."));
112112

113-
return HttpResult.Redirect(AppBaseUrl.CombineWith(request.ReturnUrl ?? "/signin"));
113+
return HttpResult.Redirect(BaseUrl.CombineWith(request.ReturnUrl ?? "/signin"));
114114
}
115115
}

MyApp.ServiceModel/Bookings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Complete declarative AutoQuery services for Bookings CRUD example:
1+
// Complete declarative AutoQuery services for Bookings CRUD example:
22
// https://docs.servicestack.net/autoquery-crud-bookings
33

44
using System;

0 commit comments

Comments
 (0)