Register - FadiZahhar/umbraco8showandtell GitHub Wiki

Let’s begin by extracting and searching for registration logic (e.g., controllers, view models, or services with "register", "member", or "account").

Your core registration logic is in these files:

  • ViewModel/RegisterViewModel.cs

  • Controllers/RegisterController.cs

Let’s review these and then write a clear, narrative Umbraco 8 registration tutorial based on them.


Step 1: Review RegisterViewModel.cs

Your RegisterViewModel ensures strong server-side validation for registration:

  • FirstName, LastName, Username, EmailAddress, Password, ConfirmPassword — all required.

  • Username & password have minimum length.

  • ConfirmPassword must match Password.


Step 2: Review RegisterController.cs

Now let’s check your registration workflow logic.

Your RegisterController implements a robust Umbraco 8 member registration system with email verification.
Here's what it does:

  • Renders the registration form using a strongly-typed view model.

  • On submit:

    • Validates the form with DataAnnotations.

    • Checks for duplicate email and duplicate username.

    • Creates a new Umbraco member (with type "Member").

    • Sets password and assigns a role ("Normal User").

    • Generates an email verification token, saves it as a custom member property.

    • Sends a verification email with the token using your injected IEmailService.

    • Provides success feedback to the user.

  • Verification Action:

    • Accepts a token (from a link in the verification email).

    • Looks up the member by token.

    • If found, marks the member as verified.


🎓 Step-by-Step Tutorial: Member Registration in Umbraco 8

(Based on your real code and best practices)


Step 1: Create the Member Properties in Umbraco

  • In Members > Member Types, edit the Member type.

  • Add these properties:

    • emailVerifyToken (Textstring) — stores the unique verification token

    • emailVerified (True/False) — has the member verified their email?

    • emailVerifiedDate (Date/Time) — when did verification occur?

  • Add any others you wish (e.g., First Name, Last Name if you want to store separately).

  • In Members > Member Groups, create a group named "Normal User" if it doesn't already exist.


Step 2: Create the Register ViewModel

File: /Core/ViewModel/RegisterViewModel.cs

Already provided above; handles all fields and validation.


Step 3: Create the Registration Form Partial View

File: /Views/Partials/Register.cshtml

@model HighlyDeveloped.Core.ViewModel.RegisterViewModel

@using (Html.BeginUmbracoForm("HandleRegister", "Register")) { @Html.AntiForgeryToken() <div class="form-group"> @Html.LabelFor(m => m.FirstName) @Html.TextBoxFor(m => m.FirstName, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.FirstName) </div> <div class="form-group"> @Html.LabelFor(m => m.LastName) @Html.TextBoxFor(m => m.LastName, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.LastName) </div> <div class="form-group"> @Html.LabelFor(m => m.Username) @Html.TextBoxFor(m => m.Username, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.Username) </div> <div class="form-group"> @Html.LabelFor(m => m.EmailAddress) @Html.TextBoxFor(m => m.EmailAddress, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.EmailAddress) </div> <div class="form-group"> @Html.LabelFor(m => m.Password) @Html.PasswordFor(m => m.Password, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.Password) </div> <div class="form-group"> @Html.LabelFor(m => m.ConfirmPassword) @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control" }) @Html.ValidationMessageFor(m => m.ConfirmPassword) </div> <button type="submit" class="btn btn-primary">Register</button> } @Html.ValidationSummary(true) @if (TempData["status"] != null && TempData["status"].ToString() == "OK") { <div class="alert alert-success">Thank you for registering! Please check your email to verify your account.</div> }


Step 4: Surface Controller Logic

File: /Core/Controllers/RegisterController.cs

Key steps:

  • Renders the form.

  • On POST:

    • Checks for existing email/username.

    • Creates member, sets password and role.

    • Generates and saves a unique verification token.

    • Sends verification email (_emailService.SendVerifyEmailAddressNotification).

    • Returns feedback to user.


Step 5: Email Verification Logic

  • The member receives an email with a link containing the token.

  • When they visit this link, the RenderEmailVerification action marks them as verified (sets emailVerified to true, and the date).

Example verification link:
https://yourdomain.com/verify/?token=abcdef12345


Step 6: Render the Registration Form Anywhere

A. In your Register page template:

@Html.Action("RenderRegister", "Register")

This ensures the form uses your ViewModel and server-side logic.

B. (Optional) As a MacroPartial:
You can adapt the rendering method if you wish to allow RTE/grid placement.


Step 7: Email Service

Your controller expects an IEmailService with a method SendVerifyEmailAddressNotification(email, token).
This service should generate an email with a verification link (see previous email service answer for patterns).


Step 8: Member Login/Access

Once a user is verified, they can log in (build a similar controller/view model for login, and check emailVerified on login if you want to enforce verification).


Step 9: Summary Table

Step What/Where Why
Member Properties Member Type in Umbraco Backoffice Store verification info per member
ViewModel /ViewModel/RegisterViewModel.cs Enforce validation for input
Partial View /Views/Partials/Register.cshtml Render the registration form
Controller /Controllers/RegisterController.cs Process registration, create member, email
Email Service /Services/EmailService.cs Send verification and notifications
Render Form Template or macro usage Allow placement anywhere needed
Verification Link in email, handled by controller Confirm identity before access

Narrative: How It Works

  1. User fills out the registration form.

  2. The backend validates input and checks for duplicate accounts.

  3. If all checks pass, it creates the member and assigns them a "Normal User" role.

  4. A unique verification token is generated, saved to the member record, and a verification email is sent.

  5. The user clicks the link in their email. If valid, they’re marked as verified in Umbraco.

  6. User can now log in and use the site!


This pattern gives you a secure, scalable, and user-friendly registration workflow in Umbraco 8.

⚠️ **GitHub.com Fallback** ⚠️