Skip to content
Browse files

- Cleaned up the Authentication. Now using the WorldDomination.Securi…

…ty package!
  • Loading branch information...
1 parent 51104b3 commit f32b755fdc9004cf182555c7743dfddf7d1fbcbd @PureKrome committed
Showing with 176 additions and 450 deletions.
  1. +1 −4 Code/RavenOverflow.Web/App_Start/StructuremapMvc.cs
  2. +4 −4 Code/RavenOverflow.Web/Areas/Question/Controllers/QuestionsController.cs
  3. +3 −3 Code/RavenOverflow.Web/Areas/Question/Models/QuestionViewModel.cs
  4. +0 −37 Code/RavenOverflow.Web/Areas/User/Controllers/UsersController.cs
  5. +0 −24 Code/RavenOverflow.Web/Areas/User/UserAreaRegistration.cs
  6. +0 −20 Code/RavenOverflow.Web/Areas/User/Views/Users/Authenticate.cshtml
  7. +0 −58 Code/RavenOverflow.Web/Areas/User/Views/Web.config
  8. +1 −1 Code/RavenOverflow.Web/AutoMapper/AutoMapperBootstrapper.cs
  9. BIN Code/RavenOverflow.Web/Content/LeahCulverAvatar.png
  10. +14 −6 Code/RavenOverflow.Web/Controllers/BaseController.cs
  11. +33 −5 Code/RavenOverflow.Web/Controllers/HomeController.cs
  12. +0 −17 Code/RavenOverflow.Web/Controllers/RavenDbController.cs
  13. +3 −11 Code/RavenOverflow.Web/DependencyResolution/AuthenticationRegistry.cs
  14. +1 −5 Code/RavenOverflow.Web/DependencyResolution/IoC.cs
  15. +2 −2 ...enOverflow.Web/DependencyResolution/{SmDependencyResolver.cs → StructureMapDependencyResolver.cs}
  16. +0 −7 Code/RavenOverflow.Web/Global.asax.cs
  17. +0 −65 Code/RavenOverflow.Web/Models/Authentication/CustomFormsAuthentication.cs
  18. +0 −19 Code/RavenOverflow.Web/Models/Authentication/CustomIdentity.cs
  19. +0 −15 Code/RavenOverflow.Web/Models/Authentication/CustomPrincipal.cs
  20. +0 −10 Code/RavenOverflow.Web/Models/Authentication/ICustomFormsAuthentication.cs
  21. +0 −9 Code/RavenOverflow.Web/Models/Authentication/ICustomIdentity.cs
  22. +0 −8 Code/RavenOverflow.Web/Models/Authentication/IOAuthAuthentication.cs
  23. +0 −19 Code/RavenOverflow.Web/Models/Authentication/OAuthAuthentication.cs
  24. +0 −42 Code/RavenOverflow.Web/Models/Authentication/UserData.cs
  25. +43 −0 Code/RavenOverflow.Web/Models/ClaimsUser.cs
  26. +16 −1 Code/RavenOverflow.Web/Models/ViewModels/AuthenticationViewModel.cs
  27. +1 −3 Code/RavenOverflow.Web/Models/ViewModels/IndexViewModel.cs
  28. +8 −9 Code/RavenOverflow.Web/Models/_LayoutViewModel.cs
  29. +5 −3 Code/RavenOverflow.Web/Models/_MainNavigationViewModel.cs
  30. +17 −27 Code/RavenOverflow.Web/RavenOverflow.Web.csproj
  31. +9 −7 Code/RavenOverflow.Web/Views/Shared/_Authentication.cshtml
  32. +3 −3 Code/RavenOverflow.Web/Views/Shared/_Layout.cshtml
  33. +1 −1 Code/RavenOverflow.Web/Views/Shared/_MainNavigation.cshtml
  34. +10 −3 Code/RavenOverflow.Web/Web.config
  35. +1 −2 Code/RavenOverflow.Web/packages.config
