0

Please or Register to create posts and topics.

How do build a page around this?

How do I build websites that use this application for user management? Should I be developing as a separate project under the same solution? Is there some code I need to include in my pages?

Hello Jeremy. This is a startup template. That means it is the starting point of your application. Except that it has some common code used in applications already implemented for you (Such as user management).

So how you go about it is take a fresh copy of the template, and build/program on top of it. Changing features and adding to it. Ultimately this is there to guide you and get you started up quickly rather than starting from scratch.

I'm very new to user management and only have ~2 websites worth of experience with MVC. I'm used to making pages by adding action results to a controller. When I make a new view using '_Layout.cshtml' as the template it comes with no formatting. Am I able to build pages using your layout? If I make my own layout how do I include a login/register link that will interact with your user management?

In the simplest form you can add the below code to your AccountController.

This will expose a "public/register" endpoint you can call from your UI to add new users.

Note that this endpoint overrides the user's role property to force every added user to the "user" role. Start from here and tweak it to your scenario.

        [HttpPost("public/register")]
        [AllowAnonymous]
        public async Task<IActionResult> SignUp([FromBodyUserEditViewModel user)
        {
            user.Roles = new[] { "user" };
 
 
            if (ModelState.IsValid)
            {
                if (user == null)
                    return BadRequest($"{nameof(user)} cannot be null"); 
 
                ApplicationUser appUser = Mapper.Map<ApplicationUser>(user); 
                var result = await _accountManager.CreateUserAsync(appUser, user.Roles, user.NewPassword);
                if (result.Item1)
                {
                    UserViewModel userVM = await GetUserViewModelHelper(appUser.Id);
                    return CreatedAtAction(GetUserByIdActionName, new { id = userVM.Id }, userVM);
                }
 
                AddErrors(result.Item2);
            }
             return BadRequest(ModelState);
        }