Update the PostLogin method to write the auth ticket the way that webapi is supposed to, not sure how this was actually working before because writing cookies directly with HttpContext and then also using WebApi normally doesn't work (maybe in very specific circumstances), so now the cookie writing is done consistently and it is working, prior to this i was getting lots of issues with the xsrf tokens. Updated some user model mappings for convenience and update naming conventions for some properties of the BackOfficeIdentityUser for consistency.

This commit is contained in:
Shannon
2015-03-24 20:17:37 +11:00
parent fc2b3d7fc7
commit 90b562a0a1
11 changed files with 175 additions and 90 deletions

View File

@@ -5,6 +5,9 @@ using Umbraco.Core.Models.Mapping;
using Umbraco.Core.Models.Membership;
using Umbraco.Web.Models.ContentEditing;
using umbraco;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Identity;
using Umbraco.Core.Security;
namespace Umbraco.Web.Models.Mapping
{
@@ -17,7 +20,19 @@ namespace Umbraco.Web.Models.Mapping
.ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserType.Alias))
.ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId))
.ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId))
.ForMember(detail => detail.Culture, opt => opt.MapFrom(user => ui.Culture(user)))
.ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService)))
.ForMember(
detail => detail.EmailHash,
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()))
.ForMember(detail => detail.SecondsUntilTimeout, opt => opt.Ignore());
config.CreateMap<BackOfficeIdentityUser, UserDetail>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => user.Id))
.ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserTypeAlias))
.ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId))
.ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId))
.ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.Culture))
.ForMember(detail => detail.AllowedSections, opt => opt.MapFrom(user => user.AllowedSections))
.ForMember(
detail => detail.EmailHash,
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()))
@@ -25,6 +40,18 @@ namespace Umbraco.Web.Models.Mapping
config.CreateMap<IProfile, UserBasic>()
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
config.CreateMap<IUser, UserData>()
.ConstructUsing((IUser user) => new UserData(Guid.NewGuid().ToString("N"))) //this is the 'session id'
.ForMember(detail => detail.Id, opt => opt.MapFrom(user => user.Id))
.ForMember(detail => detail.AllowedApplications, opt => opt.MapFrom(user => user.AllowedSections))
.ForMember(detail => detail.RealName, opt => opt.MapFrom(user => user.Name))
.ForMember(detail => detail.Roles, opt => opt.MapFrom(user => new[] {user.UserType.Alias}))
.ForMember(detail => detail.StartContentNode, opt => opt.MapFrom(user => user.StartContentId))
.ForMember(detail => detail.StartMediaNode, opt => opt.MapFrom(user => user.StartMediaId))
.ForMember(detail => detail.Username, opt => opt.MapFrom(user => user.Username))
.ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService)));
}
private static int GetIntId(object id)