Create User
For visitors to create a user and activate it by email
The Create User app makes it possible for visitors to create a user from the frontend and activate it from their email:
You must:
- Select a Create user template
- Set Email settings:
- Email template
- Sender name field
- Sender email field
- Email subject field
- Select a Redirect after approval page
Create user template
The Create user template should inherit the CreateUserViewModel, and use the Dynamicweb.Rendering and Dynamicweb.Users.Frontend namespaces.
Create a form with properties from the ViewModel that displays the necessary user information the user should be able to fill - usually that would be: username, email, password and confirm password. To execute a creation of a user submit an URL with the UserCmd=createuser, you should also check that the user information is correct otherwise inform the visitor:
@inherits ViewModelTemplate<CreateUserViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Users.Frontend
<!-- Create the URL with the UserCmd -->
@{
string createUserLink = $"/Default.aspx?ID={Pageview.Page.ID}&UserCmd=createuser";
}
<!-- Create a form that displays properties from the ViewModel-->
<form action="@createUserLink" method="post">
<input type="hidden" name="ID" value="@Pageview.ID">
<input type="text" placeholder="UserName" name="UserManagement_Form_UserName" id="UserManagement_Form_UserName" value="@Model.UserName" required>
<label for="Name">UserName</label>
<input type="email" placeholder="Email" name="UserManagement_Form_Email" id="UserManagement_Form_Email" value="@Model.Email" required />
<label for="Email">Email</label>
<input type="password" placeholder="Password" name="UserManagement_Form_Password" id="UserManagement_Form_Password" required>
<label for="Password">Password</label>
<input type="password" placeholder="Confirm Password" name="UserManagement_Form_ConfirmPassword" id="UserManagement_Form_ConfirmPassword" required>
<label for="ConfirmPassword">Confirm Password</label>
<!-- Check the result of the form, if success inform the visitor, if not show error message -->
@if (Model.Result is not null)
{
@if (Model.Result.ResultType.ToString() == "Success")
{
<div>The user has successfully been created!</div>
}
else
{
<div>@Translate(Model.Result.ResultType.ToString())</div>
}
}
<button type="submit" id="CreateUserButton">Create</button>
</form>
Email template
The Email template should inherit the CreateUserViewModel, and use the Dynamicweb.Rendering and Dynamicweb.Users.Frontend namespaces. The email needs to include a link from the ViewModel that the user follows to complete the creation process and activating their user:
@inherits ViewModelTemplate<CreateUserViewModel>
@using Dynamicweb.Rendering
@using Dynamicweb.Users.Frontend
<!--Create a link for the user to activate their user. You can also include other properties you want to display -->
@{
string resultUserName = Model.UserName;
string email = Model.Email;
string approveAccount = Model.ApprovalLink;
}
<h1>Hi and welcome @resultUserName</h1>
<p>Please click the button below to confirm your email @email for your user account </p>
<a href="@approveAccount">Click here and confirm your email</a>