// Umbraco.Code.MapAll -Id -Groups -LockoutEnabled -PhoneNumber -PhoneNumberConfirmed -TwoFactorEnabled private void Map(IUser source, BackOfficeIdentityUser target) { // well, the ctor has been fixed /* * // these two are already set in ctor but BackOfficeIdentityUser ctor is CompletelyBroken * target.Id = source.Id; * target.Groups = source.Groups.ToArray(); */ target.CalculatedMediaStartNodeIds = source.CalculateMediaStartNodeIds(_entityService, _appCaches); target.CalculatedContentStartNodeIds = source.CalculateContentStartNodeIds(_entityService, _appCaches); target.Email = source.Email; target.UserName = source.Username; target.LastPasswordChangeDateUtc = source.LastPasswordChangeDate.ToUniversalTime(); target.LastLoginDateUtc = source.LastLoginDate.ToUniversalTime(); target.EmailConfirmed = source.EmailConfirmedDate.HasValue; target.Name = source.Name; target.AccessFailedCount = source.FailedPasswordAttempts; target.PasswordHash = GetPasswordHash(source.RawPasswordValue); target.StartContentIds = source.StartContentIds; target.StartMediaIds = source.StartMediaIds; target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString(); // project CultureInfo to string target.IsApproved = source.IsApproved; target.SecurityStamp = source.SecurityStamp; target.LockoutEndDateUtc = source.IsLockedOut ? DateTime.MaxValue.ToUniversalTime() : (DateTime?)null; // this was in AutoMapper but does not have a setter anyways //target.AllowedSections = source.AllowedSections.ToArray(), // these were marked as ignored for AutoMapper but don't have a setter anyways //target.Logins =; //target.Claims =; //target.Roles =; }
public void DefineMaps(UmbracoMapper mapper) { mapper.Define <IUser, BackOfficeIdentityUser>( (source, context) => { var target = new BackOfficeIdentityUser(source.Id, source.Groups); target.DisableChangeTracking(); return(target); }, (source, target, context) => { Map(source, target); target.ResetDirtyProperties(true); target.EnableChangeTracking(); }); }
/// <summary> /// Used to construct a new instance without an identity /// </summary> /// <param name="username"></param> /// <param name="email">This is allowed to be null (but would need to be filled in if trying to persist this instance)</param> /// <param name="culture"></param> /// <returns></returns> public static BackOfficeIdentityUser CreateNew(string username, string email, string culture) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(username)); } if (string.IsNullOrWhiteSpace(culture)) { throw new ArgumentException("Value cannot be null or whitespace.", nameof(culture)); } var user = new BackOfficeIdentityUser(Array.Empty <IReadOnlyUserGroup>()); user.DisableChangeTracking(); user._userName = username; user._email = email; //we are setting minvalue here because the default is "0" which is the id of the admin user //which we cannot allow because the admin user will always exist user._id = int.MinValue; user._hasIdentity = false; user._culture = culture; user.EnableChangeTracking(); return(user); }