Thanks Mike, it is “some” use, in that it gives a bit of a hint. But it mentions code in the Startup.cs which we don’t have anymore of course. Pity it’s left out of the docs.
Thanks for that. I can see the forgotten password method, but the rememberme is still a mystery. Looking in the UmbracoSignInManager.cs I can see it handles rememberme but it doesn’t cause the asp identity application cookie to get a date, it just sits on “session”.
My login then goes to 2FA using the GoogleAuthentication package. I can also see in UmbracoSignInManager.cs that there’s some provision for rememberme wrt 2FA. It’s all rather dense and getting beyond my understanding. Just wish they’d documented this stuff so people can use it.
Would also like to know how to surface failed login messages too, but that’s probably another post.
could you copy the HandleLogin method into your own controller to use against your view, to make sure that model.RememberMe is getting passed as true… as it just seems to bubble this up to asp.net identitiy as you say and if the isPersistent passed as true we should be being remembered with a persistent cookie and not session?
Well the point is I don’t have a controller, I’m using Umbraco’s. Which is why it’s annoying they only give you half a story. If I’d done my own controller I guess I’d have used a more complete reference (hopefully).
I might have to re-engineer to use my own controller, but it’s a pain at this stage. I suppose I was hoping someone had come across this before and solved it with the Umbraco controller.
Just blanket copy the umbController… drop it in your solution… change the namespace and update your controller action to use your replacement … then debug… ?? would be my plan of attack.
Ok, so I’ve done that and it’s hitting the new controller and completing login ok. However, there are a few anomalies…
The login appears to be done in a subordinate method here:-
// Sign the user in with username/password, this also gives a chance for developers to
// custom verify the credentials and auto-link user accounts with a custom IBackOfficePasswordChecker
SignInResult result = await _signInManager.PasswordSignInAsync(
model.Username, model.Password, model.RememberMe, true);
The model.RememberMe is True when the check box is checked, but nothing happens.
There are conditionals for “result” which could have messages but no way to get them back to the original login page as it’s overridden by a return currentUmbracoPage()
else if (result.IsLockedOut)
{
ModelState.AddModelError("loginModel", "Member is locked out");
}
else if (result.IsNotAllowed)
{
ModelState.AddModelError("loginModel", "Member is not allowed");
}
else
{
ModelState.AddModelError("loginModel", "Invalid username or password");
}
return CurrentUmbracoPage();
For the validation messages, I suspect I’ll have to either use a TempData/ViewData construction or maybe even have to extend a model somewhere/somehow.
As for the RememberMe functionality, I might end up disappearing down a rabbit hole.
There are def bits missing here.
I’m just concerned that if I go off-piste, rolling my own stuff, I’ll disappear where the sun don’t shine. Is there a “better” way, etc.
I’ve had a little success with the validation messages though it looks like it’s because the one supplied in the login snippet doesn’t appear to work…
I’ve added a new line under the original asp-validation-summary, which is what I guess is supposed to surface the ModelState errors and now see the ModelState errors.
I see it alludes to some instructions to create a global cookie in appsettings, though I can’t find anything anywhere about how to set this up in appsettings.
Which seems to indicate that remember me is still only a session cookie with a 14day default expiretimespan, with sliding expiry.. so if you restart your app… or IIS session times out the remember me will still then need a new login?
Also you mentioned 2FA.. which also has the isPersistent that can be passed.. is that also correctly implemented???
looks like it should be passing the same model.IsPersistent… but maybe the same AddModelError issue.. where I think the nameof(Verify2FACodeModel.Code) should be string.Empty for the tag manager to work with none property named errors.
ps to stick to taghelpers.. <span class="text-danger" asp-validation-for="loginModel"></span> is the equivalent of @Html.ValidationMessage("loginModel", "", new { @class = "text-danger" })
I believe…
Hi @huwred I see you have forgotten password code in there, but did you get the RememberMe working? Mines followed by 2FA which might be why it’s not working, not sure.