From 41ced12e3b43ce74d022cc075f645f23cb6b94ec Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 17 Apr 2017 09:21:15 -0400 Subject: [PATCH] fix user provider --- Project-Unite/App_Start/Startup.Auth.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Project-Unite/App_Start/Startup.Auth.cs b/Project-Unite/App_Start/Startup.Auth.cs index 6852f3e..4b6951d 100644 --- a/Project-Unite/App_Start/Startup.Auth.cs +++ b/Project-Unite/App_Start/Startup.Auth.cs @@ -1,6 +1,8 @@ using System; +using System.Linq; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.Owin; +using Microsoft.AspNet.SignalR; using Microsoft.Owin; using Microsoft.Owin.Security.Cookies; using Microsoft.Owin.Security.Google; @@ -14,6 +16,10 @@ public partial class Startup // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { + var idProvider = new UniteUserIdProvider(); + + GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => idProvider); + app.MapSignalR(); @@ -70,4 +76,13 @@ public void ConfigureAuth(IAppBuilder app) } } + + public class UniteUserIdProvider : IUserIdProvider + { + public string GetUserId(IRequest request) + { + var db = new ApplicationDbContext(); + return db.Users.FirstOrDefault(x => x.UserName == request.User.Identity.Name).Id; + } + } } \ No newline at end of file