-
Notifications
You must be signed in to change notification settings - Fork 558
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate IdentityServer4 -> Duende IdentityServer
- Loading branch information
1 parent
4288433
commit 1b2eaae
Showing
345 changed files
with
9,673 additions
and
9,876 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
src/IdentityServer/Duende/ClassifiedAds.IdentityServer/Controllers/AccountController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
using ClassifiedAds.Domain.Entities; | ||
using ClassifiedAds.IdentityServer.Models.AccountModels; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace ClassifiedAds.IdentityServer.Controllers; | ||
|
||
public class AccountController : Controller | ||
{ | ||
private readonly UserManager<User> _userManager; | ||
private readonly SignInManager<User> _signInManager; | ||
|
||
public AccountController(UserManager<User> userManager, | ||
SignInManager<User> signInManager) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> ConfirmEmailAddress(string token, string email) | ||
{ | ||
var user = await _userManager.FindByEmailAsync(email); | ||
|
||
if (user == null) | ||
{ | ||
return View("Error"); | ||
} | ||
|
||
var result = await _userManager.ConfirmEmailAsync(user, token); | ||
|
||
if (result.Succeeded) | ||
{ | ||
return View("Success"); | ||
} | ||
|
||
return View("Error"); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult ForgotPassword() | ||
{ | ||
return View(); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> ForgotPassword(ForgotPasswordModel model) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return View(); | ||
} | ||
|
||
var user = await _userManager.FindByEmailAsync(model.Email); | ||
|
||
if (user != null) | ||
{ | ||
var token = await _userManager.GeneratePasswordResetTokenAsync(user); | ||
var resetUrl = Url.Action("ResetPassword", "Account", | ||
new { token = token, email = user.Email }, Request.Scheme); | ||
|
||
//await _dispatcher.DispatchAsync(new AddOrUpdateEntityCommand<EmailMessage>(new EmailMessage | ||
//{ | ||
// From = "[email protected]", | ||
// Tos = user.Email, | ||
// Subject = "Forgot Password", | ||
// Body = string.Format("Reset Url: {0}", resetUrl), | ||
//})); | ||
} | ||
else | ||
{ | ||
// email user and inform them that they do not have an account | ||
} | ||
|
||
return View("Success"); | ||
} | ||
|
||
[HttpGet] | ||
public IActionResult ResetPassword(string token, string email) | ||
{ | ||
return View(new ResetPasswordModel { Token = token, Email = email }); | ||
} | ||
|
||
[HttpPost] | ||
public async Task<IActionResult> ResetPassword(ResetPasswordModel model) | ||
{ | ||
if (!ModelState.IsValid) | ||
{ | ||
return View(); | ||
} | ||
|
||
var user = await _userManager.FindByEmailAsync(model.Email); | ||
|
||
if (user == null) | ||
{ | ||
ModelState.AddModelError(string.Empty, "Invalid Request"); | ||
return View(); | ||
} | ||
|
||
var result = await _userManager.ResetPasswordAsync(user, model.Token, model.Password); | ||
|
||
if (result.Succeeded) | ||
{ | ||
return View("Success"); | ||
} | ||
|
||
foreach (var error in result.Errors) | ||
{ | ||
ModelState.AddModelError(string.Empty, error.Description); | ||
} | ||
|
||
return View(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ntityServer/Models/ForgotPasswordModel.cs → ...dels/AccountModels/ForgotPasswordModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ds.IdentityServer/Models/RegisterModel.cs → ...ver/Models/AccountModels/RegisterModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...entityServer/Models/ResetPasswordModel.cs → ...odels/AccountModels/ResetPasswordModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/IdentityServer/Duende/ClassifiedAds.IdentityServer/Views/Account/Error.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
<div class="alert alert-danger"> | ||
<p>Error!</p> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
src/IdentityServer/Duende/ClassifiedAds.IdentityServer/Views/Account/ForgotPassword.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@using ClassifiedAds.IdentityServer.Models.AccountModels | ||
|
||
@model ForgotPasswordModel | ||
|
||
@await Html.PartialAsync("_ValidationSummary") | ||
|
||
<h1>Forgot Password</h1> | ||
<h4>Enter your email</h4> | ||
|
||
<hr /> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form asp-controller="Account" asp-action="ForgotPassword" method="post"> | ||
<div class="form-group"> | ||
<label asp-for="Email">Email</label> | ||
<input asp-for="Email" class="form-control" /> | ||
<span asp-validation-for="Email" class="text-danger"></span> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</form> | ||
</div> | ||
</div> |
33 changes: 33 additions & 0 deletions
33
src/IdentityServer/Duende/ClassifiedAds.IdentityServer/Views/Account/ResetPassword.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@using ClassifiedAds.IdentityServer.Models.AccountModels | ||
|
||
@model ResetPasswordModel | ||
|
||
<h1>Reset Password</h1> | ||
|
||
@await Html.PartialAsync("_ValidationSummary") | ||
|
||
<form asp-controller="Account" asp-action="ResetPassword" method="post" class="form-horizontal"> | ||
<h4>Enter new password</h4> | ||
<hr /> | ||
<input asp-for="Token" type="hidden" /> | ||
<input asp-for="Email" type="hidden" /> | ||
<div class="form-group"> | ||
<label asp-for="Password" class="col-md-2 control-label">Password</label> | ||
<div class="col-md-10"> | ||
<input asp-for="Password" class="form-control" /> | ||
<span asp-validation-for="Password" class="text-danger"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<label asp-for="ConfirmPassword" class="col-md-2 control-label">Confirm Password</label> | ||
<div class="col-md-10"> | ||
<input asp-for="ConfirmPassword" class="form-control" /> | ||
<span asp-validation-for="ConfirmPassword" class="text-danger"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<div class="col-md-offset-2 col-md-10"> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</div> | ||
</div> | ||
</form> |
3 changes: 3 additions & 0 deletions
3
src/IdentityServer/Duende/ClassifiedAds.IdentityServer/Views/Account/Success.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="alert alert-success"> | ||
<p>Success!</p> | ||
</div> |
21 changes: 10 additions & 11 deletions
21
...Server/IdentityServer4/ClassifiedAds.Application/AuditLogEntries/DTOs/AuditLogEntryDTO.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
using System; | ||
|
||
namespace ClassifiedAds.Application.AuditLogEntries.DTOs | ||
namespace ClassifiedAds.Application.AuditLogEntries.DTOs; | ||
|
||
public class AuditLogEntryDTO | ||
{ | ||
public class AuditLogEntryDTO | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid Id { get; set; } | ||
|
||
public Guid UserId { get; set; } | ||
public Guid UserId { get; set; } | ||
|
||
public string UserName { get; set; } | ||
public string UserName { get; set; } | ||
|
||
public string Action { get; set; } | ||
public string Action { get; set; } | ||
|
||
public string ObjectId { get; set; } | ||
public string ObjectId { get; set; } | ||
|
||
public string Log { get; set; } | ||
public string Log { get; set; } | ||
|
||
public DateTimeOffset CreatedDateTime { get; set; } | ||
} | ||
public DateTimeOffset CreatedDateTime { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.