Adds more methods to the MembershipHelper, updates the RegisterModel and obsoletes the standard ctor so biz logic is not happening in the model, updates the snippets to use the correct way. Fixes an issue in the membership repo for persisting new members when the member type doesn't contain all the built-in props.
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Umbraco.Web.Models
|
||||
/// <summary>
|
||||
/// This will construct a new LoginStatusModel and perform a lookup for hte curently logged in member
|
||||
/// </summary>
|
||||
[Obsolete("Do not use this ctor as it will perform business logic lookups. Use the MembershipHelper.GetLoginStatusModel or the static LoginStatusModel.CreateModel() to create an empty model.")]
|
||||
[Obsolete("Do not use this ctor as it will perform business logic lookups. Use the MembershipHelper.GetCurrentLoginStatus or the static LoginStatusModel.CreateModel() to create an empty model.")]
|
||||
public LoginStatusModel()
|
||||
: this(true)
|
||||
{
|
||||
|
||||
@@ -1,46 +1,55 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
public RegisterModel()
|
||||
/// <summary>
|
||||
/// Creates a new empty RegisterModel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static RegisterModel CreateModel()
|
||||
{
|
||||
this.MemberTypeAlias = Constants.Conventions.MemberTypes.Member;
|
||||
var model = new RegisterModel(false);
|
||||
return model;
|
||||
}
|
||||
|
||||
this.RedirectOnSucces = false;
|
||||
private RegisterModel(bool doLookup)
|
||||
{
|
||||
MemberTypeAlias = Constants.Conventions.MemberTypes.Member;
|
||||
RedirectOnSucces = false;
|
||||
RedirectUrl = "/";
|
||||
UsernameIsEmail = true;
|
||||
|
||||
this.RedirectUrl = "/";
|
||||
|
||||
this.UsernameIsEmail = true;
|
||||
|
||||
var memberType = MemberType.GetByAlias(this.MemberTypeAlias);
|
||||
|
||||
if (memberType != null)
|
||||
if (doLookup && HttpContext.Current != null && ApplicationContext.Current != null)
|
||||
{
|
||||
this.MemberProperties = new List<UmbracoProperty>();
|
||||
|
||||
foreach (var prop in memberType.PropertyTypes.Where(memberType.MemberCanEdit))
|
||||
{
|
||||
this.MemberProperties.Add(new UmbracoProperty
|
||||
{
|
||||
Alias = prop.Alias,
|
||||
Name = prop.Name,
|
||||
Value = string.Empty
|
||||
});
|
||||
}
|
||||
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; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns the member properties
|
||||
/// </summary>
|
||||
public List<UmbracoProperty> MemberProperties { get; set; }
|
||||
|
||||
public string MemberTypeAlias { get; set; }
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
namespace Umbraco.Web.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple representation of an Umbraco property
|
||||
/// </summary>
|
||||
public class UmbracoProperty
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user