Skip to content

Commit ff7c14d

Browse files
committed
Add simle UI and logic to Identity
1 parent ccd1215 commit ff7c14d

16 files changed

+204
-140
lines changed

src/CoinyProject.Infrastructure.Data/ConnectionExtensions.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ namespace CoinyProject.Infrastructure.Data
1212
{
1313
public static class ConnectionExtensions
1414
{
15-
public static void AddDBConnection(this IServiceCollection services, IConfiguration configuration)
15+
public static void AddDBConnection(this IServiceCollection service, IConfiguration configuration)
1616
{
17-
services.AddDbContext<ApplicationDBContext>(options =>
17+
IServiceCollection serviceCollection = service.AddDbContext<ApplicationDBContext>(options =>
1818
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
1919

20-
services.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = false)
21-
.AddEntityFrameworkStores<ApplicationDBContext>();
2220
}
2321
}
2422

src/CoinyProject.Infrastructure.Data/Migrations/ApplicationDBContextModelSnapshot.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
5151

5252
b.HasIndex("UserId");
5353

54-
b.ToTable("Albums");
54+
b.ToTable("Albums", (string)null);
5555
});
5656

5757
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.AlbumElement", b =>
@@ -81,7 +81,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
8181

8282
b.HasIndex("AlbumId");
8383

84-
b.ToTable("AlbumElements");
84+
b.ToTable("AlbumElements", (string)null);
8585
});
8686

8787
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.Auction", b =>
@@ -117,7 +117,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
117117
b.HasIndex("AlbumElementId")
118118
.IsUnique();
119119

120-
b.ToTable("Auctions");
120+
b.ToTable("Auctions", (string)null);
121121
});
122122

123123
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.AuctionBet", b =>
@@ -144,7 +144,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
144144

145145
b.HasIndex("UserId");
146146

147-
b.ToTable("AuctionBets");
147+
b.ToTable("AuctionBets", (string)null);
148148
});
149149

150150
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.Discussion", b =>
@@ -175,7 +175,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
175175

176176
b.HasIndex("UserId");
177177

178-
b.ToTable("Discussions");
178+
b.ToTable("Discussions", (string)null);
179179
});
180180

181181
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.DiscussionMessage", b =>
@@ -202,7 +202,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
202202

203203
b.HasIndex("UserId");
204204

205-
b.ToTable("DiscussionMessages");
205+
b.ToTable("DiscussionMessages", (string)null);
206206
});
207207

208208
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.DiscussionTopic", b =>
@@ -220,7 +220,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
220220

221221
b.HasKey("Id");
222222

223-
b.ToTable("DiscussionTopics");
223+
b.ToTable("DiscussionTopics", (string)null);
224224
});
225225

226226
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.FavoriteAlbums", b =>
@@ -244,7 +244,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
244244

245245
b.HasIndex("UserId");
246246

247-
b.ToTable("FavoriteAlbums");
247+
b.ToTable("FavoriteAlbums", (string)null);
248248
});
249249

