Fixes remapping the key, allows for including/excluding custom properties on profile editing too.

This commit is contained in:
Shannon
2021-04-09 16:49:17 +10:00
parent a745ef54a7
commit 5ce7127beb
5 changed files with 29 additions and 12 deletions

View File

@@ -86,6 +86,7 @@ namespace Umbraco.Cms.Core.Security
// re-assign id
user.Id = UserIdToString(memberEntity.Id);
user.Key = memberEntity.Key;
// [from backofficeuser] we have to remember whether Logins property is dirty, since the UpdateMemberProperties will reset it.
// var isLoginsPropertyDirty = user.IsPropertyDirty(nameof(MembersIdentityUser.Logins));

View File

@@ -12,6 +12,8 @@
.CreateProfileModel()
// If null or not set, this will redirect to the current page
.WithRedirectUrl(null)
// Include editable custom properties on the form
.WithCustomProperties(true)
.BuildForCurrentMemberAsync();
var success = TempData["FormSuccess"] != null;
@@ -21,7 +23,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.0/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validation-unobtrusive/3.2.11/jquery.validate.unobtrusive.min.js"></script>
@if(profileModel != null)
@if (profileModel != null)
{
if (success)
{
@@ -54,14 +56,17 @@
</div>
}
for (var i = 0; i < profileModel.MemberProperties.Count; i++)
@if (profileModel.MemberProperties != null)
{
<div class="mb-3">
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
<input asp-for="@profileModel.MemberProperties[i].Value" class="form-control" />
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
<span asp-validation-for="@profileModel.MemberProperties[i].Value" class="form-text text-danger"></span>
</div>
for (var i = 0; i < profileModel.MemberProperties.Count; i++)
{
<div class="mb-3">
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
<input asp-for="@profileModel.MemberProperties[i].Value" class="form-control" />
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
<span asp-validation-for="@profileModel.MemberProperties[i].Value" class="form-text text-danger"></span>
</div>
}
}
<button type="submit" class="btn btn-primary">Update</button>

View File

@@ -17,7 +17,7 @@
.WithRedirectUrl(null)
// Set to true if you want the member editable properties shown.
// It will only displays properties marked as "Member can edit" on the "Info" tab of the Member Type.
.LookupProperties(true)
.WithCustomProperties(false)
.Build();
var success = TempData["FormSuccess"] != null;
@@ -71,8 +71,9 @@ else
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
<div class="mb-3">
<label asp-for="@registerModel.MemberProperties[i].Value" class="form-label"></label>
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
<input asp-for="@registerModel.MemberProperties[i].Value" class="form-control" />
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<span asp-validation-for="@registerModel.MemberProperties[i].Value" class="form-text text-danger"></span>
</div>
}

View File

@@ -15,6 +15,7 @@ namespace Umbraco.Cms.Web.Website.Models
private readonly IMemberService _memberService;
private readonly IHttpContextAccessor _httpContextAccessor;
private string _redirectUrl;
private bool _lookupProperties;
public ProfileModelBuilder(
IMemberTypeService memberTypeService,
@@ -33,6 +34,12 @@ namespace Umbraco.Cms.Web.Website.Models
return this;
}
public ProfileModelBuilder WithCustomProperties(bool lookupProperties)
{
_lookupProperties = lookupProperties;
return this;
}
public async Task<ProfileModel> BuildForCurrentMemberAsync()
{
IMemberManager memberManager = _httpContextAccessor.HttpContext?.RequestServices.GetRequiredService<IMemberManager>();
@@ -78,7 +85,10 @@ namespace Umbraco.Cms.Web.Website.Models
throw new InvalidOperationException($"Could not find a member with key: {member.Key}.");
}
model.MemberProperties = GetMemberPropertiesViewModel(memberType, persistedMember);
if (_lookupProperties)
{
model.MemberProperties = GetMemberPropertiesViewModel(memberType, persistedMember);
}
return model;
}

View File

@@ -40,7 +40,7 @@ namespace Umbraco.Cms.Web.Website.Models
return this;
}
public RegisterModelBuilder LookupProperties(bool lookupProperties)
public RegisterModelBuilder WithCustomProperties(bool lookupProperties)
{
_lookupProperties = lookupProperties;
return this;