Skip to content

Commit 4e40dc9

Browse files
committed
Place holders.
1 parent c46702f commit 4e40dc9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Identity.API/Quickstart/Account/AccountController.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace IdentityServerHost.Quickstart.UI;
55

6+
using eShop.Identity.API.Models.AccountViewModels;
7+
68
[SecurityHeaders]
79
[AllowAnonymous]
810
public 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+
}

Identity.API/Views/Account/Login.cshtml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
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>

0 commit comments

Comments
 (0)