aboutsummaryrefslogtreecommitdiff
path: root/ExamTemplate/Web/Startup.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-05-08 18:10:08 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-05-08 18:10:08 +0300
commit82d270a66b8ffca28e321f29b2eb90b2412ac9a7 (patch)
treebd7e985592a0d8d5ec31b590b3c52d403e17e140 /ExamTemplate/Web/Startup.cs
parenta1e46b76a1299e35b1ac8cae69e77c66d74224a6 (diff)
downloadit-kariera-exam-template-82d270a66b8ffca28e321f29b2eb90b2412ac9a7.tar
it-kariera-exam-template-82d270a66b8ffca28e321f29b2eb90b2412ac9a7.tar.gz
it-kariera-exam-template-82d270a66b8ffca28e321f29b2eb90b2412ac9a7.zip
Implemented authorization; Replaced Role with IdentityRole<Guid>; Renamed UserController to AccountController, updated links
Diffstat (limited to 'ExamTemplate/Web/Startup.cs')
-rw-r--r--ExamTemplate/Web/Startup.cs31
1 files changed, 20 insertions, 11 deletions
diff --git a/ExamTemplate/Web/Startup.cs b/ExamTemplate/Web/Startup.cs
index 0754bff..00d94c0 100644
--- a/ExamTemplate/Web/Startup.cs
+++ b/ExamTemplate/Web/Startup.cs
@@ -1,5 +1,6 @@
using System;
using System.Linq;
+using ExamTemplate.Common;
using ExamTemplate.Data;
using ExamTemplate.Data.Models;
using ExamTemplate.Services;
@@ -11,9 +12,8 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-namespace Web
{
- public class Startup
+ public class Startup
{
public Startup(IConfiguration configuration)
{
@@ -41,10 +41,19 @@ namespace Web
options.UseNpgsql(this.Configuration.GetConnectionString("LocalDBConnection")));
// Needed for SignInManager and UserManager
- services.AddIdentity<User, Role>()
- .AddRoles<Role>()
+ services.AddIdentity<User, IdentityRole<Guid>>(options =>
+ {
+ options.SignIn.RequireConfirmedAccount = false;
+
+ // Password settings
+ options.Password.RequireDigit = false;
+ options.Password.RequireLowercase = false;
+ options.Password.RequireNonAlphanumeric = false;
+ options.Password.RequireUppercase = false;
+ options.Password.RequiredLength = 3;
+ options.Password.RequiredUniqueChars = 0;
+ }).AddRoles<IdentityRole<Guid>>()
.AddEntityFrameworkStores<TemplateContext>();
-
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -65,8 +74,8 @@ namespace Web
app.UseRouting();
- app.UseAuthorization();
app.UseAuthentication();
+ app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
@@ -85,15 +94,15 @@ namespace Web
dbContext.Database.Migrate();
- var roleManager = (RoleManager<Role>)serviceScope.ServiceProvider.GetService(typeof(RoleManager<Role>));
- if (!dbContext.Roles.Any(x => x.Name == Role.UserRole))
+ var roleManager = (RoleManager<IdentityRole<Guid>>)serviceScope.ServiceProvider.GetService(typeof(RoleManager<IdentityRole<Guid>>));
+ if (!dbContext.Roles.Any(x => x.Name == RoleConst.User))
{
- Role userRole = new() { Name = Role.UserRole };
+ IdentityRole<Guid> userRole = new() { Name = RoleConst.User };
roleManager.CreateAsync(userRole).Wait();
}
- if (!dbContext.Roles.Any(x => x.Name == Role.AdminRole))
+ if (!dbContext.Roles.Any(x => x.Name == RoleConst.Admin))
{
- Role adminRole = new() { Name = Role.AdminRole };
+ IdentityRole<Guid> adminRole = new() { Name = RoleConst.Admin };
roleManager.CreateAsync(adminRole).Wait();
}