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.


Step 1: Extract and Scan for Account-Related Code

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.


Step 2: Review AccountViewModel.cs

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)


Step 3: Review AccountController.cs

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.


📝 Step-by-Step: "My Account" (Profile) Management in Umbraco 8

(With code and best practices from your project)


Step 1: Ensure Member Type Has the Required Fields

  • 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.


Step 2: Create the Account ViewModel

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)


Step 3: Create "My Account" Partial View

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> }


Step 4: Controller Logic

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.


Step 5: Render "My Account" on the Site

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.


Step 6: Security Best Practices

  • 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).


Step 7: User Experience

  • 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 and ModelState messages.


Step 8: Summary Table

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

Step 9: Extending the Profile

  • 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.


Narrative Flow: How “My Account” Works

  1. User logs in and accesses the My Account/Profile page.

  2. The site loads their data from Umbraco’s Members system.

  3. The user can edit their name/email and submit, or set a new password.

  4. The backend validates, saves, and confirms changes.

  5. 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!

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