Account - FadiZahhar/umbraco8showandtell GitHub Wiki
You’d like a narrative, step-by-step tutorial focused on account management (member account/profile) in Umbraco 8, using the logic from your HighlyDeveloped.Core
code. I’ll extract, scan for relevant “account” code (controller/viewmodel), then walk you through how to implement a user profile/account area following your project’s approach.
Your account management logic is in:
-
ViewModel/AccountViewModel.cs
-
Controllers/AccountController.cs
Let’s break these down, then write you a best-practice, step-by-step guide for user profile/account management in Umbraco 8.
Your AccountViewModel
is designed for a "My Account" or profile page and includes:
-
Name (required)
-
Email (required, email format)
-
Username (readonly/display only)
-
Password and ConfirmPassword (for password change, with validation)
Now let’s look at the logic for displaying and updating account information.
Your AccountController
provides robust profile/account management for logged-in Umbraco members:
-
RenderMyAccount:
-
Checks if the member is logged in.
-
Fetches their details (name, email, username) and populates the view model.
-
-
HandleUpdateDetails:
-
Validates the form.
-
Updates the member’s name and email if logged in.
-
Saves changes and returns confirmation.
-
-
HandlePasswordChange:
-
Validates the form.
-
Checks the member is logged in.
-
Attempts to change the password.
-
Shows success or error feedback.
-
(With code and best practices from your project)
-
In Umbraco Backoffice > Members > Member Types ("Member"), make sure the standard properties (Name, Email, Username, Password) exist.
-
Optionally, add any custom profile fields you want your users to manage.
File: /ViewModel/AccountViewModel.cs
(You already have this)
-
Name (required)
-
Email (required, email format)
-
Username (read-only)
-
Password & ConfirmPassword (for changing password, not required for detail changes)
File: /Views/Partials/MyAccount/MyAccount.cshtml
@model HighlyDeveloped.Core.ViewModel.AccountViewModel
@using (Html.BeginUmbracoForm("HandleUpdateDetails", "Account"))
{
@Html.AntiForgeryToken()
<div class="form-group">
@Html.LabelFor(m => m.Name)
@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Email)
</div>
<div class="form-group">
@Html.LabelFor(m => m.Username)
@Html.TextBoxFor(m => m.Username, new { @class = "form-control", @readonly = "readonly" })
</div>
<button type="submit" class="btn btn-primary">Update Details</button>
}
@if (TempData["status"] != null && TempData["status"].ToString() == "Updated Details")
{
<div class="alert alert-success">Your details were updated!</div>
}
<hr/>
@using (Html.BeginUmbracoForm("HandlePasswordChange", "Account"))
{
@Html.AntiForgeryToken()
<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-warning">Change Password</button>
}
@if (TempData["status"] != null && TempData["status"].ToString() == "Updated Password")
{
<div class="alert alert-success">Your password was updated!</div>
}
@Html.ValidationSummary(true)
@if (!User.Identity.IsAuthenticated)
{
<div class="alert alert-danger">You must be logged in to manage your account.</div>
}
File: /Controllers/AccountController.cs
-
RenderMyAccount:
-
Loads the current logged-in member, populates and returns the view model.
-
-
HandleUpdateDetails:
-
Only updates details if the model is valid and the user is logged in.
-
-
HandlePasswordChange:
-
Validates new password (min length, matches confirm).
-
Saves the new password securely.
-
-
All methods return the user to the current page with success/error messages.
In your "My Account" or "Profile" page template:
@Html.Action("RenderMyAccount", "Account")
-
This will load the form with the logged-in user’s details and let them update or change their password.
-
All account actions are protected with
[ValidateAntiForgeryToken]
and check the user is authenticated. -
The password is never shown or stored in plain text.
-
Username is read-only (not editable for security and consistency).
-
The user logs in, then can access the "My Account" page.
-
They can update their name and email, and set a new password if desired.
-
If not logged in, they see a clear error.
-
Feedback for successful or failed updates is shown with
TempData
andModelState
messages.
Step | What/Where | Why |
---|---|---|
ViewModel | /ViewModel/AccountViewModel.cs | Structure/profile validation |
Partial View | /Views/Partials/MyAccount/MyAccount.cshtml | Edit details & password |
Controller | /Controllers/AccountController.cs | Handles all update logic |
Render Form | Page template | Place profile anywhere needed |
-
To add more fields (e.g. address, bio, phone), add them to both the Member Type and AccountViewModel, and update the controller and view accordingly.
-
For GDPR or privacy compliance, consider adding an "account delete" request or export data option.
-
User logs in and accesses the My Account/Profile page.
-
The site loads their data from Umbraco’s Members system.
-
The user can edit their name/email and submit, or set a new password.
-
The backend validates, saves, and confirms changes.
-
All updates are secure, with feedback for the user.
You now have a robust, secure, and extensible profile/account area for your Umbraco 8 site!