Skip to content

Commit

Permalink
Forgot password flow (#19)
Browse files Browse the repository at this point in the history
* Add flow for forgot password

* Update gitignore

* Fix untracked files

* Remove unused property

Rename files and adopted the options pattern. Remove the placeholder and place the username there. Added entry in appSettings.json file in docs and other changes

* Replace file from entities to Options folder; Propagate returnurl

* Remove necessary config overrides, add returnUrl override logic

* Make the project build again.

* The register page incorrectly used the display name as username.

* Add a development mail service.

Co-authored-by: Paul Scharnofske <[email protected]>
  • Loading branch information
weegee and asynts authored Apr 3, 2020
1 parent c5d195e commit 902a8dc
Show file tree
Hide file tree
Showing 20 changed files with 724 additions and 31 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "3.3.111304",
"commands": [
"dotnet-format"
]
},
"dotnet-ef": {
"version": "3.1.3",
"commands": [
"dotnet-ef"
]
}
}
}
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,31 @@ obj/
/.vs/
/.vscode/
*.user

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
45 changes: 24 additions & 21 deletions docs/defaults/src/WebApp/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,32 @@
}
},
"IdentityServer": {
"Clients": [
{
"ClientId": "codidact_client",
"ClientSecrets": [
{
"Value": "LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564="
}
],
"AllowedGrantTypes": [
"authorization_code"
],
"AllowedScopes": [
"openid",
"profile"
],
"RedirectUris": [
"http://localhost:8000/signin-oidc"
],
"RequireConsent": false
}
]
"Clients": [{
"ClientId": "codidact_client",
"ClientSecrets": [{
"Value": "LCa0a2j/xo/5m0U8HTBBNBNCLXBkg7+g+YpeiGJm564="
}],
"AllowedGrantTypes": [
"authorization_code"
],
"AllowedScopes": [
"openid",
"profile"
],
"RedirectUris": [
"http://localhost:8000/signin-oidc"
],
"RequireConsent": false
}]
},
"ConnectionStrings": {
"Authentication": "Data Source=authentication.db"
},
"Mail": {
"Host": "smtp.gmail.com",
"Port": 465,
"Sender": "[email protected]",
"SenderName": "example",
"EnableSsl": true
}
}
12 changes: 12 additions & 0 deletions src/Application/Common/Interfaces/IMailService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;
using Codidact.Authentication.Domain.Entities;


namespace Codidact.Authentication.Application.Common.Interfaces
{
public interface IMailService
{
Task SendEmailAsync(ApplicationUser user, string subject, string message);
Task SendResetPassword(ApplicationUser user, string token, string returnUrl);
}
}
11 changes: 11 additions & 0 deletions src/Application/Options/MailOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Codidact.Authentication.Application.Options
{
public class MailOptions
{
public string Host { get; set; }
public int Port { get; set; }
public string SenderName { get; set; }
public string Sender { get; set; }
public bool EnableSsl { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Domain/Entities/ApplicationUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Codidact.Authentication.Domain.Entities
{
public class ApplicationUser : IdentityUser<long>
{

public string DisplayName { get; set; }
}
}
16 changes: 15 additions & 1 deletion src/Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Codidact.Authentication.Application.Common.Interfaces;
using Codidact.Authentication.Infrastructure.Services;
using Codidact.Authentication.Domain.Entities;
using Codidact.Authentication.Application.Options;

namespace Codidact.Authentication.Infrastructure
{
Expand Down Expand Up @@ -45,7 +46,8 @@ public static IServiceCollection AddInfrastructure(
options.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager();
.AddSignInManager()
.AddDefaultTokenProviders();

var identityServerBuilder = services.AddIdentityServer()
.AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"))
Expand All @@ -60,6 +62,18 @@ public static IServiceCollection AddInfrastructure(
services.AddAuthentication()
.AddIdentityCookies();

services.AddSingleton(configuration.GetSection("Mail").Get<MailOptions>());


if (environment.IsDevelopment())
{
services.AddScoped<IMailService, DevelopmentMailService>();
}
else
{
services.AddScoped<IMailService, MailService>();
}

return services;
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
<AssemblyName>Codidact.Authentication.Infrastructure</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.2" />
<PackageReference Include="IdentityServer4" Version="3.1.2" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="2.5.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="MimeKit" Version="2.5.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.2" />
<PackageReference Include="IdentityServer4" Version="3.1.2" />
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="3.1.2" />
</ItemGroup>

<ItemGroup>
<Folder Include="Persistance/Migrations/" />
Expand Down
Loading

0 comments on commit 902a8dc

Please sign in to comment.