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.
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.
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.
-
(Based on your real code and best practices)
-
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.
File: /Core/ViewModel/RegisterViewModel.cs
Already provided above; handles all fields and validation.
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>
}
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.
-
-
The member receives an email with a link containing the token.
-
When they visit this link, the
RenderEmailVerificationaction marks them as verified (setsemailVerifiedto true, and the date).
Example verification link:
https://yourdomain.com/verify/?token=abcdef12345
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.
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).
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 | 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 |
-
User fills out the registration form.
-
The backend validates input and checks for duplicate accounts.
-
If all checks pass, it creates the member and assigns them a "Normal User" role.
-
A unique verification token is generated, saved to the member record, and a verification email is sent.
-
The user clicks the link in their email. If valid, they’re marked as verified in Umbraco.
-
User can now log in and use the site!
This pattern gives you a secure, scalable, and user-friendly registration workflow in Umbraco 8.