2013-08-12 15:06:12 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using AutoMapper;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models.Mapping;
|
|
|
|
|
|
using Umbraco.Core.Models.Membership;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
2013-11-15 12:26:29 +11:00
|
|
|
|
using umbraco;
|
2015-03-24 20:17:37 +11:00
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Models.Identity;
|
|
|
|
|
|
using Umbraco.Core.Security;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Models.Mapping
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class UserModelMapper : MapperConfiguration
|
|
|
|
|
|
{
|
|
|
|
|
|
public override void ConfigureMappings(IConfiguration config, ApplicationContext applicationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
config.CreateMap<IUser, UserDetail>()
|
2014-04-14 15:20:02 +10:00
|
|
|
|
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
|
|
|
|
|
|
.ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserType.Alias))
|
2014-10-07 14:59:07 +11:00
|
|
|
|
.ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId))
|
|
|
|
|
|
.ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId))
|
2015-03-24 20:17:37 +11:00
|
|
|
|
.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))
|
2014-04-14 15:20:02 +10:00
|
|
|
|
.ForMember(
|
|
|
|
|
|
detail => detail.EmailHash,
|
|
|
|
|
|
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()))
|
|
|
|
|
|
.ForMember(detail => detail.SecondsUntilTimeout, opt => opt.Ignore());
|
2013-10-15 18:46:44 +11:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
config.CreateMap<IProfile, UserBasic>()
|
|
|
|
|
|
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
|
2015-03-24 20:17:37 +11:00
|
|
|
|
|
|
|
|
|
|
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))
|
2015-04-01 14:29:35 +11:00
|
|
|
|
.ForMember(detail => detail.Culture, opt => opt.MapFrom(user => user.GetUserCulture(applicationContext.Services.TextService)))
|
|
|
|
|
|
.ForMember(detail => detail.SessionId, opt => opt.MapFrom(user => user.SecurityStamp.IsNullOrWhiteSpace() ? Guid.NewGuid().ToString("N") : user.SecurityStamp));
|
2015-03-24 20:17:37 +11:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
2013-08-26 11:26:58 +10:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
private static int GetIntId(object id)
|
|
|
|
|
|
{
|
|
|
|
|
|
var result = id.TryConvertTo<int>();
|
|
|
|
|
|
if (result.Success == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new InvalidOperationException(
|
|
|
|
|
|
"Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.Result;
|
|
|
|
|
|
}
|
2013-08-26 11:26:58 +10:00
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
2013-06-17 01:06:31 +02:00
|
|
|
|
}
|