View
5 Code/RavenOverflow.Web/App_Start/StructuremapMvc.cs
@@ -13,10 +13,7 @@ public static class StructuremapMvc
public static void Start()
{
IContainer container = IoC.Initialize();
- DependencyResolver.SetResolver(new SmDependencyResolver(container));
-
-
- RouteDebug.PreApplicationStart.Start();
+ DependencyResolver.SetResolver(new StructureMapDependencyResolver(container));
}
}
}
View
8 Code/RavenOverflow.Web/Areas/Question/Controllers/QuestionsController.cs
@@ -9,7 +9,7 @@
namespace RavenOverflow.Web.Areas.Question.Controllers
{
- public class QuestionsController : RavenDbController
+ public class QuestionsController : BaseController
{
private readonly IQuestionService _questionService;
@@ -24,7 +24,7 @@ public QuestionsController(IDocumentSession documentSession, IQuestionService qu
[HttpGet]
public ActionResult Create()
{
- var inputModel = new QuestionViewModel(User.Identity)
+ var inputModel = new QuestionViewModel(ClaimsUser)
{
Header = "Ask a Question"
};
@@ -39,7 +39,7 @@ public ActionResult Create(QuestionInputModel inputModel)
if (ModelState.IsValid)
{
var question = Mapper.Map<QuestionInputModel, Core.Entities.Question>(inputModel);
- question.CreatedByUserId = User.Identity.UserId;
+ question.CreatedByUserId = ClaimsUser == null ? null : ClaimsUser.Id;
_questionService.Store(question);
@@ -53,7 +53,7 @@ public ActionResult Create(QuestionInputModel inputModel)
ModelState.AddModelError("RuRoh", exception.Message);
}
- var viewModel = new QuestionViewModel(User.Identity);
+ var viewModel = new QuestionViewModel(ClaimsUser);
Mapper.Map(inputModel, viewModel);
return View("Create", viewModel);
View
6 Code/RavenOverflow.Web/Areas/Question/Models/QuestionViewModel.cs
@@ -1,11 +1,11 @@
-using RavenOverflow.Web.Models;
-using RavenOverflow.Web.Models.Authentication;
+using System.Security.Principal;
+using RavenOverflow.Web.Models;
namespace RavenOverflow.Web.Areas.Question.Models
{
public class QuestionViewModel : _LayoutViewModel
{
- public QuestionViewModel(ICustomIdentity customIdentity) : base(customIdentity)
+ public QuestionViewModel(ClaimsUser claimsUser) : base(claimsUser)
{
}
View
37 Code/RavenOverflow.Web/Areas/User/Controllers/UsersController.cs
@@ -1,37 +0,0 @@
-using System.Web.Mvc;
-using CuttingEdge.Conditions;
-using Raven.Client;
-using RavenOverflow.Web.Controllers;
-using RavenOverflow.Web.Models.Authentication;
-
-namespace RavenOverflow.Web.Areas.User.Controllers
-{
- public class UsersController : RavenDbController
- {
- private readonly ICustomFormsAuthentication _customFormsAuthentication;
-
- public UsersController(IDocumentSession documentSession,
- ICustomFormsAuthentication customCustomFormsAuthentication)
- : base(documentSession)
- {
- Condition.Requires(customCustomFormsAuthentication).IsNotNull();
-
- _customFormsAuthentication = customCustomFormsAuthentication;
- }
-
- [HttpGet]
- public ActionResult Authenticate()
- {
- _customFormsAuthentication.SignIn("users/1", "Some Fake user", Response);
-
- return RedirectToAction("Index", "Home", new {area = ""});
- }
-
- [HttpGet]
- public ActionResult SignOut()
- {
- _customFormsAuthentication.SignOut();
- return RedirectToAction("Index", "Home", new {area = ""});
- }
- }
-}
View
24 Code/RavenOverflow.Web/Areas/User/UserAreaRegistration.cs
@@ -1,24 +0,0 @@
-using System.Web.Mvc;
-
-namespace RavenOverflow.Web.Areas.User
-{
- public class UserAreaRegistration : AreaRegistration
- {
- public override string AreaName
- {
- get
- {
- return "User";
- }
- }
-
- public override void RegisterArea(AreaRegistrationContext context)
- {
- context.MapRoute(
- "User_default",
- "Users/{action}",
- new { controller="users", action = "Index" }
- );
- }
- }
-}
View
20 Code/RavenOverflow.Web/Areas/User/Views/Users/Authenticate.cshtml
@@ -1,20 +0,0 @@
-@using RavenOverflow.Web.Models
-@model _LayoutViewModel
-@{
- Layout = "~/Views/Shared/_Layout.cshtml";
-}
-
-@section Header
-{
- @Model.Header
-}
-
-
-<div id="register-wrap">
- <p>Sign in using one of the providers below.</p>
- <div id="register-providers">
- <ul>
- <li>@Html.ActionLink("Facebook", "AuthenticateWithFacebook", "Users")</li>
- </ul>
- </div>
-</div>
View
58 Code/RavenOverflow.Web/Areas/User/Views/Web.config
@@ -1,58 +0,0 @@
-<?xml version="1.0"?>
-
-<configuration>
- <configSections>
- <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
- <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
- <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
- </sectionGroup>
- </configSections>
-
- <system.web.webPages.razor>
- <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
- <pages pageBaseType="System.Web.Mvc.WebViewPage">
- <namespaces>
- <add namespace="System.Web.Mvc" />
- <add namespace="System.Web.Mvc.Ajax" />
- <add namespace="System.Web.Mvc.Html" />
- <add namespace="System.Web.Routing" />
- </namespaces>
- </pages>
- </system.web.webPages.razor>
-
- <appSettings>
- <add key="webpages:Enabled" value="false" />
- </appSettings>
-
- <system.web>
- <httpHandlers>
- <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
- </httpHandlers>
-
- <!--
- Enabling request validation in view pages would cause validation to occur
- after the input has already been processed by the controller. By default
- MVC performs request validation before a controller processes the input.
- To change this behavior apply the ValidateInputAttribute to a
- controller or action.
- -->
- <pages
- validateRequest="false"
- pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
- pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
- userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
- <controls>
- <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
- </controls>
- </pages>
- </system.web>
-
- <system.webServer>
- <validation validateIntegratedModeConfiguration="false" />
-
- <handlers>
- <remove name="BlockViewHandler"/>
- <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
- </handlers>
- </system.webServer>
-</configuration>
View
2 Code/RavenOverflow.Web/AutoMapper/AutoMapperBootstrapper.cs
@@ -19,7 +19,7 @@ public static void ConfigureMappings()
.ForMember(dest => dest.Comments, opt => opt.Ignore());
Mapper.CreateMap<QuestionInputModel, QuestionViewModel>()
- .ForMember(dest => dest.CustomIdentity, opt => opt.Ignore())
+ .ForMember(dest => dest.AuthenticationViewModel, opt => opt.Ignore())
.ForMember(dest => dest.Header, opt => opt.Ignore());
}
}
View
BIN Code/RavenOverflow.Web/Content/LeahCulverAvatar.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
20 Code/RavenOverflow.Web/Controllers/BaseController.cs
@@ -1,16 +1,24 @@
using System.Web.Mvc;
-using RavenOverflow.Web.Models.Authentication;
+using CuttingEdge.Conditions;
+using Raven.Client;
+using RavenOverflow.Web.Models;
namespace RavenOverflow.Web.Controllers
{
public abstract class BaseController : Controller
{
- /// <summary>
- /// Override the custom User property with our own -custom- Principal/Identity implimentation.
- /// </summary>
- public new virtual CustomPrincipal User
+ protected BaseController(IDocumentSession documentSession)
{
- get { return base.User as CustomPrincipal; }
+ Condition.Requires(documentSession).IsNotNull();
+
+ DocumentSession = documentSession;
+ }
+
+ protected IDocumentSession DocumentSession { get; private set; }
+
+ protected ClaimsUser ClaimsUser
+ {
+ get { return User == null ? null : new ClaimsUser(User); }
}
}
}
View
38 Code/RavenOverflow.Web/Controllers/HomeController.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
+using CuttingEdge.Conditions;
using Raven.Abstractions.Data;
using Raven.Client;
using Raven.Client.Linq;
@@ -10,13 +11,40 @@
using RavenOverflow.Core.Filters;
using RavenOverflow.Web.Models.ViewModels;
using RavenOverflow.Web.RavenDb.Indexes;
+using WorldDomination.Security;
namespace RavenOverflow.Web.Controllers
{
- public class HomeController : RavenDbController
+ public class HomeController : BaseController
{
- public HomeController(IDocumentSession documentSession) : base(documentSession)
+ private readonly ICustomFormsAuthentication _customFormsAuthentication;
+
+ public HomeController(IDocumentSession documentSession, ICustomFormsAuthentication customCustomFormsAuthentication) : base(documentSession)
+ {
+ Condition.Requires(customCustomFormsAuthentication).IsNotNull();
+
+ _customFormsAuthentication = customCustomFormsAuthentication;
+ }
+
+ [HttpGet]
+ public ActionResult Authenticate()
+ {
+ var userData = new UserData
+ {
+ UserId = "users/1",
+ DisplayName = "Leah Culver",
+ PictureUri = "/Content/LeahCulverAvatar.png"
+ };
+ _customFormsAuthentication.SignIn(userData);
+
+ return RedirectToAction("Index", "Home", new { area = "" });
+ }
+
+ [HttpGet]
+ public ActionResult SignOut()
{
+ _customFormsAuthentication.SignOut();
+ return RedirectToAction("Index", "Home", new { area = "" });
}
[HttpGet]
@@ -34,7 +62,7 @@ public ActionResult Index(string displayName, string tag)
// 3. Log in user information.
IQueryable<User> userQuery = UserQuery(displayName);
- var viewModel = new IndexViewModel(User.Identity)
+ var viewModel = new IndexViewModel(ClaimsUser)
{
Header = header,
QuestionListViewModel = new QuestionListViewModel
@@ -80,7 +108,7 @@ public ActionResult BatchedIndex(string displayName, string tag)
IQueryable<User> userQuery = UserQuery(displayName);
Lazy<IEnumerable<User>> lazyUserQuery = (userQuery != null ? userQuery.Lazily() : null);
- var viewModel = new IndexViewModel(User.Identity)
+ var viewModel = new IndexViewModel(ClaimsUser)
{
Header = header,
QuestionListViewModel = new QuestionListViewModel
@@ -129,7 +157,7 @@ public ActionResult AggressiveIndex(string displayName, string tag)
IQueryable<User> userQuery = UserQuery(displayName);
Lazy<IEnumerable<User>> lazyUserQuery = (userQuery != null ? userQuery.Lazily() : null);
- var viewModel = new IndexViewModel(User.Identity)
+ var viewModel = new IndexViewModel(ClaimsUser)
{
Header = header,
QuestionListViewModel = new QuestionListViewModel
View
17 Code/RavenOverflow.Web/Controllers/RavenDbController.cs
@@ -1,17 +0,0 @@
-using CuttingEdge.Conditions;
-using Raven.Client;
-
-namespace RavenOverflow.Web.Controllers
-{
- public abstract class RavenDbController : BaseController
- {
- protected RavenDbController(IDocumentSession documentSession)
- {
- Condition.Requires(documentSession).IsNotNull();
-
- DocumentSession = documentSession;
- }
-
- public IDocumentSession DocumentSession { get; private set; }
- }
-}
View
14 Code/RavenOverflow.Web/DependencyResolution/AuthenticationRegistry.cs
@@ -1,22 +1,14 @@
-using CuttingEdge.Conditions;
-using RavenOverflow.Web.Models.Authentication;
-using StructureMap.Configuration.DSL;
+using StructureMap.Configuration.DSL;
+using WorldDomination.Security;
namespace RavenOverflow.Web.DependencyResolution
{
public class AuthenticationRegistry : Registry
{
- public AuthenticationRegistry(string facebookId, string facebookSecret)
+ public AuthenticationRegistry()
{
- Condition.Requires(facebookId).IsNotNullOrEmpty();
- Condition.Requires(facebookSecret).IsNotNullOrEmpty();
-
For<ICustomFormsAuthentication>().Use<CustomFormsAuthentication>()
.Named("Custom Forms Authentication instance.");
- For<IOAuthAuthentication>().Use<OAuthAuthentication>()
- .Ctor<string>("facebookAppId").Is(facebookId)
- .Ctor<string>("facebookSecret").Is(facebookSecret)
- .Named("OAuth Authentication instance.");
}
}
}
View
6 Code/RavenOverflow.Web/DependencyResolution/IoC.cs
@@ -11,11 +11,7 @@ public static IContainer Initialize()
{
x.AddRegistry(
new RavenDbRegistry(ConfigurationManager.ConnectionStrings[0].Name));
- x.AddRegistry(
- new AuthenticationRegistry(
- ConfigurationManager.AppSettings["FacebookAppId"],
- ConfigurationManager.AppSettings["FacebookSecret"]
- ));
+ x.AddRegistry(new AuthenticationRegistry());
x.AddRegistry(new ServiceRegistry());
});
return ObjectFactory.Container;
View
4 ...endencyResolution/SmDependencyResolver.cs → ...olution/StructureMapDependencyResolver.cs
@@ -6,11 +6,11 @@
namespace RavenOverflow.Web.DependencyResolution
{
- public class SmDependencyResolver : IDependencyResolver
+ public class StructureMapDependencyResolver : IDependencyResolver
{
private readonly IContainer _container;
- public SmDependencyResolver(IContainer container)
+ public StructureMapDependencyResolver(IContainer container)
{
_container = container;
}
View
7 Code/RavenOverflow.Web/Global.asax.cs
@@ -2,7 +2,6 @@
using System.Web.Mvc;
using System.Web.Routing;
using RavenOverflow.Web.AutoMapper;
-using RavenOverflow.Web.Models.Authentication;
namespace RavenOverflow.Web
{
@@ -46,12 +45,6 @@ protected void Application_Start()
// Configure AutoMapper mappings.
AutoMapperBootstrapper.ConfigureMappings();
}
-
- protected void Application_AuthenticateRequest()
-
- {
- CustomFormsAuthentication.AuthenticateRequestDecryptCustomFormsAuthenticationTicket(Context);
- }
}
// ReSharper restore InconsistentNaming
View
65 Code/RavenOverflow.Web/Models/Authentication/CustomFormsAuthentication.cs
@@ -1,65 +0,0 @@
-using System;
-using System.Threading;
-using System.Web;
-using System.Web.Security;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public class CustomFormsAuthentication : ICustomFormsAuthentication
- {
- #region IFormsAuthenticationService Members
-
- public void SignIn(string id, string displayName, HttpResponseBase httpResponseBase)
- {
- var userData = new UserData
- {
- Id = id,
- DisplayName = displayName
- };
-
- string encodedTicket =
- FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, displayName, DateTime.UtcNow,
- DateTime.UtcNow.Add(
- FormsAuthentication.Timeout),
- true,
- userData.ToString()));
- var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encodedTicket);
- httpResponseBase.Cookies.Add(httpCookie);
- }
-
- public void SignOut()
- {
- FormsAuthentication.SignOut();
- }
-
- #endregion
-
- public static void AuthenticateRequestDecryptCustomFormsAuthenticationTicket(HttpContext httpContext)
- {
- UserData userData;
-
- string formsCookieName = FormsAuthentication.FormsCookieName;
- HttpCookie httpCookie =
- httpContext.Request.Cookies[
- string.IsNullOrWhiteSpace(formsCookieName) ? Guid.NewGuid().ToString() : formsCookieName];
- if (httpCookie == null)
- {
- userData = new UserData();
- }
- else
- {
- FormsAuthenticationTicket authenticationTicket = FormsAuthentication.Decrypt(httpCookie.Value);
-
- if (!UserData.TryParse(authenticationTicket.UserData, out userData))
- {
- // No name will mean the Idenity has no name .. which means the user is NOT authenticated. Nice.
- userData = new UserData();
- }
- }
-
- var principal = new CustomPrincipal(new CustomIdentity(userData.Id, userData.DisplayName), null);
- httpContext.User = principal;
- Thread.CurrentPrincipal = principal;
- }
- }
-}
View
19 Code/RavenOverflow.Web/Models/Authentication/CustomIdentity.cs
@@ -1,19 +0,0 @@
-using System.Security.Principal;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public class CustomIdentity : GenericIdentity, ICustomIdentity
- {
- public CustomIdentity(string userId, string displayName)
- : base(string.IsNullOrEmpty(displayName) ? string.Empty : displayName, "Forms")
- {
- UserId = userId;
- }
-
- #region Implementation of CustomIdentity
-
- public string UserId { get; private set; }
-
- #endregion
- }
-}
View
15 Code/RavenOverflow.Web/Models/Authentication/CustomPrincipal.cs
@@ -1,15 +0,0 @@
-using System.Security.Principal;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public class CustomPrincipal : GenericPrincipal
- {
- public CustomPrincipal(ICustomIdentity identity, string[] roles)
- : base(identity, roles)
- {
- Identity = identity;
- }
-
- public new virtual ICustomIdentity Identity { get; private set; }
- }
-}
View
10 Code/RavenOverflow.Web/Models/Authentication/ICustomFormsAuthentication.cs
@@ -1,10 +0,0 @@
-using System.Web;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public interface ICustomFormsAuthentication
- {
- void SignIn(string id, string displayName, HttpResponseBase httpResponseBase);
- void SignOut();
- }
-}
View
9 Code/RavenOverflow.Web/Models/Authentication/ICustomIdentity.cs
@@ -1,9 +0,0 @@
-using System.Security.Principal;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public interface ICustomIdentity : IIdentity
- {
- string UserId { get; }
- }
-}
View
8 Code/RavenOverflow.Web/Models/Authentication/IOAuthAuthentication.cs
@@ -1,8 +0,0 @@
-namespace RavenOverflow.Web.Models.Authentication
-{
- public interface IOAuthAuthentication
- {
- string FacebookAppId { get; }
- string FacebookSecret { get; }
- }
-}
View
19 Code/RavenOverflow.Web/Models/Authentication/OAuthAuthentication.cs
@@ -1,19 +0,0 @@
-namespace RavenOverflow.Web.Models.Authentication
-{
- public class OAuthAuthentication : IOAuthAuthentication
- {
- public OAuthAuthentication(string facebookAppId, string facebookSecret)
- {
- FacebookAppId = facebookAppId;
- FacebookSecret = facebookSecret;
- }
-
- #region Implementation of IOAuthAuthentication
-
- public string FacebookAppId { get; private set; }
-
- public string FacebookSecret { get; private set; }
-
- #endregion
- }
-}
View
42 Code/RavenOverflow.Web/Models/Authentication/UserData.cs
@@ -1,42 +0,0 @@
-using System;
-
-namespace RavenOverflow.Web.Models.Authentication
-{
- public class UserData
- {
- private const char Delimeter = ',';
-
- public string Id { get; set; }
- public string DisplayName { get; set; }
-
- public override string ToString()
- {
- return string.Format("{1}{0}{2}", Delimeter, Id, string.IsNullOrEmpty(DisplayName) ? "-" : DisplayName);
- }
-
- public static bool TryParse(string data, out UserData userData)
- {
- if (string.IsNullOrWhiteSpace("data"))
- {
- throw new ArgumentNullException("data");
- }
-
- userData = null;
-
- // Split the text into segments.
- string[] segments = data.Split(new[] { Delimeter }, StringSplitOptions.RemoveEmptyEntries);
- if (segments.Length != 2)
- {
- return false;
- }
-
- userData = new UserData
- {
- Id = segments[0],
- DisplayName = segments[1]
- };
-
- return true;
- }
- }
-}
View
43 Code/RavenOverflow.Web/Models/ClaimsUser.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Security.Claims;
+using System.Security.Principal;
+using CuttingEdge.Conditions;
+using WorldDomination.Security;
+
+namespace RavenOverflow.Web.Models
+{
+ public class ClaimsUser
+ {
+ public ClaimsUser(IPrincipal principal)
+ {
+ Condition.Requires(principal).IsNotNull();
+
+ var claimsPrincipal = principal as ClaimsPrincipal;
+ Condition
+ .WithExceptionOnFailure<ArgumentException>()
+ .Requires(claimsPrincipal).IsNotNull("A principal argument was provided, but it needs to be a 'ClaimsPrincipal'.");
+
+ IsAuthenticated = claimsPrincipal.Identity.IsAuthenticated;
+
+ if (claimsPrincipal.HasClaim(x => x.Type == ClaimTypes.Uri))
+ {
+ Id = claimsPrincipal.FindFirst(x => x.Type == ClaimTypes.Uri).Value;
+ }
+
+ if (claimsPrincipal.HasClaim(x => x.Type == ClaimTypes.Name))
+ {
+ Name = claimsPrincipal.FindFirst(x => x.Type == ClaimTypes.Name).Value;
+ }
+
+ if (claimsPrincipal.HasClaim(x => x.Type == CustomClaimsTypes.PictureUri))
+ {
+ PictureUri = claimsPrincipal.FindFirst(x => x.Type == CustomClaimsTypes.PictureUri).Value;
+ }
+ }
+
+ public bool IsAuthenticated { get; private set; }
+ public string Id { get; private set; }
+ public string Name { get; private set; }
+ public string PictureUri { get; private set; }
+ }
+}
View
17 Code/RavenOverflow.Web/Models/ViewModels/AuthenticationViewModel.cs
@@ -2,6 +2,21 @@
{
public class AuthenticationViewModel
{
- public string DisplayName { get; set; }
+ public AuthenticationViewModel(ClaimsUser claimsUser)
+ {
+ if (claimsUser == null)
+ {
+ IsAuthenticated = false;
+ return;
+ }
+
+ IsAuthenticated = claimsUser.IsAuthenticated;
+ Name = claimsUser.Name;
+ PictureUri = claimsUser.PictureUri;
+ }
+
+ public bool IsAuthenticated { get; private set; }
+ public string Name { get; private set; }
+ public string PictureUri { get; private set; }
}
}
View
4 Code/RavenOverflow.Web/Models/ViewModels/IndexViewModel.cs
@@ -1,16 +1,14 @@
using System.Collections.Generic;
-using RavenOverflow.Web.Models.Authentication;
namespace RavenOverflow.Web.Models.ViewModels
{
public class IndexViewModel : _LayoutViewModel
{
- public IndexViewModel(ICustomIdentity customIdentity) : base(customIdentity)
+ public IndexViewModel(ClaimsUser claimsUser) : base(claimsUser)
{
}
public QuestionListViewModel QuestionListViewModel { get; set; }
- public AuthenticationViewModel AuthenticationViewModel { get; set; }
public IDictionary<string, short> RecentPopularTags { get; set; }
public UserTagListViewModel UserFavoriteTagListViewModel { get; set; }
public UserTagListViewModel UserIgnoredTagList { get; set; }
View
17 Code/RavenOverflow.Web/Models/_LayoutViewModel.cs
@@ -1,22 +1,21 @@
-using RavenOverflow.Web.Models.Authentication;
+using RavenOverflow.Web.Models.ViewModels;
namespace RavenOverflow.Web.Models
{
// ReSharper disable InconsistentNaming
-
+
public class _LayoutViewModel
{
- public _LayoutViewModel(ICustomIdentity customIdentity)
+ public _LayoutViewModel(ClaimsUser claimsUser)
{
- CustomIdentity = customIdentity;
+ if (claimsUser != null)
+ {
+ AuthenticationViewModel = new AuthenticationViewModel(claimsUser);
+ }
}
- #region Implementation of _ILayoutViewModel
-
- public ICustomIdentity CustomIdentity { get; private set; }
+ public AuthenticationViewModel AuthenticationViewModel { get; private set; }
public string Header { get; set; }
-
- #endregion
}
// ReSharper restore InconsistentNaming
View
8 Code/RavenOverflow.Web/Models/_MainNavigationViewModel.cs
@@ -1,11 +1,13 @@
-using RavenOverflow.Web.Models.Authentication;
+using RavenOverflow.Web.Models.ViewModels;
namespace RavenOverflow.Web.Models
{
// ReSharper disable InconsistentNaming
+
public class _MainNavigationViewModel
- // ReSharper restore InconsistentNaming
{
- public ICustomIdentity CustomIdentity { get; set; }
+ public AuthenticationViewModel AuthenticationViewModel { get; set; }
}
+
+ // ReSharper restore InconsistentNaming
}
View
44 Code/RavenOverflow.Web/RavenOverflow.Web.csproj
@@ -13,7 +13,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RavenOverflow.Web</RootNamespace>
<AssemblyName>RavenOverflow.Web</AssemblyName>
- <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<MvcBuildViews>false</MvcBuildViews>
<UseIISExpress>true</UseIISExpress>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\..\RavenOverflow\</SolutionDir>
@@ -27,6 +27,7 @@
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
+ <TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -36,6 +37,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -44,6 +46,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
+ <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=2.2.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
@@ -68,29 +71,33 @@
<Reference Include="RestSharp">
<HintPath>..\..\packages\RestSharp.104.1\lib\net4\RestSharp.dll</HintPath>
</Reference>
- <Reference Include="RouteDebugger, Version=2.1.4.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\routedebugger.2.1.4.0\lib\net40\RouteDebugger.dll</HintPath>
- </Reference>
<Reference Include="StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\structuremap.2.6.4.1\lib\net40\StructureMap.dll</HintPath>
</Reference>
<Reference Include="System.ComponentModel.Composition" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Web.ApplicationServices" />
+ <Reference Include="System.Web.DynamicData" />
+ <Reference Include="System.Web.Entity" />
+ <Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
- <Reference Include="System.Core" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Abstractions" />
<Reference Include="System.Web.Routing" />
<Reference Include="System.Configuration" />
+ <Reference Include="System.Xml.Linq" />
<Reference Include="WebActivator, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\WebActivator.1.5\lib\net40\WebActivator.dll</HintPath>
</Reference>
+ <Reference Include="WorldDomination.Security">
+ <HintPath>..\..\packages\WorldDomination.Security.0.4.0\lib\net45\WorldDomination.Security.dll</HintPath>
+ </Reference>
<Reference Include="WorldDomination.Web.Authentication">
<HintPath>..\..\packages\WorldDomination.Web.Authentication.0.16.0\lib\net40\WorldDomination.Web.Authentication.dll</HintPath>
</Reference>
@@ -105,18 +112,14 @@
<Compile Include="Areas\Question\Models\QuestionViewModel.cs" />
<Compile Include="Areas\Question\Models\QuestionInputModel.cs" />
<Compile Include="Areas\Question\QuestionAreaRegistration.cs" />
- <Compile Include="Areas\User\Controllers\UsersController.cs" />
- <Compile Include="Areas\User\UserAreaRegistration.cs" />
<Compile Include="AutoMapper\TagsResolver.cs" />
- <Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\ErrorController.cs" />
<Compile Include="DependencyResolution\IoC.cs" />
+ <Compile Include="Models\ClaimsUser.cs" />
<Compile Include="RavenDb\HelperUtilities.cs" />
<Compile Include="RavenDb\Indexes\Questions_Search.cs" />
<Compile Include="DependencyResolution\AuthenticationRegistry.cs" />
<Compile Include="RavenDb\Indexes\RavenFacetTags.cs" />
- <Compile Include="Models\Authentication\IOAuthAuthentication.cs" />
- <Compile Include="Models\Authentication\OAuthAuthentication.cs" />
<Compile Include="AutoMapper\AutoMapperBootstrapper.cs" />
<Compile Include="DependencyResolution\ServiceRegistry.cs" />
<Compile Include="RavenDb\DocumentStoreExtensions.cs" />
@@ -125,21 +128,15 @@
<Compile Include="Models\ViewModels\TagListViewModel.cs" />
<Compile Include="Models\ViewModels\UserTagListViewModel.cs" />
<Compile Include="Models\_LayoutViewModel.cs" />
- <Compile Include="Controllers\RavenDbController.cs" />
+ <Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="DependencyResolution\RavenDbRegistry.cs" />
- <Compile Include="DependencyResolution\SmDependencyResolver.cs" />
+ <Compile Include="DependencyResolution\StructureMapDependencyResolver.cs" />
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="RavenDb\Indexes\RecentPopularTagsMapOnly.cs" />
<Compile Include="RavenDb\Indexes\RecentPopularTags.cs" />
- <Compile Include="Models\Authentication\CustomFormsAuthentication.cs" />
- <Compile Include="Models\Authentication\CustomIdentity.cs" />
- <Compile Include="Models\Authentication\CustomPrincipal.cs" />
- <Compile Include="Models\Authentication\ICustomFormsAuthentication.cs" />
- <Compile Include="Models\Authentication\ICustomIdentity.cs" />
- <Compile Include="Models\Authentication\UserData.cs" />
<Compile Include="Models\HtmlExtensions.cs" />
<Compile Include="Models\_MainNavigationViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -148,6 +145,7 @@
<ItemGroup>
<Content Include="Content\Images\Error\NotFound.jpg" />
<Content Include="Content\Images\Error\ServerError.jpg" />
+ <Content Include="Content\LeahCulverAvatar.png" />
<Content Include="Content\logo-ravendb.png" />
<Content Include="Global.asax" />
<Content Include="Content\Site.css" />
@@ -165,8 +163,6 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Question\Views\Shared\" />
- <Folder Include="Areas\User\Models\" />
- <Folder Include="Areas\User\Views\Shared\" />
<Folder Include="Scripts\" />
</ItemGroup>
<ItemGroup>
@@ -208,12 +204,6 @@
<Content Include="Views\Shared\_TagSearch.cshtml" />
</ItemGroup>
<ItemGroup>
- <Content Include="Areas\User\Views\Web.config" />
- </ItemGroup>
- <ItemGroup>
- <Content Include="Areas\User\Views\Users\Authenticate.cshtml" />
- </ItemGroup>
- <ItemGroup>
<Content Include="Views\Shared\_TagListVertical.cshtml" />
</ItemGroup>
<ItemGroup>
View
16 Code/RavenOverflow.Web/Views/Shared/_Authentication.cshtml
@@ -1,19 +1,21 @@
-@using RavenOverflow.Web.Models.Authentication
-@model ICustomIdentity
+@model RavenOverflow.Web.Models.ViewModels.AuthenticationViewModel
<span id="hlinks-user">
- @if (Model != null && !string.IsNullOrEmpty(Model.Name))
+ @if (Model != null && Model.IsAuthenticated)
{
- @:Welcome <strong>@Model.Name</strong>!
+ @:Welcome <strong>@Model.Name</strong>!
+ if (!string.IsNullOrEmpty(Model.PictureUri))
+ {
+ <img src="@Model.PictureUri" alt="@Model.Name" height="24" width="24"/>
+ }
<ul>
<li>Settings</li>
- <li>@Html.ActionLink("LogOff", "SignOut", "Users", new { Area = "User"}, null)</li>
+ <li>@Html.ActionLink("LogOff", "SignOut", "Home", new { Area = ""}, null)</li>
</ul>
}
else
{
<ul>
- <li>@Html.ActionLink("Register", "Authenticate", "Users", new { Area = "User"}, null)</li>
- <li>@Html.ActionLink("Log On", "Authenticate", "Users", new {Area = "User", returnUrl = HttpContext.Current.Request.RawUrl}, null)</li>
+ <li>@Html.ActionLink("Log On", "Authenticate", "Home", new {Area = "", returnUrl = HttpContext.Current.Request.RawUrl}, null)</li>
</ul>
}
</span>
View
6 Code/RavenOverflow.Web/Views/Shared/_Layout.cshtml
@@ -7,7 +7,7 @@
<link rel="shortcut icon" href="http://cdn.sstatic.net/stackoverflow/img/favicon.ico">
<link rel="apple-touch-icon" href="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
- <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
+ <link href="@Url.Content("/Content/Site.css")" rel="stylesheet" type="text/css" />
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/cupertino/jquery-ui.css" type="text/css" rel="Stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
@@ -20,7 +20,7 @@
<noscript><div id="noscript-padding"></div></noscript>
- @Html.Partial("_MainNavigation", new _MainNavigationViewModel { CustomIdentity = Model.CustomIdentity })
+ @Html.Partial("_MainNavigation", new _MainNavigationViewModel { AuthenticationViewModel = Model.AuthenticationViewModel})
<div id="notify-container"></div>
<div id="overlay-header"></div>
@@ -29,7 +29,7 @@
<div id="header">
<div id="hlinks">
- @Html.Partial("_Authentication", Model.CustomIdentity)
+ @Html.Partial("_Authentication", Model.AuthenticationViewModel)
</div>
<div id="hsearch">
@Html.Partial("_TagSearch")
View
2 Code/RavenOverflow.Web/Views/Shared/_MainNavigation.cshtml
@@ -2,7 +2,7 @@
@model _MainNavigationViewModel
<div id="topbar">
@{
- int number = Model.CustomIdentity != null && Model.CustomIdentity.IsAuthenticated ? 3 : 2;
+ int number = Model.AuthenticationViewModel != null && Model.AuthenticationViewModel.IsAuthenticated ? 3 : 2;
}
<h3>@Html.ActionLink("Index - " + number + " DB roundtrips", "Index", "Home", new {Area = ""}, new {}) ||
@Html.ActionLink("BatchedIndex - 1 DB roundtrip", "BatchedIndex", "Home", new {Area = ""}, new {}) ||
View
13 Code/RavenOverflow.Web/Web.config
@@ -17,11 +17,18 @@
<add key="FacebookSecret" value="4727898cbaaba07eed0a1ca60f1e74b3" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
- <add key="RouteDebugger:Enabled" value="true" />
</appSettings>
<!-- Unused .. i think the Facebook library uses this .. which i'm not leveraging. -->
+ <!--
+ For a description of web.config changes for .NET 4.5 see http://go.microsoft.com/fwlink/?LinkId=235367.
+
+ The following attributes can be set on the <httpRuntime> tag.
+ <system.Web>
+ <httpRuntime targetFramework="4.5" />
+ </system.Web>
+ -->
<system.web>
- <compilation debug="true" targetFramework="4.0">
+ <compilation debug="true" targetFramework="4.5">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
@@ -33,7 +40,7 @@
<authentication mode="Forms">
<forms loginUrl="~/Users/Authenticate" timeout="2880" />
</authentication>
- <pages>
+ <pages controlRenderingCompatibilityVersion="4.0">
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
View
3 Code/RavenOverflow.Web/packages.config
@@ -7,11 +7,10 @@
<package id="RavenDB.Client" version="2.0.2261" targetFramework="net40" />
<package id="RavenDB.Client.MvcIntegration" version="2.0.2261" targetFramework="net40" />
<package id="RestSharp" version="104.1" targetFramework="net40" />
- <package id="routedebugger" version="2.1.4.0" targetFramework="net40" />
<package id="structuremap" version="2.6.4.1" targetFramework="net40" />
<package id="StructureMap.MVC3" version="1.0.8" />
<package id="WebActivator" version="1.5" />
- <package id="WorldDomination.Security" version="0.4.0" targetFramework="net40" />
+ <package id="WorldDomination.Security" version="0.4.0" targetFramework="net45" />
<package id="WorldDomination.Web.Authentication" version="0.16.0" targetFramework="net40" />
<package id="WorldDomination.Web.Authentication.Mvc" version="0.16.0" targetFramework="net40" />
</packages>

0 comments on commit f32b755

Please sign in to comment.
Something went wrong with that request. Please try again.