Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
CafeCritic
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yevgeniy Agrafenin
CafeCritic
Commits
4e78a832
Commit
4e78a832
authored
Nov 18, 2023
by
Yevgeniy Agrafenin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#2
Добавил контекст базы данных, изменил шаблон главной страницы.
parent
47626667
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
6 deletions
+62
-6
CafeDbContext.cs
CafeCritic/Context/CafeDbContext.cs
+10
-0
Program.cs
CafeCritic/Program.cs
+20
-0
_Layout.cshtml
CafeCritic/Views/Shared/_Layout.cshtml
+29
-6
appsettings.json
CafeCritic/appsettings.json
+3
-0
No files found.
CafeCritic/Context/CafeDbContext.cs
0 → 100644
View file @
4e78a832
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
CafeCritic/Program.cs
View file @
4e78a832
using
CafeCritic.Context
;
using
CafeCritic.Models
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.EntityFrameworkCore
;
var
builder
=
WebApplication
.
CreateBuilder
(
args
);
var
builder
=
WebApplication
.
CreateBuilder
(
args
);
// Add services to the container.
// Add services to the container.
...
@@ -5,6 +10,20 @@ builder.Services.AddControllersWithViews();
...
@@ -5,6 +10,20 @@ builder.Services.AddControllersWithViews();
var
app
=
builder
.
Build
();
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.
// Configure the HTTP request pipeline.
if
(!
app
.
Environment
.
IsDevelopment
())
if
(!
app
.
Environment
.
IsDevelopment
())
{
{
...
@@ -18,6 +37,7 @@ app.UseStaticFiles();
...
@@ -18,6 +37,7 @@ app.UseStaticFiles();
app
.
UseRouting
();
app
.
UseRouting
();
app
.
UseAuthentication
();
app
.
UseAuthorization
();
app
.
UseAuthorization
();
app
.
MapControllerRoute
(
app
.
MapControllerRoute
(
...
...
CafeCritic/Views/Shared/_Layout.cshtml
View file @
4e78a832
<!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"
>
<html
lang=
"en"
>
<head>
<head>
<meta
charset=
"utf-8"
/>
<meta
charset=
"utf-8"
/>
...
@@ -20,11 +26,28 @@
...
@@ -20,11 +26,28 @@
<div
class=
"navbar-collapse collapse d-sm-inline-flex justify-content-between"
>
<div
class=
"navbar-collapse collapse d-sm-inline-flex justify-content-between"
>
<ul
class=
"navbar-nav flex-grow-1"
>
<ul
class=
"navbar-nav flex-grow-1"
>
<li
class=
"nav-item"
>
<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>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-dark"
asp-area=
""
asp-controller=
"Home"
asp-action=
"Privacy"
>
Privacy
</a>
</li>
</li>
@if (User.Identity!.IsAuthenticated)
{
<li
class=
"nav-item"
>
<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>
</ul>
</div>
</div>
</div>
</div>
...
@@ -38,7 +61,7 @@
...
@@ -38,7 +61,7 @@
<footer
class=
"border-top footer text-muted"
>
<footer
class=
"border-top footer text-muted"
>
<div
class=
"container"
>
<div
class=
"container"
>
©
2023 - Cafe
Critic -
<a
asp-area=
""
asp-controller=
"Home"
asp-action=
"Privacy"
>
Privacy
</a>
©
2023 - Cafe
Critic
</div>
</div>
</footer>
</footer>
<script
src=
"~/lib/jquery/dist/jquery.min.js"
></script>
<script
src=
"~/lib/jquery/dist/jquery.min.js"
></script>
...
...
CafeCritic/appsettings.json
View file @
4e78a832
{
{
"ConnectionStrings"
:
{
"DefaultConnection"
:
"Server=127.0.0.1;Port=5432;Database=CafeCritic;User Id=postgres;Password=attractor01"
},
"Logging"
:
{
"Logging"
:
{
"LogLevel"
:
{
"LogLevel"
:
{
"Default"
:
"Information"
,
"Default"
:
"Information"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment