File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 33
44namespace IdentityServerHost . Quickstart . UI ;
55
6+ using eShop . Identity . API . Models . AccountViewModels ;
7+
68[ SecurityHeaders ]
79[ AllowAnonymous ]
810public class AccountController : Controller
@@ -33,6 +35,35 @@ public AccountController(
3335 _events = events ;
3436 }
3537
38+ [ HttpGet ]
39+ public IActionResult Register ( )
40+ {
41+ return View ( ) ;
42+ }
43+
44+ [ HttpPost ]
45+ [ ValidateAntiForgeryToken ]
46+ public async Task < IActionResult > Register ( RegisterViewModel model )
47+ {
48+ if ( ModelState . IsValid )
49+ {
50+ var user = new ApplicationUser { UserName = model . Email , Email = model . Email } ;
51+ var result = await _userManager . CreateAsync ( user , model . Password ) ;
52+ if ( result . Succeeded )
53+ {
54+ await _signInManager . SignInAsync ( user , isPersistent : false ) ;
55+ return RedirectToAction ( nameof ( HomeController . Index ) , "Home" ) ;
56+ }
57+ foreach ( var error in result . Errors )
58+ {
59+ ModelState . AddModelError ( string . Empty , error . Description ) ;
60+ }
61+ }
62+
63+ // If we got this far, something failed, redisplay form
64+ return View ( model ) ;
65+ }
66+
3667 /// <summary>
3768 /// Entry point into the login workflow
3869 /// </summary>
@@ -330,4 +361,4 @@ private async Task<LoggedOutViewModel> BuildLoggedOutViewModelAsync(string logou
330361
331362 return vm ;
332363 }
333- }
364+ }
Original file line number Diff line number Diff line change 3737 <p >The default users are alice / bob , password : Pass123 $</p >
3838 </div >
3939 <button class =" btn btn-primary" name =" button" value =" login" >Login </button >
40+ <button class =" btn btn-primary" name =" button" value =" register" asp-action =" Register" >Register </button >
4041 </div >
4142 </form >
4243 </div >
You can’t perform that action at this time.
0 commit comments