Remember Me Button
# help-with-umbraco
r
Hello. I have implemented the member login and register functionality from the Umbraco Docs (Link to docs). The docs didn't show the remember me button, but it is present when you use the Macro snipit. But no matter how many docs or forum posts I read, I can't find a way to change the default timeout for the remember me button. Code below shows the Macro snippet that Umbraco creates.
Copy code
cs
@using (Html.BeginUmbracoForm<UmbLoginController>(
    "HandleLogin", new { RedirectUrl = loginModel.RedirectUrl })) {
 <h4>Log in with a local account.</h4>
        <hr />
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="mb-3">
            <label asp-for="@loginModel.Username" class="form-label"></label>
            <input asp-for="@loginModel.Username" class="form-control" />
            <span asp-validation-for="@loginModel.Username" class="form-text text-danger"></span>
        </div>
        <div class="mb-3">
            <label asp-for="@loginModel.Password" class="form-label"></label>
            <input asp-for="@loginModel.Password" class="form-control" />
            <span asp-validation-for="@loginModel.Password" class="form-text text-danger"></span>
        </div>
        <div class="mb-3 form-check">
            <input asp-for="@loginModel.RememberMe" class="form-check-input">
            <label asp-for="@loginModel.RememberMe" class="form-check-label">
                @Html.DisplayNameFor(m => loginModel.RememberMe)
            </label>
        </div>
        <button type="submit" class="btn btn-primary">Log in</button>
    }
It's the
<input asp-for="@loginModel.RememberMe" class="form-check-input">
I'm looking at. EDIT: I have seen that you can create a global cookie in appsettings, but I need remember me to be able to be turned on or off. EDIT: I'm using
UmbAlternativeLoginController
What I would like to ask is, how do I change the default timeout for the member that is signing in, with the remember me button?
I found a workaround. I copy/paste the default
UmbLoginController
, and add a line before the return at the bottom, where it checks if the remember me button is checked. And if it's checked, it redirects to a view called /remembered. And that page redirects to the index. In startup.cs, I have a few lines:
Copy code
cs
services.ConfigureApplicationCookie(options =>
              // Both of these triggers
            {
                options.Cookie.Name = "DontRememberMe";
                options.Cookie.HttpOnly = false;
                options.ExpireTimeSpan = TimeSpan.FromMinutes(1);
                options.LoginPath = "/Views/MacroPartials/Login";
                options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
                options.SlidingExpiration = false;
                //options.Cookie.Expiration = TimeSpan.FromMinutes(1);
                options.Cookie.MaxAge = TimeSpan.FromMinutes(1);
            });
            
            // This is the longest running cookie, and therefore it's the cookie that decides when the user is logged out
            services.ConfigureApplicationCookie(options =>
            {
                options.Cookie.Name = "RememberMe";
                options.Cookie.HttpOnly = false;
                options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
                options.LoginPath = "/Views/Remembered";
                options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
                options.SlidingExpiration = false;
                //options.Cookie.Expiration = TimeSpan.FromMinutes(1);
                options.Cookie.MaxAge = TimeSpan.FromMinutes(10);
            });
And in my
UmbAlternativeLoginController
Copy code
cs
if (model.RememberMe)
  {
    return Redirect("/Remembered");
  }
return RedirectToCurrentUmbracoUrl();
It's not pretty, but it works
39 Views