250250
modelBuilder.Entity("CoinyProject.Core.Domain.Entities.User", b =>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using CoinyProject.Core.Domain.Entities;
2+
using CoinyProject.Infrastructure.Data;
3+
using Microsoft.AspNetCore.Identity;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
namespace CoinyProject.WebUI.Areas.Identity
7+
{
8+
public static class IdentityExtensions
9+
{
10+
public static void AddIdentityUser(this IServiceCollection service)
11+
{
12+
service.AddDefaultIdentity<User>(options => options.SignIn.RequireConfirmedAccount = false)
13+
.AddEntityFrameworkStores<ApplicationDBContext>();
14+
}
15+
16+
public static void ConfigurateIdentityOptions(this IServiceCollection service)
17+
{
18+
service.Configure<IdentityOptions>(options =>
19+
{
20+
options.Password.RequiredLength = 8;
21+
options.Password.RequireUppercase = false;
22+
});
23+
}
24+
}
25+
}

src/CoinyProject.WebUI/Areas/Identity/Pages/Account/Login.cshtml

+4-45
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
@{
55
ViewData["Title"] = "Log in";
6+
Layout = "~/Areas/Identity/Pages/_AuthLayout.cshtml";
67
}
78

8-
<h1>@ViewData["Title"]</h1>
9-
<div class="row">
10-
<div class="col-md-4">
9+
<div class="row justify-content-center">
10+
<div class="col-10">
1111
<section>
1212
<form id="account" method="post">
13-
<h2>Use a local account to log in.</h2>
13+
<h2 class="row justify-content-center">Welcome Back</h2>
1414
<hr />
1515
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
1616
<div class="form-floating mb-3">
@@ -32,50 +32,9 @@
3232
<div>
3333
<button id="login-submit" type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
3434
</div>
35-
<div>
36-
<p>
37-
<a id="forgot-password" asp-page="./ForgotPassword">Forgot your password?</a>
38-
</p>
39-
<p>
40-
<a asp-page="./Register" asp-route-returnUrl="@Model.ReturnUrl">Register as a new user</a>
41-
</p>
42-
<p>
43-
<a id="resend-confirmation" asp-page="./ResendEmailConfirmation">Resend email confirmation</a>
44-
</p>
45-
</div>
4635
</form>
4736
</section>
4837
</div>
49-
<div class="col-md-6 col-md-offset-2">
50-
<section>
51-
<h3>Use another service to log in.</h3>
52-
<hr />
53-
@{
54-
if ((Model.ExternalLogins?.Count ?? 0) == 0)
55-
{
56-
<div>
57-
<p>
58-
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
59-
about setting up this ASP.NET application to support logging in via external services</a>.
60-
</p>
61-
</div>
62-
}
63-
else
64-
{
65-
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
66-
<div>
67-
<p>
68-
@foreach (var provider in Model.ExternalLogins!)
69-
{
70-
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
71-
}
72-
</p>
73-
</div>
74-
</form>
75-
}
76-
}
77-
</section>
78-
</div>
7938
</div>
8039

8140
@section Scripts {

src/CoinyProject.WebUI/Areas/Identity/Pages/Account/Login.cshtml.cs

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Linq;
99
using System.Threading.Tasks;
1010
using Microsoft.AspNetCore.Authorization;
11+
using CoinyProject.Core.Domain.Entities;
1112
using Microsoft.AspNetCore.Authentication;
1213
using Microsoft.AspNetCore.Identity;
1314
using Microsoft.AspNetCore.Identity.UI.Services;
@@ -19,10 +20,10 @@ namespace CoinyProject.WebUI.Areas.Identity.Pages.Account
1920
{
2021
public class LoginModel : PageModel
2122
{
22-
private readonly SignInManager<IdentityUser> _signInManager;
23+
private readonly SignInManager<User> _signInManager;
2324
private readonly ILogger<LoginModel> _logger;
2425

25-
public LoginModel(SignInManager<IdentityUser> signInManager, ILogger<LoginModel> logger)
26+
public LoginModel(SignInManager<User> signInManager, ILogger<LoginModel> logger)
2627
{
2728
_signInManager = signInManager;
2829
_logger = logger;
@@ -86,6 +87,10 @@ public class InputModel
8687

8788
public async Task OnGetAsync(string returnUrl = null)
8889
{
90+
if (User.Identity.IsAuthenticated)
91+
{
92+
Response.Redirect("/");
93+
}
8994
if (!string.IsNullOrEmpty(ErrorMessage))
9095
{
9196
ModelState.AddModelError(string.Empty, ErrorMessage);

src/CoinyProject.WebUI/Areas/Identity/Pages/Account/Register.cshtml

+33-52
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,47 @@
22
@model RegisterModel
33
@{
44
ViewData["Title"] = "Register";
5+
Layout = "~/Areas/Identity/Pages/_AuthLayout.cshtml";
56
}
67

7-
<h1>@ViewData["Title"]</h1>
8-
9-
<div class="row">
10-
<div class="col-md-4">
11-
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
12-
<h2>Create a new account.</h2>
13-
<hr />
14-
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
15-
<div class="form-floating mb-3">
16-
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
17-
<label asp-for="Input.Email">Email</label>
18-
<span asp-validation-for="Input.Email" class="text-danger"></span>
19-
</div>
8+
<form id="registerForm" asp-route-returnUrl="@Model.ReturnUrl" method="post">
9+
<h2 class="row justify-content-center">New Account</h2>
10+
<hr />
11+
<div asp-validation-summary="ModelOnly" class="text-danger" role="alert"></div>
12+
<div class="row">
13+
<div class="col-6">
2014
<div class="form-floating mb-3">
21-
<input asp-for="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
22-
<label asp-for="Input.Password">Password</label>
23-
<span asp-validation-for="Input.Password" class="text-danger"></span>
15+
<input asp-for="Input.FirstName" class="form-control" autocomplete="firstname" aria-required="true" placeholder="first name" />
16+
<label asp-for="Input.FirstName">First Name</label>
17+
<span asp-validation-for="Input.FirstName" class="text-danger"></span>
2418
</div>
19+
</div>
20+
<div class="col-6">
2521
<div class="form-floating mb-3">
26-
<input asp-for="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
27-
<label asp-for="Input.ConfirmPassword">Confirm Password</label>
28-
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
22+
<input asp-for="Input.LastName" class="form-control" autocomplete="lastname" aria-required="true" placeholder="last name" />
23+
<label asp-for="Input.LastName">Last Name</label>
24+
<span asp-validation-for="Input.LastName" class="text-danger"></span>
2925
</div>
30-
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
31-
</form>
26+
</div>
3227
</div>
33-
<div class="col-md-6 col-md-offset-2">
34-
<section>
35-
<h3>Use another service to register.</h3>
36-
<hr />
37-
@{
38-
if ((Model.ExternalLogins?.Count ?? 0) == 0)
39-
{
40-
<div>
41-
<p>
42-
There are no external authentication services configured. See this <a href="https://go.microsoft.com/fwlink/?LinkID=532715">article
43-
about setting up this ASP.NET application to support logging in via external services</a>.
44-
</p>
45-
</div>
46-
}
47-
else
48-
{
49-
<form id="external-account" asp-page="./ExternalLogin" asp-route-returnUrl="@Model.ReturnUrl" method="post" class="form-horizontal">
50-
<div>
51-
<p>
52-
@foreach (var provider in Model.ExternalLogins!)
53-
{
54-
<button type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
55-
}
56-
</p>
57-
</div>
58-
</form>
59-
}
60-
}
61-
</section>
28+
<div class="form-floating mb-3">
29+
<input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true" placeholder="name@example.com" />
30+
<label asp-for="Input.Email">Email</label>
31+
<span asp-validation-for="Input.Email" class="text-danger"></span>
6232
</div>
63-
</div>
64-
33+
<div class="form-floating mb-3">
34+
<input asp-for="Input.Password" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
35+
<label asp-for="Input.Password">Password</label>
36+
<span asp-validation-for="Input.Password" class="text-danger"></span>
37+
</div>
38+
<div class="form-floating mb-3">
39+
<input asp-for="Input.ConfirmPassword" class="form-control" autocomplete="new-password" aria-required="true" placeholder="password" />
40+
<label asp-for="Input.ConfirmPassword">Confirm Password</label>
41+
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
42+
</div>
43+
<button id="registerSubmit" type="submit" class="w-100 btn btn-lg btn-primary">Register</button>
44+
</form>
45+
6546
@section Scripts {
6647
<partial name="_ValidationScriptsPartial" />
6748
}

0 commit comments

Comments
 (0)