Added MVC sample.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.3
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29009.5
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{DCA79957-4BB6-40F8-83A5-DAF316943D63}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
@@ -18,7 +18,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||
Readme.md = Readme.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{0C8F67DC-B6B3-4D8C-9E33-BBB47F858BE3}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.RazorPages", "Samples\RazorPages\Sample.RazorPages.csproj", "{0C8F67DC-B6B3-4D8C-9E33-BBB47F858BE3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.Mvc", "Samples\Mvc\Sample.Mvc\Sample.Mvc.csproj", "{8AA88A38-C74A-4F0D-9853-EFA0D78F0E63}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -34,6 +36,10 @@ Global
|
||||
{0C8F67DC-B6B3-4D8C-9E33-BBB47F858BE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0C8F67DC-B6B3-4D8C-9E33-BBB47F858BE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0C8F67DC-B6B3-4D8C-9E33-BBB47F858BE3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8AA88A38-C74A-4F0D-9853-EFA0D78F0E63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8AA88A38-C74A-4F0D-9853-EFA0D78F0E63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8AA88A38-C74A-4F0D-9853-EFA0D78F0E63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8AA88A38-C74A-4F0D-9853-EFA0D78F0E63}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace Raven.Identity
|
||||
/// <param name="role">The role whose normalized name should be retrieved.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
/// <returns>A <see cref="Task{TResult}"/> that contains the name of the role.</returns>
|
||||
public virtual Task<string> GetNormalizedRoleNameAsync(TRole role, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public virtual Task<string> GetNormalizedRoleNameAsync(TRole role, CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
ThrowIfDisposed();
|
||||
|
||||
@@ -134,6 +134,11 @@ namespace Raven.Identity
|
||||
user.Id = id;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(user.UserName))
|
||||
{
|
||||
user.UserName = user.Email;
|
||||
}
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// See if the email address is already taken.
|
||||
@@ -390,7 +395,9 @@ namespace Raven.Identity
|
||||
}
|
||||
|
||||
// See if we have an IdentityRole with that.
|
||||
var roleId = "IdentityRoles/" + roleNameLowered;
|
||||
var identityUserPrefix = DbSession.Advanced.DocumentStore.Conventions.GetCollectionName(typeof(IdentityRole));
|
||||
var identityPartSeperator = DbSession.Advanced.DocumentStore.Conventions.IdentityPartsSeparator;
|
||||
var roleId = identityUserPrefix + identityPartSeperator + roleNameLowered;
|
||||
var existingRoleOrNull = await this.DbSession.LoadAsync<IdentityRole>(roleId, cancellationToken);
|
||||
if (existingRoleOrNull == null)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using Raven.Client.Documents;
|
||||
using Sample.Mvc.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Common
|
||||
{
|
||||
public static class RavenExtensions
|
||||
{
|
||||
public static IDocumentStore EnsureExists(this IDocumentStore store)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var dbSession = store.OpenSession())
|
||||
{
|
||||
dbSession.Query<AppUser>().Take(0).ToList();
|
||||
}
|
||||
}
|
||||
catch (Raven.Client.Exceptions.Database.DatabaseDoesNotExistException)
|
||||
{
|
||||
store.Maintenance.Server.Send(new Raven.Client.ServerWide.Operations.CreateDatabaseOperation(new Raven.Client.ServerWide.DatabaseRecord
|
||||
{
|
||||
DatabaseName = store.Database
|
||||
}));
|
||||
}
|
||||
|
||||
return store;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
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 Raven.Client.Documents.Session;
|
||||
using Sample.Mvc.Models;
|
||||
|
||||
namespace Sample.Mvc.Controllers
|
||||
{
|
||||
public class AccountController : RavenController
|
||||
{
|
||||
private readonly SignInManager<AppUser> signInManager;
|
||||
private readonly UserManager<AppUser> userManager;
|
||||
|
||||
public AccountController(
|
||||
IAsyncDocumentSession dbSession, // injected thanks to Startup.cs call to services.AddRavenDbAsyncSession()
|
||||
UserManager<AppUser> userManager, // injected thanks to Startup.cs call to services.AddRavenDbIdentity<AppUser>()
|
||||
SignInManager<AppUser> signInManager) // injected thanks to Startup.cs call to services.AddRavenDbIdentity<AppUser>()
|
||||
: base(dbSession)
|
||||
{
|
||||
this.userManager = userManager;
|
||||
this.signInManager = signInManager;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult SignIn()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SignIn(SignInModel model)
|
||||
{
|
||||
var signInResult = await this.signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);
|
||||
if (signInResult.Succeeded)
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
var reason = signInResult.IsLockedOut ? "Your user is locked out" :
|
||||
signInResult.IsNotAllowed ? "Your user is not allowed to sign in" :
|
||||
signInResult.RequiresTwoFactor ? "2FA is required" :
|
||||
"Bad user name or password";
|
||||
return RedirectToAction("SignInFailure", new { reason = reason });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult SignInFailure(string reason)
|
||||
{
|
||||
ViewBag.FailureReason = reason;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Register(RegisterModel model)
|
||||
{
|
||||
// Create the user.
|
||||
var appUser = new AppUser
|
||||
{
|
||||
UserName = model.Email,
|
||||
Email = model.Email
|
||||
};
|
||||
var createUserResult = await this.userManager.CreateAsync(appUser, model.Password);
|
||||
if (!createUserResult.Succeeded)
|
||||
{
|
||||
var errorString = string.Join(", ", createUserResult.Errors.Select(e => e.Description));
|
||||
return RedirectToAction("RegisterFailure", new { reason = errorString });
|
||||
}
|
||||
|
||||
// Add him to a role.
|
||||
await this.userManager.AddToRoleAsync(appUser, AppUser.ManagerRole);
|
||||
|
||||
// Sign him in and go home.
|
||||
await this.signInManager.SignInAsync(appUser, true);
|
||||
return this.RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult RegisterFailure(string reason)
|
||||
{
|
||||
ViewBag.FailureReason = reason;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult ChangeRoles()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize] // Must be logged in to reach this page.
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> ChangeRoles(ChangeRolesModel model)
|
||||
{
|
||||
var currentUser = await this.userManager.FindByEmailAsync(User.Identity.Name);
|
||||
var currentRoles = await this.userManager.GetRolesAsync(currentUser);
|
||||
|
||||
// Add any new roles.
|
||||
var newRoles = model.Roles.Except(currentRoles).ToList();
|
||||
await this.userManager.AddToRolesAsync(currentUser, newRoles);
|
||||
|
||||
// Remove any old roles we're no longer in.
|
||||
var removedRoles = currentRoles.Except(model.Roles).ToList();
|
||||
await this.userManager.RemoveFromRolesAsync(currentUser, removedRoles);
|
||||
|
||||
// After we change roles, we need to call SignInAsync before AspNetCore Identity picks up the new roles.
|
||||
await this.signInManager.SignInAsync(currentUser, true);
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> SignOut()
|
||||
{
|
||||
await this.signInManager.SignOutAsync();
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult AccessDenied()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Sample.Mvc.Models;
|
||||
|
||||
namespace Sample.Mvc.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
var allRoles = new[] { AppUser.AdminRole, AppUser.ManagerRole };
|
||||
var userRoles = string.Join(", ", allRoles.Where(r => User.IsInRole(r)));
|
||||
|
||||
ViewBag.UserRoles = userRoles;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Roles = AppUser.AdminRole)]
|
||||
public IActionResult AdminOnly()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Raven.Client.Documents.Session;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// A controller that calls DbSession.SaveChangesAsync() when an action finishes executing successfully.
|
||||
/// </summary>
|
||||
public class RavenController : Controller
|
||||
{
|
||||
public RavenController(IAsyncDocumentSession dbSession)
|
||||
{
|
||||
this.DbSession = DbSession;
|
||||
|
||||
// RavenDB best practice: during save, wait for the indexes to update.
|
||||
// This way, Post-Redirect-Get scenarios won't be affected by stale indexes.
|
||||
// For more info, see https://ravendb.net/docs/article-page/4.2/csharp/client-api/session/saving-changes
|
||||
this.DbSession.Advanced.WaitForIndexesAfterSaveChanges(timeout: TimeSpan.FromSeconds(5), throwOnTimeout: false);
|
||||
}
|
||||
|
||||
public IAsyncDocumentSession DbSession { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Executes the action. If no error occurred, any changes made in the RavenDB document session will be saved.
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <param name="next"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
var executedContext = await next.Invoke();
|
||||
if (executedContext.Exception == null)
|
||||
{
|
||||
await DbSession.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Models
|
||||
{
|
||||
public class AppUser : Raven.Identity.IdentityUser
|
||||
{
|
||||
public const string AdminRole = "admin";
|
||||
public const string ManagerRole = "manager";
|
||||
|
||||
/// <summary>
|
||||
/// The user's full name.
|
||||
/// </summary>
|
||||
public string FullName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Models
|
||||
{
|
||||
public class ChangeRolesModel
|
||||
{
|
||||
public List<string> Roles { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Sample.Mvc.Models
|
||||
{
|
||||
public class ErrorViewModel
|
||||
{
|
||||
public string RequestId { get; set; }
|
||||
|
||||
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Models
|
||||
{
|
||||
public class RegisterModel
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sample.Mvc.Models
|
||||
{
|
||||
public class SignInModel
|
||||
{
|
||||
public string Email { get; set; }
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Sample.Mvc
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateWebHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
# RavenDB.Identity Sample
|
||||
|
||||
This is an AspNetCore MVC sample that shows how to use Raven.Identity.
|
||||
|
||||
There are four areas of interest:
|
||||
1. [appsettings.json](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/appsettings.json) - where we configure our connection to Raven.
|
||||
2. [AppUser.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Models/AppUser.cs) - our user class containing any user data like FirstName and LastName.
|
||||
3. [RavenController.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Controllers/RavenController.cs) - where we save changes to Raven after actions finish executing.
|
||||
4. [AccountController.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Controllers/AccountController.cs) - where we register users, sign in, change roles.
|
||||
5. [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Startup.cs) - where we wire up everything.
|
||||
|
||||
More details below.
|
||||
|
||||
## 1. appsettings.json - connection to Raven
|
||||
|
||||
Our [appsettings.json file](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/appsettings.json) defines our connection to Raven. This is done using the [RavenDB.DependencyInjection](https://github.com/JudahGabriel/RavenDB.DependencyInjection/) package.
|
||||
|
||||
```json
|
||||
"RavenSettings": {
|
||||
"Urls": [
|
||||
"http://live-test.ravendb.net"
|
||||
],
|
||||
"DatabaseName": "Raven.Identity.Sample.Mvc",
|
||||
"CertFilePath": "",
|
||||
"CertPassword": ""
|
||||
},
|
||||
```
|
||||
|
||||
## 2. AppUser.cs - user class
|
||||
|
||||
We create our own [AppUser class](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Models/AppUser.cs) to hold user data:
|
||||
|
||||
```csharp
|
||||
public class AppUser : Raven.Identity.IdentityUser
|
||||
{
|
||||
/// <summary>
|
||||
/// The full name of the user.
|
||||
/// </summary>
|
||||
public string FullName { get; set; }
|
||||
}
|
||||
```
|
||||
|
||||
While this step isn't strictly necessary -- it's possible to skip AppUser and just use the built-in `Raven.Identity.IdentityUser` -- we recommend creating an AppUser class so you can extend your users with app-specific data.
|
||||
|
||||
## 3. RavenController
|
||||
|
||||
We need to `.SaveChangesAsync()` for anything to persist in Raven. Where should we do this?
|
||||
|
||||
While we could call `.SaveChangesAsync()` in every controller action, that is tedious and error prone. Instead, we create a base controller, [RavenController.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Controllers/RavenController.cs):
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// A controller that calls DbSession.SaveChangesAsync() when an action finishes executing successfully.
|
||||
/// </summary>
|
||||
public class RavenController : Controller
|
||||
{
|
||||
public RavenController(IAsyncDocumentSession dbSession)
|
||||
{
|
||||
this.DbSession = DbSession;
|
||||
}
|
||||
|
||||
public IAsyncDocumentSession DbSession { get; private set; }
|
||||
|
||||
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
var executedContext = await next.Invoke();
|
||||
if (executedContext.Exception == null)
|
||||
{
|
||||
await DbSession.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 4. AccountController
|
||||
|
||||
In [AccountController.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/Mvc/Controllers/AccountController.cs), we use the standard AspNetCore identity APIs to do registration, sign in, role change, and more:
|
||||
|
||||
```csharp
|
||||
// Register a new user.
|
||||
var appUser = new AppUser
|
||||
{
|
||||
Email = model.Email
|
||||
};
|
||||
var password = "SuperSecret613$$"
|
||||
var createUserResult = await this.userManager.CreateAsync(appUser, password);
|
||||
```
|
||||
|
||||
Likewise for sign-in:
|
||||
|
||||
```csharp
|
||||
public async Task<IActionResult> SignIn(SignInModel model)
|
||||
{
|
||||
var signInResult = await this.signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);
|
||||
if (signInResult.Succeeded)
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## 5. Start.cs, wiring it all together
|
||||
|
||||
In [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Startup.cs), we wire up all of the above steps:
|
||||
|
||||
```csharp
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
// Grab our RavenSettings object from appsettings.json.
|
||||
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
|
||||
|
||||
...
|
||||
|
||||
// Add an IDocumentStore singleton, with settings pulled from the RavenSettings.
|
||||
services.AddRavenDbDocStore();
|
||||
|
||||
// Add a scoped IAsyncDocumentSession. For the sync version, use .AddRavenSession() instead.
|
||||
// Note: Your code is responsible for calling .SaveChangesAsync() on this. This Sample does so via the RavenSaveChangesAsyncFilter.
|
||||
services.AddRavenDbAsyncSession();
|
||||
|
||||
// Use Raven for our users
|
||||
services.AddRavenDbIdentity<AppUser>();
|
||||
|
||||
...
|
||||
|
||||
// Call .SaveChangesAsync() after each action.
|
||||
services
|
||||
.AddMvc(o => o.Filters.Add<RavenSaveChangesAsyncFilter>())
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
}
|
||||
```
|
||||
|
||||
Finally, make sure you call `app.UseAuthentication()` inside Configure:
|
||||
```csharp
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
...
|
||||
app.UseAuthentication();
|
||||
...
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
|
||||
<PackageReference Include="RavenDB.Client" Version="4.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\RavenDB.Identity\RavenDB.Identity.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Sample.Mvc.Models;
|
||||
using Raven.DependencyInjection;
|
||||
using Raven.Identity;
|
||||
using Raven.Client.Documents;
|
||||
using Sample.Mvc.Common;
|
||||
|
||||
namespace Sample.Mvc
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.Configure<CookiePolicyOptions>(options =>
|
||||
{
|
||||
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
|
||||
options.CheckConsentNeeded = context => false;
|
||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||
options.Secure = CookieSecurePolicy.Always;
|
||||
});
|
||||
|
||||
services
|
||||
.AddRavenDbDocStore() // Create our IDocumentStore singleton using the database settings in appsettings.json
|
||||
.AddRavenDbAsyncSession() // Create an Raven IAsyncDocumentSession for every request.
|
||||
.AddRavenDbIdentity<AppUser>(); // Let Raven store users and roles.
|
||||
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
}
|
||||
|
||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseAuthentication();
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseCookiePolicy();
|
||||
|
||||
// Create the database if it doesn't exist.
|
||||
app.ApplicationServices.GetRequiredService<IDocumentStore>().EnsureExists();
|
||||
|
||||
app.UseMvc(routes =>
|
||||
{
|
||||
routes.MapRoute(
|
||||
name: "default",
|
||||
template: "{controller=Home}/{action=Index}/{id?}");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">He's just a very naughty boy</h1>
|
||||
<p>Access denied! You tried to view a page you're not authorized to view.</p>
|
||||
@@ -0,0 +1,22 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h1>Change your roles</h1>
|
||||
<p>For testing purposes, you can change your role(s) here to see authorization in action.</p>
|
||||
|
||||
<form action="/account/changeroles" method="post">
|
||||
<div class="form-group">
|
||||
<label for="inputRole">Roles:</label>
|
||||
<select class="form-control" id="inputRole" name="Roles" multiple size="2">
|
||||
<option selected="@User.IsInRole(AppUser.ManagerRole)">@AppUser.ManagerRole</option>
|
||||
<option selected="@User.IsInRole(AppUser.AdminRole)">@AppUser.AdminRole</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">
|
||||
Use CTRL to select multiple
|
||||
</small>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
@{
|
||||
ViewData["Title"] = "Register";
|
||||
}
|
||||
|
||||
<h1>Register</h1>
|
||||
<p>(Already registered? Please <a href="/account/register">Sign in</a>.)</p>
|
||||
|
||||
<form action="/account/register" method="post">
|
||||
<div class="form-group">
|
||||
<label for="inputEmail">Email address</label>
|
||||
<input type="email" class="form-control" id="inputEmail" name="Email" aria-describedby="emailHelp" placeholder="you@foo.com">
|
||||
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputPassword">Password</label>
|
||||
<input type="password" class="form-control" id="inputPassword" name="Password" placeholder="Password">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Register</button>
|
||||
</form>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "RegisterFailure";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Uh oh, registration failed</h1>
|
||||
<p>
|
||||
Error details: @ViewBag.FailureReason
|
||||
</p>
|
||||
<p>
|
||||
Try again? <a href="/account/register">Register</a> or <a href="/account/signin">sign in</a>.
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
@{
|
||||
ViewData["Title"] = "Sign in";
|
||||
}
|
||||
|
||||
<h1>Hi! Please sign in. (Not registered? <a href="/account/register">Register here</a>.)</h1>
|
||||
|
||||
<form action="/account/signin" method="post">
|
||||
<div class="form-group">
|
||||
<label for="inputEmail">Email address</label>
|
||||
<input type="email" class="form-control" id="inputEmail" name="Email" placeholder="you@foo.com">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="inputPassword">Password</label>
|
||||
<input type="password" class="form-control" id="inputPassword" name="Password" placeholder="Password">
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Sign in</button>
|
||||
</form>
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "RegisterFailure";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Uh oh, sign in failed</h1>
|
||||
<p>
|
||||
Error details: @ViewBag.FailureReason
|
||||
</p>
|
||||
<p>
|
||||
Try again? <a href="/account/signin">Sign in</a> or <a href="/account/register">register</a>.
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<h1>Shhh! You're on an admin-only page 😎</h1>
|
||||
<p>If you can read this, you're an admin</p>
|
||||
@@ -0,0 +1,24 @@
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
|
||||
<h1 class="display-4">Welcome to MVC sample for Raven.Identity</h1>
|
||||
@if (User.Identity.IsAuthenticated)
|
||||
{
|
||||
<p>
|
||||
Hi, @User.Identity.Name. You're currently signed in, and your role is @ViewBag.UserRoles. 😎
|
||||
</p>
|
||||
<p>
|
||||
From here, you can <a href="/account/changeroles">change your role</a>, <a href="/home/adminonly">view an admin-only page</a>, or <a href="/account/signout">sign out</a>.
|
||||
</p>
|
||||
<p>
|
||||
Your user is saved in Raven. <a href="http://live-test.ravendb.net/studio/index.html#databases/documents?collection=AppUsers&database=Raven.Identity.Sample.Mvc">View it</a>.
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p>You're not signed in. Please <a href="/account/signin">Sign In</a> or <a href="/account/register">Register</a>.</p>
|
||||
}
|
||||
</div>
|
||||
@@ -0,0 +1,6 @@
|
||||
@{
|
||||
ViewData["Title"] = "Privacy Policy";
|
||||
}
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
<p>Use this page to detail your site's privacy policy.</p>
|
||||
@@ -0,0 +1,25 @@
|
||||
@model ErrorViewModel
|
||||
@{
|
||||
ViewData["Title"] = "Error";
|
||||
}
|
||||
|
||||
<h1 class="text-danger">Error.</h1>
|
||||
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||
|
||||
@if (Model.ShowRequestId)
|
||||
{
|
||||
<p>
|
||||
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||
</p>
|
||||
}
|
||||
|
||||
<h3>Development Mode</h3>
|
||||
<p>
|
||||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||
</p>
|
||||
<p>
|
||||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||
It can result in displaying sensitive information from exceptions to end users.
|
||||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||
and restarting the app.
|
||||
</p>
|
||||
@@ -0,0 +1,25 @@
|
||||
@using Microsoft.AspNetCore.Http.Features
|
||||
|
||||
@{
|
||||
var consentFeature = Context.Features.Get<ITrackingConsentFeature>();
|
||||
var showBanner = !consentFeature?.CanTrack ?? false;
|
||||
var cookieString = consentFeature?.CreateConsentCookie();
|
||||
}
|
||||
|
||||
@if (showBanner)
|
||||
{
|
||||
<div id="cookieConsent" class="alert alert-info alert-dismissible fade show" role="alert">
|
||||
Use this space to summarize your privacy and cookie use policy. <a asp-area="" asp-controller="Home" asp-action="Privacy">Learn More</a>.
|
||||
<button type="button" class="accept-policy close" data-dismiss="alert" aria-label="Close" data-cookie-string="@cookieString">
|
||||
<span aria-hidden="true">Accept</span>
|
||||
</button>
|
||||
</div>
|
||||
<script>
|
||||
(function () {
|
||||
var button = document.querySelector("#cookieConsent button[data-cookie-string]");
|
||||
button.addEventListener("click", function (event) {
|
||||
document.cookie = button.dataset.cookieString;
|
||||
}, false);
|
||||
})();
|
||||
</script>
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>@ViewData["Title"] - Sample.Mvc</title>
|
||||
|
||||
<environment include="Development">
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
|
||||
</environment>
|
||||
<environment exclude="Development">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css"
|
||||
asp-fallback-href="~/lib/bootstrap/dist/css/bootstrap.min.css"
|
||||
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha256-eSi1q2PG6J7g7ib17yAaWMcrr5GrtohYChqibrV7PBE="/>
|
||||
</environment>
|
||||
<link rel="stylesheet" href="~/css/site.css" />
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Sample.Mvc</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||
aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||
<ul class="navbar-nav flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
<div class="container">
|
||||
<partial name="_CookieConsentPartial" />
|
||||
<main role="main" class="pb-3">
|
||||
@RenderBody()
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2019 - Sample.Mvc - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<environment include="Development">
|
||||
<script src="~/lib/jquery/dist/jquery.js"></script>
|
||||
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.js"></script>
|
||||
</environment>
|
||||
<environment exclude="Development">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"
|
||||
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
|
||||
asp-fallback-test="window.jQuery"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=">
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.bundle.min.js"
|
||||
asp-fallback-src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"
|
||||
asp-fallback-test="window.jQuery && window.jQuery.fn && window.jQuery.fn.modal"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha256-E/V4cWE4qvAeO5MOhjtGtqDzPndRO1LBk8lJ/PR7CA4=">
|
||||
</script>
|
||||
</environment>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
||||
@RenderSection("Scripts", required: false)
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
<environment include="Development">
|
||||
<script src="~/lib/jquery-validation/dist/jquery.validate.js"></script>
|
||||
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js"></script>
|
||||
</environment>
|
||||
<environment exclude="Development">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js"
|
||||
asp-fallback-src="~/lib/jquery-validation/dist/jquery.validate.min.js"
|
||||
asp-fallback-test="window.jQuery && window.jQuery.validator"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha256-F6h55Qw6sweK+t7SiOJX+2bpSAa3b/fnlrVCJvmEj1A=">
|
||||
</script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"
|
||||
asp-fallback-src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"
|
||||
asp-fallback-test="window.jQuery && window.jQuery.validator && window.jQuery.validator.unobtrusive"
|
||||
crossorigin="anonymous"
|
||||
integrity="sha256-9GycpJnliUjJDVDqP0UEu/bsm9U+3dnQUH8+3W10vkY=">
|
||||
</script>
|
||||
</environment>
|
||||
@@ -0,0 +1,3 @@
|
||||
@using Sample.Mvc
|
||||
@using Sample.Mvc.Models
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -3,7 +3,7 @@
|
||||
"Urls": [
|
||||
"http://live-test.ravendb.net"
|
||||
],
|
||||
"DatabaseName": "Raven.Identity.Sample",
|
||||
"DatabaseName": "Raven.Identity.Sample.Mvc",
|
||||
"CertFilePath": "",
|
||||
"CertPassword": ""
|
||||
},
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,4 @@
|
||||
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
// for details on configuring this project to bundle and minify static web assets.
|
||||
|
||||
// Write your JavaScript code.
|
||||
Vendored
@@ -6,12 +6,12 @@
|
||||
@inject SignInManager<AppUser> SignInManager
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">RavenDB Identity Sample</h1>
|
||||
<h1 class="display-4">Welcome to Razor Pages sample for Raven.Identity</h1>
|
||||
@if (SignInManager.IsSignedIn(User))
|
||||
{
|
||||
<p>Hi, @User.Identity.Name. You're currently signed in. 😎</p>
|
||||
<p>
|
||||
Your user is saved in Raven. <a href="http://live-test.ravendb.net/studio/index.html#databases/documents?collection=AppUsers&database=Raven.Identity.Sample">View it</a>.
|
||||
Your user is saved in Raven. <a href="http://live-test.ravendb.net/studio/index.html#databases/documents?collection=AppUsers&database=Raven.Identity.Sample.RazorPages">View it</a>.
|
||||
</p>
|
||||
}
|
||||
else
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
@@ -3,23 +3,23 @@
|
||||
This is a Razor Pages sample that shows how to use Raven.Identity.
|
||||
|
||||
There are four areas of interest:
|
||||
1. [appsettings.json](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/appsettings.json) - where we configure our connection to Raven.
|
||||
2. [AppUser.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs) - our user class containing any user data like FirstName and LastName.
|
||||
3. [RavenSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs) - where we save changes to Raven after actions finish executing. This makes sense for a Razor Pages project. For an MVC or Web API project, use a RavenController base class instead.
|
||||
4. [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Startup.cs) - where we wire up everything.
|
||||
1. [appsettings.json](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/appsettings.json) - where we configure our connection to Raven.
|
||||
2. [AppUser.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Models/AppUser.cs) - our user class containing any user data like FirstName and LastName.
|
||||
3. [RavenSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Filters/RavenSaveChangesAsyncFilter.cs) - where we save changes to Raven after actions finish executing. This makes sense for a Razor Pages project. For an MVC or Web API project, use a RavenController base class instead.
|
||||
4. [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Startup.cs) - where we wire up everything.
|
||||
|
||||
More details below.
|
||||
|
||||
## 1. appsettings.json - connection to Raven
|
||||
|
||||
Our [appsettings.json file](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/appsettings.json) defines our connection to Raven. This is done using the [RavenDB.DependencyInjection](https://github.com/JudahGabriel/RavenDB.DependencyInjection/) package.
|
||||
Our [appsettings.json file](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/appsettings.json) defines our connection to Raven. This is done using the [RavenDB.DependencyInjection](https://github.com/JudahGabriel/RavenDB.DependencyInjection/) package.
|
||||
|
||||
```json
|
||||
"RavenSettings": {
|
||||
"Urls": [
|
||||
"http://live-test.ravendb.net"
|
||||
],
|
||||
"DatabaseName": "Raven.Identity.Sample",
|
||||
"DatabaseName": "Raven.Identity.Sample.RazorPages",
|
||||
"CertFilePath": "",
|
||||
"CertPassword": ""
|
||||
},
|
||||
@@ -27,7 +27,7 @@ Our [appsettings.json file](https://github.com/JudahGabriel/RavenDB.Identity/blo
|
||||
|
||||
## 2. AppUser.cs - user class
|
||||
|
||||
We create our own [AppUser class](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs) to hold user data:
|
||||
We create our own [AppUser class](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Models/AppUser.cs) to hold user data:
|
||||
|
||||
```csharp
|
||||
public class AppUser : Raven.Identity.IdentityUser
|
||||
@@ -45,7 +45,7 @@ While this step isn't strictly necessary -- it's possible to skip AppUser and ju
|
||||
|
||||
We need to `.SaveChangesAsync()` for anything to persist in Raven. Where should we do this?
|
||||
|
||||
While we could call `.SaveChangesAsync()` in the code-behind of every Razor page, that is tedious and error prone. Instead, we create a Razor action filter to save changes, [RaveSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs):
|
||||
While we could call `.SaveChangesAsync()` in the code-behind of every Razor page, that is tedious and error prone. Instead, we create a Razor action filter to save changes, [RaveSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Filters/RavenSaveChangesAsyncFilter.cs):
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
@@ -82,7 +82,7 @@ For MVC and Web API projects can use an action filter, or may alternately use a
|
||||
|
||||
## 4. Start.cs, wiring it all together
|
||||
|
||||
In [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Startup.cs), we wire up all of the above steps:
|
||||
In [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Samples/RazorPages/Startup.cs), we wire up all of the above steps:
|
||||
|
||||
```csharp
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
@@ -15,12 +15,12 @@
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RavenDB.Identity\RavenDB.Identity.csproj" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Services\" />
|
||||
<ProjectReference Include="..\..\RavenDB.Identity\RavenDB.Identity.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"RavenSettings": {
|
||||
"Urls": [
|
||||
"http://live-test.ravendb.net"
|
||||
],
|
||||
"DatabaseName": "Raven.Identity.Sample.RazorPages",
|
||||
"CertFilePath": "",
|
||||
"CertPassword": ""
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
for details on configuring this project to bundle and minify static web assets. */
|
||||
|
||||
a.navbar-brand {
|
||||
white-space: normal;
|
||||
text-align: center;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* Sticky footer styles
|
||||
-------------------------------------------------- */
|
||||
html {
|
||||
font-size: 14px;
|
||||
}
|
||||
@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.border-top {
|
||||
border-top: 1px solid #e5e5e5;
|
||||
}
|
||||
.border-bottom {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
}
|
||||
|
||||
.box-shadow {
|
||||
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
|
||||
}
|
||||
|
||||
button.accept-policy {
|
||||
font-size: 1rem;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
/* Sticky footer styles
|
||||
-------------------------------------------------- */
|
||||
html {
|
||||
position: relative;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
/* Margin bottom by footer height */
|
||||
margin-bottom: 60px;
|
||||
}
|
||||
.footer {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
width: 100%;
|
||||
white-space: nowrap;
|
||||
/* Set the fixed height of the footer here */
|
||||
height: 60px;
|
||||
line-height: 60px; /* Vertically center the text there */
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2011-2018 Twitter, Inc.
|
||||
Copyright (c) 2011-2018 The Bootstrap Authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,331 @@
|
||||
/*!
|
||||
* Bootstrap Reboot v4.1.3 (https://getbootstrap.com/)
|
||||
* Copyright 2011-2018 The Bootstrap Authors
|
||||
* Copyright 2011-2018 Twitter, Inc.
|
||||
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
||||
* Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md)
|
||||
*/
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-family: sans-serif;
|
||||
line-height: 1.15;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
-ms-text-size-adjust: 100%;
|
||||
-ms-overflow-style: scrollbar;
|
||||
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
@-ms-viewport {
|
||||
width: device-width;
|
||||
}
|
||||
|
||||
article, aside, figcaption, figure, footer, header, hgroup, main, nav, section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
|
||||
font-size: 1rem;
|
||||
font-weight: 400;
|
||||
line-height: 1.5;
|
||||
color: #212529;
|
||||
text-align: left;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
[tabindex="-1"]:focus {
|
||||
outline: 0 !important;
|
||||
}
|
||||
|
||||
hr {
|
||||
box-sizing: content-box;
|
||||
height: 0;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-top: 0;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
abbr[title],
|
||||
abbr[data-original-title] {
|
||||
text-decoration: underline;
|
||||
-webkit-text-decoration: underline dotted;
|
||||
text-decoration: underline dotted;
|
||||
cursor: help;
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
address {
|
||||
margin-bottom: 1rem;
|
||||
font-style: normal;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
ol,
|
||||
ul,
|
||||
dl {
|
||||
margin-top: 0;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
ol ol,
|
||||
ul ul,
|
||||
ol ul,
|
||||
ul ol {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin-bottom: .5rem;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
dfn {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
b,
|
||||
strong {
|
||||
font-weight: bolder;
|
||||
}
|
||||
|
||||
small {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
sub,
|
||||
sup {
|
||||
position: relative;
|
||||
font-size: 75%;
|
||||
line-height: 0;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
sub {
|
||||
bottom: -.25em;
|
||||
}
|
||||
|
||||
sup {
|
||||
top: -.5em;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
background-color: transparent;
|
||||
-webkit-text-decoration-skip: objects;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #0056b3;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:not([href]):not([tabindex]) {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:not([href]):not([tabindex]):hover, a:not([href]):not([tabindex]):focus {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:not([href]):not([tabindex]):focus {
|
||||
outline: 0;
|
||||
}
|
||||
|
||||
pre,
|
||||
code,
|
||||
kbd,
|
||||
samp {
|
||||
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
pre {
|
||||
margin-top: 0;
|
||||
margin-bottom: 1rem;
|
||||
overflow: auto;
|
||||
-ms-overflow-style: scrollbar;
|
||||
}
|
||||
|
||||
figure {
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
img {
|
||||
vertical-align: middle;
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
svg {
|
||||
overflow: hidden;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
caption {
|
||||
padding-top: 0.75rem;
|
||||
padding-bottom: 0.75rem;
|
||||
color: #6c757d;
|
||||
text-align: left;
|
||||
caption-side: bottom;
|
||||
}
|
||||
|
||||
th {
|
||||
text-align: inherit;
|
||||
}
|
||||
|
||||
label {
|
||||
display: inline-block;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
button:focus {
|
||||
outline: 1px dotted;
|
||||
outline: 5px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
input,
|
||||
button,
|
||||
select,
|
||||
optgroup,
|
||||
textarea {
|
||||
margin: 0;
|
||||
font-family: inherit;
|
||||
font-size: inherit;
|
||||
line-height: inherit;
|
||||
}
|
||||
|
||||
button,
|
||||
input {
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
button,
|
||||
select {
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
button,
|
||||
html [type="button"],
|
||||
[type="reset"],
|
||||
[type="submit"] {
|
||||
-webkit-appearance: button;
|
||||
}
|
||||
|
||||
button::-moz-focus-inner,
|
||||
[type="button"]::-moz-focus-inner,
|
||||
[type="reset"]::-moz-focus-inner,
|
||||
[type="submit"]::-moz-focus-inner {
|
||||
padding: 0;
|
||||
border-style: none;
|
||||
}
|
||||
|
||||
input[type="radio"],
|
||||
input[type="checkbox"] {
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
input[type="date"],
|
||||
input[type="time"],
|
||||
input[type="datetime-local"],
|
||||
input[type="month"] {
|
||||
-webkit-appearance: listbox;
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: auto;
|
||||
resize: vertical;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
legend {
|
||||
display: block;
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
padding: 0;
|
||||
margin-bottom: .5rem;
|
||||
font-size: 1.5rem;
|
||||
line-height: inherit;
|
||||
color: inherit;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
progress {
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
[type="number"]::-webkit-inner-spin-button,
|
||||
[type="number"]::-webkit-outer-spin-button {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
[type="search"] {
|
||||
outline-offset: -2px;
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
[type="search"]::-webkit-search-cancel-button,
|
||||
[type="search"]::-webkit-search-decoration {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
|
||||
::-webkit-file-upload-button {
|
||||
font: inherit;
|
||||
-webkit-appearance: button;
|
||||
}
|
||||
|
||||
output {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
summary {
|
||||
display: list-item;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
template {
|
||||
display: none;
|
||||
}
|
||||
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
/*# sourceMappingURL=bootstrap-reboot.css.map */
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user