using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using umbraco.cms.businesslogic.member;
using Umbraco.Core;
using Umbraco.Web.Security;
namespace Umbraco.Web.Models
{
public class RegisterModel : PostRedirectModel
{
///
/// Creates a new empty RegisterModel
///
///
public static RegisterModel CreateModel()
{
var model = new RegisterModel(false);
return model;
}
private RegisterModel(bool doLookup)
{
MemberTypeAlias = Constants.Conventions.MemberTypes.Member;
RedirectOnSucces = false;
RedirectUrl = "/";
UsernameIsEmail = true;
MemberProperties = new List();
LoginOnSuccess = true;
if (doLookup && HttpContext.Current != null && ApplicationContext.Current != null)
{
var helper = new MembershipHelper(ApplicationContext.Current, new HttpContextWrapper(HttpContext.Current));
var model = helper.CreateRegistrationModel(MemberTypeAlias);
MemberProperties = model.MemberProperties;
}
}
[Obsolete("Do not use this ctor as it will perform business logic lookups. Use the MembershipHelper.CreateRegistrationModel or the static RegisterModel.CreateModel() to create an empty model.")]
public RegisterModel()
: this(true)
{
}
[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; }
///
/// Returns the member properties
///
public List MemberProperties { get; set; }
///
/// The member type alias to use to register the member
///
public string MemberTypeAlias { get; set; }
///
/// The members real name
///
public string Name { get; set; }
///
/// The members password
///
[Required]
public string Password { get; set; }
[ReadOnly(true)]
[Obsolete("This is no longer used and will be removed from the codebase in future versions")]
public bool RedirectOnSucces { get; set; }
///
/// The username of the model, if UsernameIsEmail is true then this is ignored.
///
public string Username { get; set; }
///
/// Flag to determine if the username should be the email address, if true then the Username property is ignored
///
public bool UsernameIsEmail { get; set; }
///
/// Specifies if the member should be logged in if they are succesfully created
///
public bool LoginOnSuccess { get; set; }
}
}