2014-02-13 16:22:51 +11:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
2013-09-02 15:40:14 +02:00
using System.ComponentModel.DataAnnotations ;
using System.Linq ;
2014-02-13 16:22:51 +11:00
using System.Web ;
2014-03-13 14:12:45 +11:00
using System.Web.Mvc ;
2014-03-11 14:47:00 +11:00
using System.Xml ;
using System.Xml.Linq ;
2013-09-02 15:40:14 +02:00
using umbraco.cms.businesslogic.member ;
2014-02-13 16:22:51 +11:00
using Umbraco.Core ;
2014-03-11 14:47:00 +11:00
using Umbraco.Core.Models ;
using Umbraco.Core.Models.PublishedContent ;
using Umbraco.Web.PublishedCache ;
2014-02-13 16:22:51 +11:00
using Umbraco.Web.Security ;
2013-09-02 15:40:14 +02:00
namespace Umbraco.Web.Models
{
2014-03-11 14:47:00 +11:00
/// <summary>
/// A readonly member profile model
/// </summary>
2014-03-13 14:12:45 +11:00
[ModelBinder(typeof(ProfileModelBinder))]
2014-02-13 16:22:51 +11:00
public class ProfileModel : PostRedirectModel
2013-09-02 15:40:14 +02:00
{
2014-03-11 14:47:00 +11:00
2014-02-13 16:22:51 +11:00
public static ProfileModel CreateModel ( )
2013-09-02 15:40:14 +02:00
{
2014-02-13 16:22:51 +11:00
var model = new ProfileModel ( false ) ;
return model ;
}
private ProfileModel ( bool doLookup )
{
MemberProperties = new List < UmbracoProperty > ( ) ;
2017-08-10 13:46:18 +10:00
if ( doLookup & & UmbracoContext . Current ! = null )
2013-09-02 15:40:14 +02:00
{
2017-08-10 13:46:18 +10:00
var helper = new MembershipHelper ( UmbracoContext . Current ) ;
2014-03-11 14:47:00 +11:00
var model = helper . GetCurrentMemberProfileModel ( ) ;
2014-02-13 16:22:51 +11:00
MemberProperties = model . MemberProperties ;
}
}
[Obsolete("Do not use this ctor as it will perform business logic lookups. Use the MembershipHelper.CreateProfileModel or the static ProfileModel.CreateModel() to create an empty model.")]
public ProfileModel ( )
: this ( true )
{
2013-09-02 15:40:14 +02:00
}
[Required]
[RegularExpression(@"[a-z0-9!#$%&'*+/=?^_`{|}~-] + ( ? : \ . [ a - z0 - 9 ! # $ % & ' * + / = ? ^ _ ` { | } ~ - ] + ) * @ ( ? : [ a - z0 - 9 ] ( ? : [ a - z0 - 9 - ] * [ a - z0 - 9 ] ) ? \ . ) + [ a - z0 - 9 ] ( ? : [ a - z0 - 9 - ] * [ a - z0 - 9 ] ) ? ",
ErrorMessage = "Please enter a valid e-mail address" ) ]
public string Email { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The member's real name
/// </summary>
2013-09-02 15:40:14 +02:00
public string Name { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The member's member type alias
/// </summary>
[ReadOnly(true)]
2013-09-02 15:40:14 +02:00
public string MemberTypeAlias { get ; set ; }
2014-02-19 16:55:56 +11:00
[ReadOnly(true)]
public string UserName { get ; set ; }
[ReadOnly(true)]
public string PasswordQuestion { get ; set ; }
[ReadOnly(true)]
public string Comment { get ; set ; }
[ReadOnly(true)]
public bool IsApproved { get ; set ; }
[ReadOnly(true)]
public bool IsLockedOut { get ; set ; }
[ReadOnly(true)]
public DateTime LastLockoutDate { get ; set ; }
[ReadOnly(true)]
public DateTime CreationDate { get ; set ; }
[ReadOnly(true)]
public DateTime LastLoginDate { get ; set ; }
[ReadOnly(true)]
public DateTime LastActivityDate { get ; set ; }
[ReadOnly(true)]
public DateTime LastPasswordChangedDate { get ; set ; }
2014-02-13 16:22:51 +11:00
/// <summary>
/// The list of member properties
/// </summary>
/// <remarks>
/// Adding items to this list on the front-end will not add properties to the member in the database.
/// </remarks>
2014-03-13 14:12:45 +11:00
public List < UmbracoProperty > MemberProperties { get ; set ; }
/// <summary>
/// A custom model binder for MVC because the default ctor performs a lookup!
/// </summary>
internal class ProfileModelBinder : DefaultModelBinder
{
protected override object CreateModel ( ControllerContext controllerContext , ModelBindingContext bindingContext , Type modelType )
{
return ProfileModel . CreateModel ( ) ;
}
}
2013-09-02 15:40:14 +02:00
}
}