-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
120 lines (104 loc) · 3.87 KB
/
Program.cs
File metadata and controls
120 lines (104 loc) · 3.87 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using TiAchei_Tcc.Db;
using TiAchei_Tcc.Models;
using TiAchei_Tcc.Repository;
using TiAchei_Tcc.Repository.Interfaces;
using TiAchei_Tcc.Services;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnetion");
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<AppDbContextMysql>(x => x.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
builder.Services.AddIdentity<User, IdentityRole>(x =>
{
x.Password.RequiredLength = 5;
x.Password.RequireLowercase = false;
x.Password.RequireUppercase = false;
x.Password.RequireNonAlphanumeric = false;
x.Password.RequireDigit = false;
x.User.RequireUniqueEmail = true;
x.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._@+~ ";
})
.AddEntityFrameworkStores<AppDbContextMysql>()
.AddDefaultTokenProviders();
builder.Services.ConfigureApplicationCookie(options =>
{
options.AccessDeniedPath = "/Identity/Account/AccessDenied";
options.Cookie.Name = "cookieLogin";
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
options.LoginPath = "/User/Login";
options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
options.SlidingExpiration = true;
});
builder.Services.AddScoped<IPetRepository, PetRepository>();
builder.Services.AddScoped<IPessoaRepository, PessoaRepository>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<ServiceUploadFile>();
var app = builder.Build();
if(!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoit =>
{
endpoit.MapDefaultControllerRoute();
endpoit.MapControllerRoute(
name: "editar",
pattern: "Painel/Editar/{id?}",
defaults: new { Controller = "Painel", Action = "Editar"}
);
endpoit.MapControllerRoute(
name: "editarpessoa",
pattern: "Painel/EditarPessoa/{id?}",
defaults: new { Controller = "Painel", Action = "EditarPessoa"}
);
endpoit.MapControllerRoute(
name: "cardfiltro",
pattern: "Card/Perfil/{id?}",
defaults: new { Controller = "Card", Action = "Perfil"}
);
endpoit.MapControllerRoute(
name: "cardfiltropessoa",
pattern: "Card/PerfilPessoa/{id?}",
defaults: new { Controller = "Card", Action = "PerfilPessoa"}
);
endpoit.MapControllerRoute(
name: "buscarid",
pattern: "Painel/buscar/{id?}",
defaults: new { Controller = "Painel", Action = "Buscar"}
);
endpoit.MapControllerRoute(
name: "deletarid",
pattern: "Painel/deletar/{id?}",
defaults: new { Controller = "Painel", Action = "Deletar"}
);
endpoit.MapControllerRoute(
name: "qrcodeid",
pattern: "Painel/QrCode/{id?}",
defaults: new { Controller = "Painel", Action = "Qrcode"}
);
endpoit.MapControllerRoute(
name: "imgqrcodeid",
pattern: "ImgQrCode/{id?}",
defaults: new { Controller = "ImgQrCode", Action = "Index"}
);
endpoit.MapControllerRoute(
name: "imgqrcodepessoaid",
pattern: "ImgQrCode/pessoa/{id?}",
defaults: new { Controller = "ImgQrCode", Action = "Pessoa"}
);
endpoit.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}"
);
}
);
app.Run();