IMPORTANT!
This forum is now archived. Click here for the New Support Forum
How do build a page around this?
Quote from Jeremy T on January 11, 2018, 4:57 pmHow 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?
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?
Quote from Eben Monney on January 15, 2018, 11:31 amHello 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.
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.
Quote from Jeremy T on January 17, 2018, 3:04 pmI'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?
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?
Quote from Eben Monney on January 18, 2018, 5:06 amIn 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([FromBody] UserEditViewModel 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); }
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([FromBody] UserEditViewModel 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); }
IMPORTANT!
This forum is now archived. Click here for the New Support Forum