Table of Contents

Authentication

Manage user authentication in frontend

The Users - Authentication app renders a frontend authentication form and handles the result of a sign‑in attempt. It also exposes links to Create user and Set password pages and can surface external identity providers configured for the solution.

Note

Template location: /Templates/Users/UserAuthentication/Login

What the app does

When the app is running on a paragraph it will render a login form. When the authentication form is submitted, the result of the authentication will be either rendered in the authentication template or redirect to another page when the authentication is successful.

The template receives a UserAuthenticationViewModel with:

  • RedirectAfterLogin – URL to send the user to after success (derived from either Redirect back to referrer or Redirect to specific page).
  • CreatePasswordLink, CreateUserLink – fully resolved links to the chosen pages.
  • ExternalLogins – collection of available external providers (id, name, optional icon).
  • Result – the outcome of the most recent sign‑in attempt.

Paragraph app settings

Users login

From the paragraph app you have the following settings as an editor:

  • Login template: choose a Razor template from /Templates/Users/UserAuthentication/Login.
  • Redirect after authentication
    • Redirect to specific page: choose a fallback page to send users to after a successful login.
    • Redirect back to referrer: if enabled, a successful login redirects to the page the user came from (when available).
  • Pages
    • Page to set password
    • Page to create user
Note
  • If both Redirect back to referrer is enabled and a valid referrer exists, it wins; otherwise the module falls back to Redirect to specific page.
  • The old ForgotPasswordLink editor value is obsolete. Use the Page to set password setting instead.

Login template

Place a .cshtml file in /Templates/Users/UserAuthentication/Login. The template should inherit ViewModelTemplate<UserAuthenticationViewModel> and import the Dynamicweb.Users.Frontend.UserAuthentication namespace.

Minimal example

@inherits ViewModelTemplate<Dynamicweb.Users.Frontend.UserAuthentication.UserAuthenticationViewModel>
@using Dynamicweb
@using Dynamicweb.Rendering
@using Dynamicweb.Users.Frontend.UserAuthentication

@{
    var redirectPage = Model.RedirectAfterLogin;
}

<form method="post">
    <input type="hidden" name="redirect" value="@redirectPage" />

    <label for="login-username">Email</label>
    <input type="text" id="login-username" name="username" placeholder="Email" required />

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

    <div>
        <input type="checkbox" value="True" name="Autologin" id="remember-me" />
        <label for="remember-me">Keep me signed in</label>
    </div>

    <div class="actions">
        <button type="submit" id="sign-in-button">Sign in</button>
        @* Optional links *@
        @if (!string.IsNullOrEmpty(Model.CreatePasswordLink)) {
            <a href="@Model.CreatePasswordLink">Forgot / set password</a>
        }
        @if (!string.IsNullOrEmpty(Model.CreateUserLink)) {
            <a href="@Model.CreateUserLink">Create account</a>
        }
    </div>

    @* Show an authentication result if present *@
    @if (Model.Result != UserAuthenticationResultType.None) {
        <div class="login-result">@Translate(Model.Result.ToString())</div>
    }

    @* Optionally list external providers *@
    @if (Model.ExternalLogins?.Any() == true) {
        <div class="external-logins">
            <div>Or continue with</div>
            <ul>
                @foreach (var p in Model.ExternalLogins) {
                    <li>
                        <button type="submit" name="DwExternalLoginProvider" value="@p.Id">
                            @if (!string.IsNullOrEmpty(p.Icon)) { <img src="@p.Icon" alt="" /> }
                            <span>@p.Name</span>
                        </button>
                    </li>
                }
            </ul>
        </div>
    }
</form>

Styling & accessibility tips

  • Use proper <label> elements bound to inputs.
  • Keep the result message near the submit button for immediate feedback.
  • Prefer type="email" for the username if your solution uses email logins.
  • Add server‑side validation messages where relevant.

Handling results in your template

UserAuthenticationResultType covers all outcomes you may want to translate or customize in your UI, including success and typical errors. You can switch on Model.Result if you want custom text or behavior per case (e.g., show a link to reset password on PasswordExpired).

@switch (Model.Result)
{
    case UserAuthenticationResultType.Success:
        <text></text> @* successful posts usually redirect *@
        break;
    case UserAuthenticationResultType.IncorrectLogin:
        <div class="error">Wrong username or password.</div>
        break;
    case UserAuthenticationResultType.PasswordExpired:
        <div class="error">Your password has expired. <a href="@Model.CreatePasswordLink">Set a new one</a>.</div>
        break;
    // handle other cases as needed…
}

How redirect resolution works

When Redirect back to referrer is enabled and a referrer header is present, RedirectAfterLogin will be populated with that URL. If not, it will use the Redirect to specific page setting. Your template receives the final RedirectAfterLogin string, so you only need to pass it back via a hidden redirect field as shown above.

References

  • View models
    • UserAuthenticationViewModel: RedirectAfterLogin, CreateUserLink, CreatePasswordLink, ExternalLogins, Result.
    • ExternalLoginViewModel: Id, Name, Icon.
    • UserAuthenticationResultType values you may see: Success, IncorrectLogin, PasswordLengthInvalid, PasswordExpired, ExceededFailedLogOnLimit, LoginLocked, ExternalProviderAuthenticationFailed, ExternalProviderEmailNotProvided, ExternalProviderNotRegisteredOrInactive, UserAutoCreationDisabled, UserCreationFailed.
  • Editor / settings
    • Template folder: /Templates/Users/UserAuthentication/Login
    • Settings persisted as: LoginTemplate, RedirectToSpecificPage, RedirectToReferrer, CreatePasswordPageId, CreateUserPageId.
To top