-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c937760
commit ef5185a
Showing
150 changed files
with
20,146 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/template", | ||
"identity": "RazorStripe", | ||
"author": "Dragon Mastery LLC", | ||
"classifications": [ "Web/MVC/Razor Pages" ], | ||
"name": "ASP.NET Core 2.2 Web App Razor Stripe", | ||
"shortName": "razorstripe", | ||
"tags": { | ||
"language": "C#" | ||
}, | ||
"sourceName": "RazorStripe", | ||
"symbols":{ | ||
"copyrightName": { | ||
"type": "parameter", | ||
"defaultValue": "Company", | ||
"replaces":"Dragon Mastery LLC" | ||
} | ||
}, | ||
"postActions": [ | ||
{ | ||
"condition": "(!skipRestore)", | ||
"description": "Restore NuGet packages required by this project.", | ||
"manualInstructions": [ | ||
{ "text": "Run 'dotnet restore'" } | ||
], | ||
"actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025", | ||
"continueOnError": true | ||
} | ||
] | ||
} |
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 RazorStripe.Data; | ||
|
||
[assembly: HostingStartup(typeof(RazorStripe.Areas.Identity.IdentityHostingStartup))] | ||
namespace RazorStripe.Areas.Identity | ||
{ | ||
public class IdentityHostingStartup : IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) | ||
{ | ||
builder.ConfigureServices((context, services) => { | ||
}); | ||
} | ||
} | ||
} |
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> |
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 RazorStripe.Areas.Identity.Pages.Account | ||
{ | ||
public class AccessDeniedModel : PageModel | ||
{ | ||
public void OnGet() | ||
{ | ||
|
||
} | ||
} | ||
} | ||
|
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,12 @@ | ||
@page | ||
@model ConfirmEmailModel | ||
@{ | ||
ViewData["Title"] = "Confirm email"; | ||
} | ||
|
||
<h2>@ViewData["Title"]</h2> | ||
<div> | ||
<p> | ||
Thank you for confirming your email. | ||
</p> | ||
</div> |
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,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using RazorStripe.Data; | ||
using RazorStripe.Data.Models; | ||
|
||
namespace RazorStripe.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ConfirmEmailModel : PageModel | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
|
||
public ConfirmEmailModel(UserManager<ApplicationUser> userManager) | ||
{ | ||
_userManager = userManager; | ||
} | ||
|
||
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}'."); | ||
} | ||
|
||
var result = await _userManager.ConfirmEmailAsync(user, code); | ||
if (!result.Succeeded) | ||
{ | ||
throw new InvalidOperationException($"Error confirming email for user with ID '{userId}':"); | ||
} | ||
|
||
return Page(); | ||
} | ||
} | ||
} |
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,34 @@ | ||
@page | ||
@model ExternalLoginModel | ||
@{ | ||
ViewData["Title"] = "Register"; | ||
} | ||
|
||
<h2>@ViewData["Title"]</h2> | ||
<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-default">Register</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} | ||
|
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,142 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel.DataAnnotations; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
using RazorStripe.Data; | ||
using RazorStripe.Data.Models; | ||
|
||
namespace RazorStripe.Areas.Identity.Pages.Account | ||
{ | ||
[AllowAnonymous] | ||
public class ExternalLoginModel : PageModel | ||
{ | ||
private readonly SignInManager<ApplicationUser> _signInManager; | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly ILogger<ExternalLoginModel> _logger; | ||
|
||
public ExternalLoginModel( | ||
SignInManager<ApplicationUser> signInManager, | ||
UserManager<ApplicationUser> userManager, | ||
ILogger<ExternalLoginModel> logger) | ||
{ | ||
_signInManager = signInManager; | ||
_userManager = userManager; | ||
_logger = logger; | ||
} | ||
|
||
[BindProperty] | ||
public InputModel Input { get; set; } | ||
|
||
public string LoginProvider { get; set; } | ||
|
||
public string ReturnUrl { get; set; } | ||
|
||
[TempData] | ||
public string ErrorMessage { get; set; } | ||
|
||
public class InputModel | ||
{ | ||
[Required] | ||
[EmailAddress] | ||
public string Email { get; set; } | ||
} | ||
|
||
public IActionResult OnGetAsync() | ||
{ | ||
return RedirectToPage("./Login"); | ||
} | ||
|
||
public IActionResult OnPost(string provider, string returnUrl = null) | ||
{ | ||
// Request a redirect to the external login provider. | ||
var redirectUrl = Url.Page("./ExternalLogin", pageHandler: "Callback", values: new { returnUrl }); | ||
var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); | ||
return new ChallengeResult(provider, properties); | ||
} | ||
|
||
public async Task<IActionResult> OnGetCallbackAsync(string returnUrl = null, string remoteError = null) | ||
{ | ||
returnUrl = returnUrl ?? Url.Content("~/"); | ||
if (remoteError != null) | ||
{ | ||
ErrorMessage = $"Error from external provider: {remoteError}"; | ||
return RedirectToPage("./Login", new {ReturnUrl = returnUrl }); | ||
} | ||
var info = await _signInManager.GetExternalLoginInfoAsync(); | ||
if (info == null) | ||
{ | ||
ErrorMessage = "Error loading external login information."; | ||
return RedirectToPage("./Login", new { ReturnUrl = returnUrl }); | ||
} | ||
|
||
// Sign in the user with this external login provider if the user already has a login. | ||
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor : true); | ||
if (result.Succeeded) | ||
{ | ||
_logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider); | ||
return LocalRedirect(returnUrl); | ||
} | ||
if (result.IsLockedOut) | ||
{ | ||
return RedirectToPage("./Lockout"); | ||
} | ||
else | ||
{ | ||
// If the user does not have an account, then ask the user to create an account. | ||
ReturnUrl = returnUrl; | ||
LoginProvider = info.LoginProvider; | ||
if (info.Principal.HasClaim(c => c.Type == ClaimTypes.Email)) | ||
{ | ||
Input = new InputModel | ||
{ | ||
Email = info.Principal.FindFirstValue(ClaimTypes.Email) | ||
}; | ||
} | ||
return Page(); | ||
} | ||
} | ||
|
||
public async Task<IActionResult> OnPostConfirmationAsync(string returnUrl = null) | ||
{ | ||
returnUrl = returnUrl ?? Url.Content("~/"); | ||
// Get the information about the user from the external login provider | ||
var info = await _signInManager.GetExternalLoginInfoAsync(); | ||
if (info == null) | ||
{ | ||
ErrorMessage = "Error loading external login information during confirmation."; | ||
return RedirectToPage("./Login", new { ReturnUrl = returnUrl }); | ||
} | ||
|
||
if (ModelState.IsValid) | ||
{ | ||
var user = new ApplicationUser { UserName = Input.Email, Email = Input.Email }; | ||
var result = await _userManager.CreateAsync(user); | ||
if (result.Succeeded) | ||
{ | ||
result = await _userManager.AddLoginAsync(user, info); | ||
if (result.Succeeded) | ||
{ | ||
await _signInManager.SignInAsync(user, isPersistent: false); | ||
_logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider); | ||
return LocalRedirect(returnUrl); | ||
} | ||
} | ||
foreach (var error in result.Errors) | ||
{ | ||
ModelState.AddModelError(string.Empty, error.Description); | ||
} | ||
} | ||
|
||
LoginProvider = info.LoginProvider; | ||
ReturnUrl = returnUrl; | ||
return Page(); | ||
} | ||
} | ||
} |
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,26 @@ | ||
@page | ||
@model ForgotPasswordModel | ||
@{ | ||
ViewData["Title"] = "Forgot your password?"; | ||
} | ||
|
||
<h2>@ViewData["Title"]</h2> | ||
<h4>Enter your email.</h4> | ||
<hr /> | ||
<div class="row"> | ||
<div class="col-md-4"> | ||
<form 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-default">Submit</button> | ||
</form> | ||
</div> | ||
</div> | ||
|
||
@section Scripts { | ||
<partial name="_ValidationScriptsPartial" /> | ||
} |
Oops, something went wrong.