-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix for #10, updating tests for role seperation from users and separa…
…te tests for netcore2.0 and netcore3.0. version 2.2. adding netcore3 sample
- Loading branch information
1 parent
4d80da9
commit 63e6550
Showing
110 changed files
with
4,736 additions
and
227 deletions.
There are no files selected for viewing
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
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
21 changes: 21 additions & 0 deletions
21
sample/samplecore3.mvc/Areas/Identity/IdentityHostingStartup.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,21 @@ | ||
using System; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Identity.UI; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using samplecore3.mvc.Data; | ||
|
||
[assembly: HostingStartup(typeof(samplecore3.mvc.Areas.Identity.IdentityHostingStartup))] | ||
namespace samplecore3.mvc.Areas.Identity | ||
{ | ||
public class IdentityHostingStartup : IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) | ||
{ | ||
builder.ConfigureServices((context, services) => { | ||
}); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
sample/samplecore3.mvc/Areas/Identity/Pages/Account/AccessDenied.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,10 @@ | ||
@page | ||
@model AccessDeniedModel | ||
@{ | ||
ViewData["Title"] = "Access denied"; | ||
} | ||
|
||
<header> | ||
<h1 class="text-danger">@ViewData["Title"]</h1> | ||
<p class="text-danger">You do not have access to this resource.</p> | ||
</header> |
17 changes: 17 additions & 0 deletions
17
sample/samplecore3.mvc/Areas/Identity/Pages/Account/AccessDenied.cshtml.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,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
|
||
namespace samplecore3.mvc.Areas.Identity.Pages.Account | ||
{ | ||
public class AccessDeniedModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmail.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,8 @@ | ||
@page | ||
@model ConfirmEmailModel | ||
@{ | ||
ViewData["Title"] = "Confirm email"; | ||
} | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
<partial name="_StatusMessage" model="Model.StatusMessage" /> |
47 changes: 47 additions & 0 deletions
47
sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmail.cshtml.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,47 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser; | ||
|
||
namespace samplecore3.mvc.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ConfirmEmailModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
|
||
public ConfirmEmailModel(UserManager<IdentityUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
[TempData] | ||
public string StatusMessage { get; set; } | ||
|
||
public async Task<IActionResult> OnGetAsync(string userId, string code) | ||
{ | ||
if (userId == null || code == null) | ||
{ | ||
return RedirectToPage("/Index"); | ||
} | ||
|
||
var user = await _userManager.FindByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{userId}'."); | ||
} | ||
|
||
code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); | ||
var result = await _userManager.ConfirmEmailAsync(user, code); | ||
StatusMessage = result.Succeeded ? "Thank you for confirming your email." : "Error confirming your email."; | ||
return Page(); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmailChange.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,8 @@ | ||
@page | ||
@model ConfirmEmailChangeModel | ||
@{ | ||
ViewData["Title"] = "Confirm email change"; | ||
} | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
<partial name="_StatusMessage" model="Model.StatusMessage" /> |
65 changes: 65 additions & 0 deletions
65
sample/samplecore3.mvc/Areas/Identity/Pages/Account/ConfirmEmailChange.cshtml.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,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.AspNetCore.WebUtilities; | ||
using IdentityUser = ElCamino.AspNetCore.Identity.DocumentDB.Model.IdentityUser; | ||
|
||
namespace samplecore3.mvc.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ConfirmEmailChangeModel : PageModel | ||
{ | ||
private readonly UserManager<IdentityUser> _userManager; | ||
private readonly SignInManager<IdentityUser> _signInManager; | ||
|
||
public ConfirmEmailChangeModel(UserManager<IdentityUser> userManager, SignInManager<IdentityUser> signInManager) | ||
{ | ||
_userManager = userManager; | ||
_signInManager = signInManager; | ||
} | ||
|
||
[TempData] | ||
public string StatusMessage { get; set; } | ||
|
||
public async Task<IActionResult> OnGetAsync(string userId, string email, string code) | ||
{ | ||
if (userId == null || email == null || code == null) | ||
{ | ||
return RedirectToPage("/Index"); | ||
} | ||
|
||
var user = await _userManager.FindByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
return NotFound($"Unable to load user with ID '{userId}'."); | ||
} | ||
|
||
code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code)); | ||
var result = await _userManager.ChangeEmailAsync(user, email, code); | ||
if (!result.Succeeded) | ||
{ | ||
StatusMessage = "Error changing email."; | ||
return Page(); | ||
} | ||
|
||
// In our UI email and user name are one and the same, so when we update the email | ||
// we need to update the user name. | ||
var setUserNameResult = await _userManager.SetUserNameAsync(user, email); | ||
if (!setUserNameResult.Succeeded) | ||
{ | ||
StatusMessage = "Error changing user name."; | ||
return Page(); | ||
} | ||
|
||
await _signInManager.RefreshSignInAsync(user); | ||
StatusMessage = "Thank you for confirming your email change."; | ||
return Page(); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
sample/samplecore3.mvc/Areas/Identity/Pages/Account/ExternalLogin.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 @@ | ||
@page | ||
@model ExternalLoginModel | ||
@{ | ||
ViewData["Title"] = "Register"; | ||
} | ||
|
||
<h1>@ViewData["Title"]</h1> | ||
<h4>Associate your @Model.LoginProvider account.</h4> | ||
<hr /> | ||
|
||
<p class="text-info"> | ||
You've successfully authenticated with <strong>@Model.LoginProvider</strong>. | ||
Please enter an email address for this site below and click the Register button to finish | ||
logging in. | ||
</p> | ||
|
||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form asp-page-handler="Confirmation" asp-route-returnUrl="@Model.ReturnUrl" method="post"> | ||
<div asp-validation-summary="All" class="text-danger"></div> | ||
<div class="form-group"> | ||
<label asp-for="Input.Email"></label> | ||
<input asp-for="Input.Email" class="form-control" /> | ||
<span asp-validation-for="Input.Email" class="text-danger"></span> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Register</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
Oops, something went wrong.