2014-03-11 14:23:51 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
2014-07-08 18:07:59 +10:00
|
|
|
|
using Umbraco.Core.Models.Membership;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
using Umbraco.Core.Models.PublishedContent;
|
|
|
|
|
|
using Umbraco.Web.Models;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Exposes a member object as IPublishedContent
|
|
|
|
|
|
/// </summary>
|
2016-06-09 19:38:51 +02:00
|
|
|
|
public sealed class PublishedMember : PublishedContentBase
|
2014-03-11 14:23:51 +11:00
|
|
|
|
{
|
|
|
|
|
|
private readonly IMember _member;
|
2014-07-08 18:07:59 +10:00
|
|
|
|
private readonly IMembershipUser _membershipUser;
|
2014-04-02 11:13:54 +02:00
|
|
|
|
private readonly IPublishedProperty[] _properties;
|
2019-04-15 13:04:14 +02:00
|
|
|
|
private readonly IPublishedContentType _publishedMemberType;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-01-23 14:16:42 +01:00
|
|
|
|
public PublishedMember(
|
|
|
|
|
|
IMember member,
|
2019-04-24 14:25:41 +02:00
|
|
|
|
IPublishedContentType publishedMemberType)
|
2014-03-11 14:23:51 +11:00
|
|
|
|
{
|
2017-07-21 17:19:00 +02:00
|
|
|
|
_member = member ?? throw new ArgumentNullException(nameof(member));
|
2014-07-08 18:07:59 +10:00
|
|
|
|
_membershipUser = member;
|
2017-07-21 17:19:00 +02:00
|
|
|
|
_publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
|
2014-04-02 11:13:54 +02:00
|
|
|
|
|
2018-01-10 12:48:51 +01:00
|
|
|
|
// RawValueProperty is used for two things here
|
|
|
|
|
|
// - for the 'map properties' thing that we should really get rid of
|
|
|
|
|
|
// - for populating properties that every member should always have, and that we force-create
|
|
|
|
|
|
// if they are not part of the member type properties - in which case they are created as
|
|
|
|
|
|
// simple raw properties - which are completely invariant
|
|
|
|
|
|
|
|
|
|
|
|
var properties = new List<IPublishedProperty>();
|
|
|
|
|
|
foreach (var propertyType in _publishedMemberType.PropertyTypes)
|
|
|
|
|
|
{
|
|
|
|
|
|
var property = _member.Properties[propertyType.Alias];
|
|
|
|
|
|
if (property == null) continue;
|
|
|
|
|
|
|
2019-04-22 11:58:51 +02:00
|
|
|
|
properties.Add(new RawValueProperty(propertyType, this, property.GetValue()));
|
2018-01-10 12:48:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
EnsureMemberProperties(properties);
|
|
|
|
|
|
_properties = properties.ToArray();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Membership provider member properties
|
2016-06-03 10:57:54 +02:00
|
|
|
|
|
|
|
|
|
|
public string Email => _membershipUser.Email;
|
|
|
|
|
|
|
|
|
|
|
|
public string UserName => _membershipUser.Username;
|
|
|
|
|
|
|
|
|
|
|
|
public string Comments => _membershipUser.Comments;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsApproved => _membershipUser.IsApproved;
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsLockedOut => _membershipUser.IsLockedOut;
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime LastLockoutDate => _membershipUser.LastLockoutDate;
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime CreationDate => _membershipUser.CreateDate;
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime LastLoginDate => _membershipUser.LastLoginDate;
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime LastActivityDate => _membershipUser.LastLoginDate;
|
|
|
|
|
|
|
|
|
|
|
|
public DateTime LastPasswordChangeDate => _membershipUser.LastPasswordChangeDate;
|
|
|
|
|
|
|
2014-03-11 14:23:51 +11:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region IPublishedContent
|
|
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override PublishedItemType ItemType => PublishedItemType.Member;
|
|
|
|
|
|
|
2018-12-13 15:08:12 +01:00
|
|
|
|
public override bool IsDraft(string culture = null) => false;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-01-23 07:54:45 +01:00
|
|
|
|
public override bool IsPublished(string culture = null) => true;
|
|
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override IPublishedContent Parent => null;
|
|
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override IEnumerable<IPublishedContent> ChildrenForAllCultures => Enumerable.Empty<IPublishedContent>();
|
2016-06-03 10:57:54 +02:00
|
|
|
|
|
2016-06-10 16:37:28 +02:00
|
|
|
|
public override IEnumerable<IPublishedProperty> Properties => _properties;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
|
|
|
|
|
public override IPublishedProperty GetProperty(string alias)
|
|
|
|
|
|
{
|
2018-01-10 12:48:51 +01:00
|
|
|
|
return _properties.FirstOrDefault(x => x.Alias.InvariantEquals(alias));
|
2014-03-11 14:23:51 +11:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-10 12:48:51 +01:00
|
|
|
|
private void EnsureMemberProperties(List<IPublishedProperty> properties)
|
2017-09-26 14:57:50 +02:00
|
|
|
|
{
|
2018-01-10 12:48:51 +01:00
|
|
|
|
var aliases = properties.Select(x => x.Alias).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "Email", Email);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "UserName", UserName);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "Comments", Comments);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "IsApproved", IsApproved);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "IsLockedOut", IsLockedOut);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "LastLockoutDate", LastLockoutDate);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "CreateDate", CreateDate);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "LastLoginDate", LastLoginDate);
|
|
|
|
|
|
EnsureMemberProperty(properties, aliases, "LastPasswordChangeDate", LastPasswordChangeDate);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void EnsureMemberProperty(List<IPublishedProperty> properties, List<string> aliases, string alias, object value)
|
|
|
|
|
|
{
|
|
|
|
|
|
// if the property already has a value, nothing to do
|
|
|
|
|
|
if (aliases.Contains(alias)) return;
|
|
|
|
|
|
|
|
|
|
|
|
// if not a property type, ignore
|
|
|
|
|
|
var propertyType = ContentType.GetPropertyType(alias);
|
|
|
|
|
|
if (propertyType == null) return;
|
|
|
|
|
|
|
|
|
|
|
|
// create a raw-value property
|
|
|
|
|
|
// note: throws if propertyType variations is not InvariantNeutral
|
|
|
|
|
|
var property = new RawValueProperty(propertyType, this, value);
|
|
|
|
|
|
properties.Add(property);
|
2017-09-26 14:57:50 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-04-15 13:04:14 +02:00
|
|
|
|
public override IPublishedContentType ContentType => _publishedMemberType;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override int Id => _member.Id;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override Guid Key => _member.Key;
|
2015-08-31 18:59:51 +02:00
|
|
|
|
|
2018-11-15 07:23:09 +00:00
|
|
|
|
public override int? TemplateId => throw new NotSupportedException();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override int SortOrder => 0;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override string Name => _member.Name;
|
2018-04-24 01:31:01 +10:00
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override IReadOnlyDictionary<string, PublishedCultureInfo> Cultures => throw new NotSupportedException();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-06-06 16:54:00 +02:00
|
|
|
|
public override string UrlSegment => throw new NotSupportedException();
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-01-27 01:17:32 -05:00
|
|
|
|
// TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override string WriterName => _member.GetCreatorProfile().Name;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2019-01-27 01:17:32 -05:00
|
|
|
|
// TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override string CreatorName => _member.GetCreatorProfile().Name;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override int WriterId => _member.CreatorId;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override int CreatorId => _member.CreatorId;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override string Path => _member.Path;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override DateTime CreateDate => _member.CreateDate;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override DateTime UpdateDate => _member.UpdateDate;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
2016-06-03 10:57:54 +02:00
|
|
|
|
public override int Level => _member.Level;
|
2014-03-11 14:23:51 +11:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|