Commit 4e78a832 authored by Yevgeniy Agrafenin's avatar Yevgeniy Agrafenin

#2 Добавил контекст базы данных, изменил шаблон главной страницы.

parent 47626667
using CafeCritic.Models;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace CafeCritic.Context;
public class CafeDbContext: IdentityDbContext<User>
{
CafeDbContext(DbContextOptions options) : base(options){}
}
\ No newline at end of file
using CafeCritic.Context;
using CafeCritic.Models;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
......@@ -5,6 +10,20 @@ builder.Services.AddControllersWithViews();
var app = builder.Build();
var connectionString = builder.Configuration
.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<CafeDbContext>(options => options.UseNpgsql(connectionString)).AddIdentity<User, IdentityRole>(
o =>
{
o.User.RequireUniqueEmail = true;
o.Password.RequiredLength = 6;
o.Password.RequireNonAlphanumeric = false;
o.Password.RequireLowercase = false;
o.Password.RequireUppercase = false;
o.Password.RequireDigit = false;
}).AddEntityFrameworkStores<CafeDbContext>();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
......@@ -18,6 +37,7 @@ app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
......
<!DOCTYPE html>
@using Microsoft.AspNetCore.Identity
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject UserManager<User> UserManager;
@{
var user = await UserManager.GetUserAsync(User);
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
......@@ -20,11 +26,28 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Cafe Critic</a>
</li>
@if (User.Identity!.IsAuthenticated)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
<span class="nav-link text-dark">Привет - @user.Email</span>
</li>
<li class="nav-item">
<form asp-action="LogOut" asp-controller="Account" method="post">
<button type="submit" class="btn btn-dark">Выйти</button>
</form>
</li>
}
else
{
<li class="nav-item">
<a class="nav-link text-dark" asp-action="Login" asp-controller="Account">Войти</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-action="Register" asp-controller="Account">Зарегистрироваться</a>
</li>
}
</ul>
</div>
</div>
......@@ -38,7 +61,7 @@
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2023 - CafeCritic - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
&copy; 2023 - Cafe Critic
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
......
{
"ConnectionStrings": {
"DefaultConnection" : "Server=127.0.0.1;Port=5432;Database=CafeCritic;User Id=postgres;Password=attractor01"
},
"Logging": {
"LogLevel": {
"Default": "Information",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment