-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
92 lines (69 loc) · 3.43 KB
/
Copy pathProgram.cs
File metadata and controls
92 lines (69 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using MovieProject.Data;
using MovieProject.Models;
var builder = WebApplication.CreateBuilder(args);
// We tell the system where to store the language files (Resources)
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
// We are integrating multilingual support (for Views and DataAnnotations) into the MVC architecture
builder.Services.AddControllersWithViews()
.AddViewLocalization()
.AddDataAnnotationsLocalization(options => {
options.DataAnnotationLocalizerProvider = (type, factory) =>
factory.Create(typeof(MovieProject.SharedResource));
});
//--DATABASE CONNECTION (PostgreSQL)--
//We locate and retrieve the encrypted address named "DefaultConnection" from the appsettings.json file.
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
//We're adding our AppDbContext bridge to the system so it uses PostgreSQL
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(connectionString));
//--IDENTITY AND MEMBERSHIP SYSTEM--
builder.Services.AddIdentity<AppUser, IdentityRole>(options =>
{
// PASSWORD RULES
options.Password.RequireDigit = true; // The password must contain at least 1 digit (0-9)
options.Password.RequiredLength = 8; // The password must be at least 8 characters long
options.Password.RequireUppercase = true; // At least 1 uppercase letter is required
options.Password.RequireLowercase = true; // At least 1 lowercase letter is required
options.Password.RequireNonAlphanumeric = false; // Special characters (@, #, !) should not be required
// USER/EMAIL RULES
options.User.RequireUniqueEmail = true; // Prevent users from registering twice with the same email address
options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+"; // Valid characters in a username
})
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
var app = builder.Build();
//Seed Data
//Every time the application runs, it opens a temporary scope and performs a seeding check
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
await SeedData.Initialize(services);
}
//--HTTP REQUEST LINE--
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles(); //It allows css, js and image files in the wwwroot folder to be accessible externally
// Languages supported by the site: Turkish and English
var supportedCultures = new[] { "en-US", "tr-TR" };
var localizationOptions = new RequestLocalizationOptions()
.SetDefaultCulture(supportedCultures[0]) // The site's default language is Turkish
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
app.UseRequestLocalization(localizationOptions);
app.UseRouting();
//ID VERIFICATION (Is the user logged in?)
app.UseAuthentication();
//AUTHORIZATION (Does the user have permission/role to access this page?)
app.UseAuthorization();
//We are setting the URL path for the site's default home page (Home/Index)
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
app.Run();