diff --git a/src/IdentitySvc/Pages/Account/Login/Index.cshtml b/src/IdentitySvc/Pages/Account/Login/Index.cshtml index c40a6e9..a45f6dc 100644 --- a/src/IdentitySvc/Pages/Account/Login/Index.cshtml +++ b/src/IdentitySvc/Pages/Account/Login/Index.cshtml @@ -2,10 +2,6 @@ @model IdentitySvc.Pages.Login.Index
-
-

Login

-

Choose how to login

-
@@ -13,10 +9,10 @@ @if (Model.View.EnableLocalLogin) { -
+
-

Local Account

+

Login

@@ -44,6 +40,10 @@
} + + New User? Register here + + diff --git a/src/IdentitySvc/Pages/Account/Register/Index.cshtml b/src/IdentitySvc/Pages/Account/Register/Index.cshtml new file mode 100644 index 0000000..85c6a29 --- /dev/null +++ b/src/IdentitySvc/Pages/Account/Register/Index.cshtml @@ -0,0 +1,64 @@ +@page +@model IdentitySvc.Pages.Register.Index + + + + + + + + +
+ + +
+
+
+
+

Register

+
+
+
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + Already Regitered? Login here + + + + +
+
+ + @if (Model.RegisterSuccess) + { +
+ Successfully registered - You can now login +
+ } +
+
+
+
+ + \ No newline at end of file diff --git a/src/IdentitySvc/Pages/Account/Register/Index.cshtml.cs b/src/IdentitySvc/Pages/Account/Register/Index.cshtml.cs new file mode 100644 index 0000000..71213f1 --- /dev/null +++ b/src/IdentitySvc/Pages/Account/Register/Index.cshtml.cs @@ -0,0 +1,66 @@ +using System.Security.Claims; +using IdentityModel; +using IdentitySvc.Models; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace IdentitySvc.Pages.Register; + +[SecurityHeaders] +[AllowAnonymous] + +public class Index : PageModel +{ + private readonly UserManager _userManager; + + public Index(UserManager userManager) + { + _userManager = userManager; + } + + [BindProperty] + public RegisterViewModel Input { get; set; } + [BindProperty] + public bool RegisterSuccess { get; set; } + + public IActionResult OnGet(string returnUrl) + { + Input = new RegisterViewModel + { + ReturnUrl = returnUrl, + }; + + return Page(); + } + + public async Task OnPost() + { + if (Input.Button != "register") return Redirect("~/"); + + if (ModelState.IsValid) + { + var user = new ApplicationUser + { + UserName = Input.Username, + Email = Input.Email, + EmailConfirmed = true, + }; + + var result = await _userManager.CreateAsync(user, Input.Password); + + if (result.Succeeded) + { + await _userManager.AddClaimsAsync(user, new Claim[] + { + new Claim(JwtClaimTypes.Name, Input.FullName) + }); + + RegisterSuccess = true; + } + } + + return Page(); + } +} \ No newline at end of file diff --git a/src/IdentitySvc/Pages/Account/Register/RegisterViewModel.cs b/src/IdentitySvc/Pages/Account/Register/RegisterViewModel.cs new file mode 100644 index 0000000..e172947 --- /dev/null +++ b/src/IdentitySvc/Pages/Account/Register/RegisterViewModel.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; + +namespace IdentitySvc.Pages.Register; + +public class RegisterViewModel +{ + [Required] + public string Email { get; set; } + [Required] + public string Password { get; set; } + [Required] + public string Username { get; set; } + [Required] + public string FullName { get; set; } + + public string ReturnUrl { get; set; } + public string Button { get; set; } +} \ No newline at end of file diff --git a/src/IdentitySvc/Pages/Shared/_Nav.cshtml b/src/IdentitySvc/Pages/Shared/_Nav.cshtml index e678cf1..3f1fdc2 100644 --- a/src/IdentitySvc/Pages/Shared/_Nav.cshtml +++ b/src/IdentitySvc/Pages/Shared/_Nav.cshtml @@ -13,7 +13,7 @@ - Duende IdentityServer + Optifit Identity SSO @if (!string.IsNullOrWhiteSpace(name))