Migrated member related partial views along with necessary methods from MembershipHelper into IUmbracoWebsiteSecurity.

This commit is contained in:
Andy Butland
2020-11-24 11:33:46 +01:00
parent ebe643e30b
commit b331d683ec
13 changed files with 381 additions and 120 deletions

View File

@@ -68,6 +68,10 @@
<None Remove="Umbraco/Models/all.dll.path" />
<None Remove="Umbraco/Models/models.hash" />
<None Remove="Umbraco/Models/models.err" />
<None Remove="umbraco\PartialViewMacros\Templates\EditProfile.cshtml" />
<None Remove="umbraco\PartialViewMacros\Templates\Login.cshtml" />
<None Remove="umbraco\PartialViewMacros\Templates\LoginStatus.cshtml" />
<None Remove="umbraco\PartialViewMacros\Templates\RegisterMember.cshtml" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,61 @@
@using Umbraco.Core.Security
@using Umbraco.Extensions
@using Umbraco.Web.Website.Controllers
@inherits Umbraco.Web.Common.Macros.PartialViewMacroPage
@inject IUmbracoWebsiteSecurityAccessor UmbracoWebsiteSecurityAccessor
@{
var profileModel = await UmbracoWebsiteSecurityAccessor.WebsiteSecurity.GetCurrentMemberProfileModelAsync();
var success = TempData["ProfileUpdateSuccess"] != null;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<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 (UmbracoWebsiteSecurityAccessor.WebsiteSecurity.IsLoggedIn() && profileModel != null)
{
if (success)
{
@* This message will show if profileModel.RedirectUrl is not defined (default) *@
<p>Profile updated</p>
}
using (Html.BeginUmbracoForm<UmbProfileController>("HandleUpdateProfile"))
{
<fieldset>
<legend>Edit profile</legend>
@Html.ValidationSummary("profileModel", true)
@Html.LabelFor(m => profileModel.Name)
@Html.TextBoxFor(m => profileModel.Name)
@Html.ValidationMessageFor(m => profileModel.Name)
<br />
@Html.LabelFor(m => profileModel.Email)
@Html.TextBoxFor(m => profileModel.Email)
@Html.ValidationMessageFor(m => profileModel.Email)
<br />
@for (var i = 0; i < profileModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => profileModel.MemberProperties[i].Value, profileModel.MemberProperties[i].Name)
@*
By default this will render a textbox but if you want to change the editor template for this property you can
easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
render your specific editor template like:
@Html.EditorFor(m => profileModel.MemberProperties[i].Value, "MyEditor")
*@
@Html.EditorFor(m => profileModel.MemberProperties[i].Value)
@Html.HiddenFor(m => profileModel.MemberProperties[i].Alias)
<br />
}
<button>Save</button>
</fieldset>
}
}

View File

@@ -0,0 +1,36 @@
@using Microsoft.AspNetCore.Http.Extensions
@using Umbraco.Core.Models.Security
@using Umbraco.Extensions
@using Umbraco.Web.Website.Controllers
@inherits Umbraco.Web.Common.Macros.PartialViewMacroPage
@{
var loginModel = new LoginModel();
loginModel.RedirectUrl = Context.Request.GetDisplayUrl();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<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>
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
@Html.HiddenFor(m => loginModel.RedirectUrl)
<fieldset>
<legend>Login</legend>
@Html.ValidationSummary("loginModel", true)
@Html.LabelFor(m => loginModel.Username)
@Html.TextBoxFor(m => loginModel.Username)
@Html.ValidationMessageFor(m => loginModel.Username)
<br />
@Html.LabelFor(m => loginModel.Password)
@Html.PasswordFor(m => loginModel.Password)
@Html.ValidationMessageFor(m => loginModel.Password)
<br />
<button>Login</button>
</fieldset>
}

View File

@@ -0,0 +1,33 @@
@using Umbraco.Core.Security
@using Umbraco.Core.Models.Security
@using Umbraco.Extensions
@using Umbraco.Web.Website.Controllers
@inherits Umbraco.Web.Common.Macros.PartialViewMacroPage
@inject IUmbracoWebsiteSecurityAccessor UmbracoWebsiteSecurityAccessor
@{
var loginStatusModel = await UmbracoWebsiteSecurityAccessor.WebsiteSecurity.GetCurrentLoginStatusAsync();
var logoutModel = new PostRedirectModel();
@*
Here you can specify a redirect URL for after logging out, by default umbraco will simply
redirect to the current page. Example to redirect to the home page:
logoutModel.RedirectUrl = "/";
*@
}
@if (loginStatusModel.IsLoggedIn)
{
<p>You are currently logged in as @loginStatusModel.Name</p>
using (Html.BeginUmbracoForm<UmbLoginStatusController>("HandleLogout"))
{
<fieldset>
<legend>Logout</legend>
<button>Logout</button>
</fieldset>
@Html.HiddenFor(m => logoutModel.RedirectUrl)
}
}

View File

@@ -0,0 +1,98 @@
@using Umbraco.Core.Security
@using Umbraco.Extensions
@using Umbraco.Web.Website.Controllers
@inherits Umbraco.Web.Common.Macros.PartialViewMacroPage
@inject IUmbracoWebsiteSecurityAccessor UmbracoWebsiteSecurityAccessor
@{
@*
You can specify a custom member type alias in the constructor, the default is 'Member'
for example, to use 'Custom Member' you'd use this syntax:
var registerModel = Members.CreateRegistrationModel("Custom Member");
*@
var registerModel = UmbracoWebsiteSecurityAccessor.WebsiteSecurity.CreateRegistrationModel();
@*
Configurable here:
registerModel.RedirectUrl - Optional. What path to redirect to if registration is successful.
By default the member will be redirected to the current umbraco page
unless this is specified.
registerModel.UsernameIsEmail - the default is true
if you want the username to be different from the email
address, set this to true and add a new Username field in
the form below
@Html.LabelFor(m => registerModel.Username)
@Html.TextBoxFor(m => registerModel.Username)
@Html.ValidationMessageFor(m => registerModel.Username)
*@
var success = TempData["FormSuccess"] != null;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<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 (success)
{
@* This message will show if registerModel.RedirectUrl is not defined (default) *@
<p>Registration succeeded.</p>
}
else
{
using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember"))
{
<fieldset>
<legend>Register Member</legend>
@Html.ValidationSummary("registerModel", true)
@Html.LabelFor(m => registerModel.Name)
@Html.TextBoxFor(m => registerModel.Name)
@Html.ValidationMessageFor(m => registerModel.Name)
<br />
@Html.LabelFor(m => registerModel.Email)
@Html.TextBoxFor(m => registerModel.Email)
@Html.ValidationMessageFor(m => registerModel.Email)
<br />
@Html.LabelFor(m => registerModel.Password)
@Html.PasswordFor(m => registerModel.Password)
@Html.ValidationMessageFor(m => registerModel.Password)
<br />
@if (registerModel.MemberProperties != null)
{
@*
It will only displays properties marked as "Member can edit" on the "Info" tab of the Member Type.
*@
for (var i = 0; i < registerModel.MemberProperties.Count; i++)
{
@Html.LabelFor(m => registerModel.MemberProperties[i].Value, registerModel.MemberProperties[i].Name)
@*
By default this will render a textbox but if you want to change the editor template for this property you can
easily change it. For example, if you wanted to render a custom editor for this field called "MyEditor" you would
create a file at ~/Views/Shared/EditorTemplates/MyEditor.cshtml", then you will change the next line of code to
render your specific editor template like:
@Html.EditorFor(m => registerModel.MemberProperties[i].Value, "MyEditor")
*@
@Html.EditorFor(m => registerModel.MemberProperties[i].Value)
@Html.HiddenFor(m => registerModel.MemberProperties[i].Alias)
<br />
}
}
@Html.HiddenFor(m => registerModel.MemberTypeAlias)
@Html.HiddenFor(m => registerModel.RedirectUrl)
@Html.HiddenFor(m => registerModel.UsernameIsEmail)
<button>Register</button>
</fieldset>
}
}