Table of Contents

Login

Manage user login in frontend

The Login app is fairly simple and makes it possible for users to log in and navigate to a forgotten password site:

Users login

In the app you must:

  • Provide a Login template
  • Select a page with a Forgot password link
  • Select a page to redirect users to after login OR select to redirect to the page defined on the specific user

Login template

The Login template should inherit the UserLoginViewModel, and use the Dynamicweb.Rendering and Dynamicweb.Users.Frontend namespaces. A simple login form could be:

@inherits ViewModelTemplate<LoginViewModel>
@using Dynamicweb
@using Dynamicweb.Rendering
@using Dynamicweb.Users.Frontend

<form method="post">
    <label for="login-username">Email</label>
    <input type="text" class="form-control" id="login-username" name="username" placeholder="Email" required>

    <label for="login-password">Password</label>
    <input type="password" class="form-control" id="LoginPassword" name="password" placeholder="Password" required>

    <!-- Create a link to redirect to the Forgot Password page -->
    <a tabindex="-1" class="form-label-link" href="@Model.ForgotPasswordLink" id="ForgotPasswordButton">Forgot password?</a>
    
    <label for="RememberMe">Keep me signed in</label>
    <input type="checkbox" value="True" name="Autologin" id="RememberMe">
    
    <div>
        <!-- Show the login result -->
        @if (Model.Result is not null)
        {
            @if (Model.Result.Success)
            {
                <div class="label">You are logged in!</div>
            }
            else
            {
                <div class="label">@Model.Result.FailedReason.ToString()</div>
            }
        }
        <button type="submit" id="SignInButton">Sign in</button>    
    </div>
</form>
To top