We've been using the basic snippets and can achive the following:
* Secure pages - redirecting the user to the login page - the downside is the user is then redirected to the login page after successfully logging in.
* Register users - you can't allocate them to a group though which means manual intervention to allow them access to your protected area (if done by group)
* Show the users login status - works nicely :)
So using the snippets you can *nearly* create a fully fledged Members only area part of a site. Suggest the following:
* login razor snippet is changed to redirect the use to the page they requested that was protected (see below)
* Update the public / secure access UI option to allow you to specify a member Type (as well as a group)
* Add to the CreateRegistrationModel Member API an option to specify a group that the user is added to on register.
Then you could have a fully working members area without having to touch any code (short of creating some snippets).
Is this possible - happy to have a go at a pull request if someone could point me in the right direction(s).
This is my revised login code from the snippet to avoid the user being redirected to the login page (or perhaps I've missed a setting somewhere!!).
Would this be a suitable replacement for the current snippet?
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@using System.Web.Mvc.Html
@using ClientDependency.Core.Mvc
@using Umbraco.Web
@using Umbraco.Web.Models
@using Umbraco.Web.Controllers
@{
// You have to set the login node ID otherwise you'll have an infinite loop if someone hits the login page first
var loginNodeID = 1072;
var loginModel = new LoginModel();
var loginStatusModel = Members.GetCurrentLoginStatus();
Html.EnableClientValidation();
Html.EnableUnobtrusiveJavaScript();
Html.RequiresJs("/umbraco_client/ui/jquery.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.min.js");
Html.RequiresJs("/umbraco_client/Application/JQuery/jquery.validate.unobtrusive.min.js");
}
@* NOTE: This RenderJsHere code should be put on your main template page where the rest of your script tags are placed *@
@Html.RenderJsHere()
@{
@* if we don't have a session variable and have a request URL then store it *@
if (HttpContext.Current.Request.Url != null && HttpContext.Current.Session["redirectURL"] == null) {
if (CurrentPage.Id != loginNodeID) {
HttpContext.Current.Session["redirectURL"] = HttpContext.Current.Request.Url.ToString();
}
}
}
@if (loginStatusModel.IsLoggedIn)
{
var redirectUrl = (string)HttpContext.Current.Session["redirectURL"];
var currentUrl = HttpContext.Current.Request.Url.ToString();
if (HttpContext.Current.Session["redirectURL"] != null) {
// clear the session variable for future logins
HttpContext.Current.Session["redirectURL"] = null;
HttpContext.Current.Response.Redirect(redirectUrl);
}
else {
// Nothing in the session so we will go home
HttpContext.Current.Response.Redirect("/");
}
}
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin"))
{
<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>
}
Member Snippets - suggestions for improvements
Hi,
I've been helping someone on the forum http://our.umbraco.org/forum/umbraco-7/using-umbraco-7/53194-Need-some-help-) ;
We've been using the basic snippets and can achive the following:
* Secure pages - redirecting the user to the login page - the downside is the user is then redirected to the login page after successfully logging in.
* Register users - you can't allocate them to a group though which means manual intervention to allow them access to your protected area (if done by group)
* Show the users login status - works nicely :)
So using the snippets you can *nearly* create a fully fledged Members only area part of a site. Suggest the following:
* login razor snippet is changed to redirect the use to the page they requested that was protected (see below)
* Update the public / secure access UI option to allow you to specify a member Type (as well as a group)
* Add to the CreateRegistrationModel Member API an option to specify a group that the user is added to on register.
Then you could have a fully working members area without having to touch any code (short of creating some snippets).
Is this possible - happy to have a go at a pull request if someone could point me in the right direction(s).
I've created an issue for this http://issues.umbraco.org/issue/U4-5038
This is my revised login code from the snippet to avoid the user being redirected to the login page (or perhaps I've missed a setting somewhere!!).
Would this be a suitable replacement for the current snippet?
Oops double post
"* Add to the CreateRegistrationModel Member API an option to specify a group that the user is added to on register."
with the help of the amazing Casey Neehouse, i was able to add a class to app_code to assign a new member to a role when created.
is working on a reply...