Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
N
NewLifeProject
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
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
Юнусов Ибрагим
NewLifeProject
Commits
85a80e47
Commit
85a80e47
authored
Jul 21, 2022
by
Юнусов Ибрагим
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Заменил самописную регистрацию на IdentityCore и поменял миграции
parent
355dfcbe
Show whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
825 additions
and
418 deletions
+825
-418
AccountsController.cs
NewStores/Store/Controllers/AccountsController.cs
+68
-77
HomeController.cs
NewStores/Store/Controllers/HomeController.cs
+1
-2
ServicesAppExtension.cs
NewStores/Store/Extensions/ServicesAppExtension.cs
+5
-11
20220718152553_Init.Designer.cs
NewStores/Store/Migrations/20220718152553_Init.Designer.cs
+0
-107
20220718152553_Init.cs
NewStores/Store/Migrations/20220718152553_Init.cs
+0
-74
20220721141424_Init.Designer.cs
NewStores/Store/Migrations/20220721141424_Init.Designer.cs
+279
-0
20220721141424_Init.cs
NewStores/Store/Migrations/20220721141424_Init.cs
+221
-0
AppDbContextModelSnapshot.cs
NewStores/Store/Migrations/AppDbContextModelSnapshot.cs
+208
-36
AppDbContext.cs
NewStores/Store/Models/AppDbContext.cs
+3
-5
Role.cs
NewStores/Store/Models/Users/Role.cs
+0
-13
User.cs
NewStores/Store/Models/Users/User.cs
+4
-7
IUserRepository.cs
NewStores/Store/Repositories/Interfaces/IUserRepository.cs
+0
-11
UserRepository.cs
NewStores/Store/Repositories/UserRepository.cs
+0
-48
Store.csproj
NewStores/Store/Store.csproj
+1
-0
RegisterViewModel.cs
NewStores/Store/ViewModels/Auths/RegisterViewModel.cs
+4
-0
Register.cshtml
NewStores/Store/Views/Accounts/Register.cshtml
+31
-27
No files found.
NewStores/Store/Controllers/AccountsController.cs
View file @
85a80e47
using
System.Security.Claims
;
using
System.Security.Claims
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Authentication
;
using
Microsoft.AspNetCore.Authentication.Cookies
;
using
Microsoft.AspNetCore.Authentication.Cookies
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Mvc
;
using
Store.Models
;
using
Store.Models.Users
;
using
Store.Models.Users
;
using
Store.Repositories.Interfaces
;
using
Store.ViewModels.Auths
;
using
Store.ViewModels.Auths
;
namespace
Store.Controllers
;
namespace
Store.Controllers
;
public
class
AccountsController
:
Controller
public
class
AccountsController
:
Controller
{
{
private
readonly
IUserRepository
_userRepository
;
private
readonly
UserManager
<
User
>
_userManager
;
private
readonly
SignInManager
<
User
>
_signInManager
;
public
AccountsController
(
IUserRepository
userRepository
)
public
AccountsController
(
UserManager
<
User
>
userManager
,
SignInManager
<
User
>
signInManager
)
{
{
_userRepository
=
userRepository
;
_userManager
=
userManager
;
_signInManager
=
signInManager
;
}
}
[
HttpGet
]
[
HttpGet
]
...
@@ -24,38 +24,38 @@ public class AccountsController : Controller
...
@@ -24,38 +24,38 @@ public class AccountsController : Controller
return
View
();
return
View
();
}
}
[
HttpPost
]
//
[HttpPost]
[
ValidateAntiForgeryToken
]
//
[ValidateAntiForgeryToken]
public
async
Task
<
IActionResult
>
Login
(
LoginViewModel
model
)
//
public async Task<IActionResult> Login(LoginViewModel model)
{
//
{
try
//
try
{
//
{
if
(
ModelState
.
IsValid
)
//
if (ModelState.IsValid)
{
//
{
var
user
=
_userRepository
.
GetUserByEmail
(
model
.
Email
);
//
var user = _userRepository.GetUserByEmail(model.Email);
if
(
user
is
not
null
)
//
if (user is not null)
{
//
{
if
(
user
.
Password
.
Equals
(
model
.
Password
))
//
if (user.Password.Equals(model.Password))
{
//
{
await
AuthenticateAsync
(
user
);
//
await AuthenticateAsync(user);
return
RedirectToAction
(
"Index"
,
"Home"
);
//
return RedirectToAction("Index", "Home");
}
//
}
ModelState
.
AddModelError
(
""
,
"пароль введен неверно"
);
//
ModelState.AddModelError("", "пароль введен неверно");
}
//
}
else
//
else
{
//
{
ModelState
.
AddModelError
(
""
,
"пользователь не найден"
);
//
ModelState.AddModelError("", "пользователь не найден");
}
//
}
}
//
}
//
return
View
(
model
);
//
return View(model);
}
//
}
catch
(
Exception
e
)
//
catch (Exception e)
{
//
{
Console
.
WriteLine
(
e
);
//
Console.WriteLine(e);
return
View
();
//
return View();
}
//
}
}
//
}
[
HttpGet
]
[
HttpGet
]
public
IActionResult
Register
()
public
IActionResult
Register
()
...
@@ -66,58 +66,49 @@ public class AccountsController : Controller
...
@@ -66,58 +66,49 @@ public class AccountsController : Controller
[
HttpPost
]
[
HttpPost
]
[
ValidateAntiForgeryToken
]
[
ValidateAntiForgeryToken
]
public
async
Task
<
IActionResult
>
Register
(
RegisterViewModel
viewModel
)
public
async
Task
<
IActionResult
>
Register
(
RegisterViewModel
viewModel
)
{
try
{
{
if
(
ModelState
.
IsValid
)
if
(
ModelState
.
IsValid
)
{
{
var
user
=
_userRepository
.
GetUserByEmail
(
viewModel
.
Email
);
var
email
=
await
_userManager
.
FindByEmailAsync
(
viewModel
.
Email
);
if
(
user
is
null
)
if
(
email
is
null
)
{
{
var
role
=
_userRepository
.
GetRoles
().
FirstOrDefault
(
s
=>
s
.
Name
==
"user"
);
var
user
=
new
User
var
newUser
=
new
User
{
{
Email
=
viewModel
.
Email
,
Email
=
viewModel
.
Email
,
Password
=
viewModel
.
Password
,
UserName
=
viewModel
.
UserName
,
RoleId
=
role
?.
Id
,
BirthDate
=
viewModel
.
BirthDate
.
Date
Role
=
role
};
};
_userRepository
.
Create
(
newUser
);
_userRepository
.
Save
();
var
result
=
await
_userManager
.
CreateAsync
(
user
,
viewModel
.
Password
);
await
AuthenticateAsync
(
newUser
);
if
(
result
.
Succeeded
)
{
await
_signInManager
.
SignInAsync
(
user
,
true
);
return
RedirectToAction
(
"Index"
,
"Home"
);
return
RedirectToAction
(
"Index"
,
"Home"
);
}
}
foreach
(
var
error
in
result
.
Errors
)
ModelState
.
AddModelError
(
string
.
Empty
,
error
.
Description
);
return
View
(
viewModel
);
}
ModelState
.
AddModelError
(
""
,
"пользователь с таким email уже существует"
);
ModelState
.
AddModelError
(
""
,
"пользователь с таким email уже существует"
);
}
}
return
View
(
viewModel
);
return
View
(
viewModel
);
}
}
catch
(
Exception
e
)
{
ModelState
.
AddModelError
(
""
,
e
.
Message
);
return
View
(
viewModel
);
}
}
public
async
Task
<
IActionResult
>
Logout
()
public
async
Task
<
IActionResult
>
Logout
()
{
{
await
HttpContext
.
SignOutAsync
(
CookieAuthenticationDefaults
.
AuthenticationScheme
);
await
HttpContext
.
SignOutAsync
(
CookieAuthenticationDefaults
.
AuthenticationScheme
);
return
RedirectToAction
(
"Login"
);
return
RedirectToAction
(
"Login"
);
}
}
private
async
Task
AuthenticateAsync
(
User
user
)
{
var
claims
=
new
List
<
Claim
>
{
new
Claim
(
ClaimsIdentity
.
DefaultNameClaimType
,
user
.
Email
),
new
Claim
(
ClaimsIdentity
.
DefaultNameClaimType
,
user
.
Role
?.
Name
)
};
ClaimsIdentity
id
=
new
ClaimsIdentity
(
claims
,
"ApplicationCookie"
,
ClaimsIdentity
.
DefaultNameClaimType
,
ClaimsIdentity
.
DefaultRoleClaimType
);
await
HttpContext
.
SignInAsync
(
CookieAuthenticationDefaults
.
AuthenticationScheme
,
new
ClaimsPrincipal
(
id
),
new
AuthenticationProperties
{
IsPersistent
=
true
,
ExpiresUtc
=
DateTime
.
UtcNow
.
AddMinutes
(
1
)
}
);
}
}
}
\ No newline at end of file
NewStores/Store/Controllers/HomeController.cs
View file @
85a80e47
...
@@ -20,7 +20,6 @@ public class HomeController : Controller
...
@@ -20,7 +20,6 @@ public class HomeController : Controller
return
View
();
return
View
();
}
}
[
Authorize
(
Roles
=
"admin, user"
)]
public
IActionResult
Privacy
()
public
IActionResult
Privacy
()
{
{
return
View
();
return
View
();
...
...
NewStores/Store/Extensions/ServicesAppExtension.cs
View file @
85a80e47
using
Microsoft.AspNetCore.Authentication.Cookies
;
using
Microsoft.AspNetCore.Authentication.Cookies
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Store.Models
;
using
Store.Models
;
using
Store.Repositories
;
using
Store.Models.Users
;
using
Store.Repositories.Interfaces
;
namespace
Store.Extensions
;
namespace
Store.Extensions
;
...
@@ -11,14 +11,8 @@ public static class ServicesAppExtension
...
@@ -11,14 +11,8 @@ public static class ServicesAppExtension
public
static
void
AddAppServices
(
this
IServiceCollection
services
,
IConfiguration
configuration
)
public
static
void
AddAppServices
(
this
IServiceCollection
services
,
IConfiguration
configuration
)
{
{
services
.
AddDbContext
<
AppDbContext
>(
opt
=>
services
.
AddDbContext
<
AppDbContext
>(
opt
=>
opt
.
UseNpgsql
(
configuration
.
GetConnectionString
(
"ConnectionString"
)));
opt
.
UseNpgsql
(
configuration
.
GetConnectionString
(
"ConnectionString"
)))
services
.
AddAuthentication
(
CookieAuthenticationDefaults
.
AuthenticationScheme
)
.
AddIdentity
<
User
,
IdentityRole
>()
.
AddCookie
(
opt
=>
.
AddEntityFrameworkStores
<
AppDbContext
>();
{
opt
.
LoginPath
=
new
PathString
(
"/Accounts/Login"
);
});
//repositories
services
.
AddScoped
<
IUserRepository
,
UserRepository
>();
}
}
}
}
\ No newline at end of file
NewStores/Store/Migrations/20220718152553_Init.Designer.cs
deleted
100644 → 0
View file @
355dfcbe
// <auto-generated />
using
System
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
using
Store.Models
;
#
nullable
disable
namespace
Store.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20220718152553_Init"
)]
partial
class
Init
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"6.0.7"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
modelBuilder
.
Entity
(
"Store.Models.Users.Role"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Name"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Roles"
);
b
.
HasData
(
new
{
Id
=
1
,
Name
=
"admin"
},
new
{
Id
=
2
,
Name
=
"user"
});
});
modelBuilder
.
Entity
(
"Store.Models.Users.User"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Email"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Password"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
Property
<
int
?>(
"RoleId"
)
.
HasColumnType
(
"integer"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"Users"
);
b
.
HasData
(
new
{
Id
=
1
,
Email
=
"email@test"
,
Password
=
"1234"
,
RoleId
=
1
});
});
modelBuilder
.
Entity
(
"Store.Models.Users.User"
,
b
=>
{
b
.
HasOne
(
"Store.Models.Users.Role"
,
"Role"
)
.
WithMany
(
"Users"
)
.
HasForeignKey
(
"RoleId"
);
b
.
Navigation
(
"Role"
);
});
modelBuilder
.
Entity
(
"Store.Models.Users.Role"
,
b
=>
{
b
.
Navigation
(
"Users"
);
});
#pragma warning restore 612, 618
}
}
}
NewStores/Store/Migrations/20220718152553_Init.cs
deleted
100644 → 0
View file @
355dfcbe
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
#
nullable
disable
namespace
Store.Migrations
{
public
partial
class
Init
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"Roles"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
Name
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Roles"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"Users"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
Email
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
Password
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
RoleId
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_Users"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_Users_Roles_RoleId"
,
column
:
x
=>
x
.
RoleId
,
principalTable
:
"Roles"
,
principalColumn
:
"Id"
);
});
migrationBuilder
.
InsertData
(
table
:
"Roles"
,
columns
:
new
[]
{
"Id"
,
"Name"
},
values
:
new
object
[,]
{
{
1
,
"admin"
},
{
2
,
"user"
}
});
migrationBuilder
.
InsertData
(
table
:
"Users"
,
columns
:
new
[]
{
"Id"
,
"Email"
,
"Password"
,
"RoleId"
},
values
:
new
object
[]
{
1
,
"email@test"
,
"1234"
,
1
});
migrationBuilder
.
CreateIndex
(
name
:
"IX_Users_RoleId"
,
table
:
"Users"
,
column
:
"RoleId"
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"Users"
);
migrationBuilder
.
DropTable
(
name
:
"Roles"
);
}
}
}
NewStores/Store/Migrations/20220721141424_Init.Designer.cs
0 → 100644
View file @
85a80e47
// <auto-generated />
using
System
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore.Infrastructure
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Microsoft.EntityFrameworkCore.Storage.ValueConversion
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
using
Store.Models
;
#
nullable
disable
namespace
Store.Migrations
{
[
DbContext
(
typeof
(
AppDbContext
))]
[
Migration
(
"20220721141424_Init"
)]
partial
class
Init
{
protected
override
void
BuildTargetModel
(
ModelBuilder
modelBuilder
)
{
#pragma warning disable 612, 618
modelBuilder
.
HasAnnotation
(
"ProductVersion"
,
"6.0.7"
)
.
HasAnnotation
(
"Relational:MaxIdentifierLength"
,
63
);
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Name"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"NormalizedName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"NormalizedName"
)
.
IsUnique
()
.
HasDatabaseName
(
"RoleNameIndex"
);
b
.
ToTable
(
"AspNetRoles"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"ClaimType"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ClaimValue"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"RoleId"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"AspNetRoleClaims"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserClaim<string>"
,
b
=>
{
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
HasColumnType
(
"integer"
);
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"ClaimType"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ClaimValue"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserClaims"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
Property
<
string
>(
"LoginProvider"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ProviderKey"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ProviderDisplayName"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
()
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"LoginProvider"
,
"ProviderKey"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserLogins"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserRole<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"RoleId"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"UserId"
,
"RoleId"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"AspNetUserRoles"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserToken<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"LoginProvider"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Value"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"UserId"
,
"LoginProvider"
,
"Name"
);
b
.
ToTable
(
"AspNetUserTokens"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Store.Models.Users.User"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
int
>(
"AccessFailedCount"
)
.
HasColumnType
(
"integer"
);
b
.
Property
<
DateTime
>(
"BirthDate"
)
.
HasColumnType
(
"timestamp with time zone"
);
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Email"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
bool
>(
"EmailConfirmed"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
bool
>(
"LockoutEnabled"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
DateTimeOffset
?>(
"LockoutEnd"
)
.
HasColumnType
(
"timestamp with time zone"
);
b
.
Property
<
string
>(
"NormalizedEmail"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"NormalizedUserName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"PasswordHash"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"PhoneNumber"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
bool
>(
"PhoneNumberConfirmed"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
string
>(
"SecurityStamp"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
bool
>(
"TwoFactorEnabled"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
string
>(
"UserName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"NormalizedEmail"
)
.
HasDatabaseName
(
"EmailIndex"
);
b
.
HasIndex
(
"NormalizedUserName"
)
.
IsUnique
()
.
HasDatabaseName
(
"UserNameIndex"
);
b
.
ToTable
(
"AspNetUsers"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserClaim<string>"
,
b
=>
{
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserRole<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserToken<string>"
,
b
=>
{
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
#pragma warning restore 612, 618
}
}
}
NewStores/Store/Migrations/20220721141424_Init.cs
0 → 100644
View file @
85a80e47
using
System
;
using
Microsoft.EntityFrameworkCore.Migrations
;
using
Npgsql.EntityFrameworkCore.PostgreSQL.Metadata
;
#
nullable
disable
namespace
Store.Migrations
{
public
partial
class
Init
:
Migration
{
protected
override
void
Up
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
CreateTable
(
name
:
"AspNetRoles"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
Name
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
NormalizedName
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
ConcurrencyStamp
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetRoles"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetUsers"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
BirthDate
=
table
.
Column
<
DateTime
>(
type
:
"date"
,
nullable
:
false
),
UserName
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
NormalizedUserName
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
Email
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
NormalizedEmail
=
table
.
Column
<
string
>(
type
:
"character varying(256)"
,
maxLength
:
256
,
nullable
:
true
),
EmailConfirmed
=
table
.
Column
<
bool
>(
type
:
"boolean"
,
nullable
:
false
),
PasswordHash
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
SecurityStamp
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
ConcurrencyStamp
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
PhoneNumber
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
PhoneNumberConfirmed
=
table
.
Column
<
bool
>(
type
:
"boolean"
,
nullable
:
false
),
TwoFactorEnabled
=
table
.
Column
<
bool
>(
type
:
"boolean"
,
nullable
:
false
),
LockoutEnd
=
table
.
Column
<
DateTimeOffset
>(
type
:
"timestamp with time zone"
,
nullable
:
true
),
LockoutEnabled
=
table
.
Column
<
bool
>(
type
:
"boolean"
,
nullable
:
false
),
AccessFailedCount
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetUsers"
,
x
=>
x
.
Id
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetRoleClaims"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
RoleId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
ClaimType
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
ClaimValue
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetRoleClaims"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_AspNetRoleClaims_AspNetRoles_RoleId"
,
column
:
x
=>
x
.
RoleId
,
principalTable
:
"AspNetRoles"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetUserClaims"
,
columns
:
table
=>
new
{
Id
=
table
.
Column
<
int
>(
type
:
"integer"
,
nullable
:
false
)
.
Annotation
(
"Npgsql:ValueGenerationStrategy"
,
NpgsqlValueGenerationStrategy
.
IdentityByDefaultColumn
),
UserId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
ClaimType
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
ClaimValue
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetUserClaims"
,
x
=>
x
.
Id
);
table
.
ForeignKey
(
name
:
"FK_AspNetUserClaims_AspNetUsers_UserId"
,
column
:
x
=>
x
.
UserId
,
principalTable
:
"AspNetUsers"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetUserLogins"
,
columns
:
table
=>
new
{
LoginProvider
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
ProviderKey
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
ProviderDisplayName
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
),
UserId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetUserLogins"
,
x
=>
new
{
x
.
LoginProvider
,
x
.
ProviderKey
});
table
.
ForeignKey
(
name
:
"FK_AspNetUserLogins_AspNetUsers_UserId"
,
column
:
x
=>
x
.
UserId
,
principalTable
:
"AspNetUsers"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetUserRoles"
,
columns
:
table
=>
new
{
UserId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
RoleId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetUserRoles"
,
x
=>
new
{
x
.
UserId
,
x
.
RoleId
});
table
.
ForeignKey
(
name
:
"FK_AspNetUserRoles_AspNetRoles_RoleId"
,
column
:
x
=>
x
.
RoleId
,
principalTable
:
"AspNetRoles"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
table
.
ForeignKey
(
name
:
"FK_AspNetUserRoles_AspNetUsers_UserId"
,
column
:
x
=>
x
.
UserId
,
principalTable
:
"AspNetUsers"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateTable
(
name
:
"AspNetUserTokens"
,
columns
:
table
=>
new
{
UserId
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
LoginProvider
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
Name
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
false
),
Value
=
table
.
Column
<
string
>(
type
:
"text"
,
nullable
:
true
)
},
constraints
:
table
=>
{
table
.
PrimaryKey
(
"PK_AspNetUserTokens"
,
x
=>
new
{
x
.
UserId
,
x
.
LoginProvider
,
x
.
Name
});
table
.
ForeignKey
(
name
:
"FK_AspNetUserTokens_AspNetUsers_UserId"
,
column
:
x
=>
x
.
UserId
,
principalTable
:
"AspNetUsers"
,
principalColumn
:
"Id"
,
onDelete
:
ReferentialAction
.
Cascade
);
});
migrationBuilder
.
CreateIndex
(
name
:
"IX_AspNetRoleClaims_RoleId"
,
table
:
"AspNetRoleClaims"
,
column
:
"RoleId"
);
migrationBuilder
.
CreateIndex
(
name
:
"RoleNameIndex"
,
table
:
"AspNetRoles"
,
column
:
"NormalizedName"
,
unique
:
true
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_AspNetUserClaims_UserId"
,
table
:
"AspNetUserClaims"
,
column
:
"UserId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_AspNetUserLogins_UserId"
,
table
:
"AspNetUserLogins"
,
column
:
"UserId"
);
migrationBuilder
.
CreateIndex
(
name
:
"IX_AspNetUserRoles_RoleId"
,
table
:
"AspNetUserRoles"
,
column
:
"RoleId"
);
migrationBuilder
.
CreateIndex
(
name
:
"EmailIndex"
,
table
:
"AspNetUsers"
,
column
:
"NormalizedEmail"
);
migrationBuilder
.
CreateIndex
(
name
:
"UserNameIndex"
,
table
:
"AspNetUsers"
,
column
:
"NormalizedUserName"
,
unique
:
true
);
}
protected
override
void
Down
(
MigrationBuilder
migrationBuilder
)
{
migrationBuilder
.
DropTable
(
name
:
"AspNetRoleClaims"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetUserClaims"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetUserLogins"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetUserRoles"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetUserTokens"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetRoles"
);
migrationBuilder
.
DropTable
(
name
:
"AspNetUsers"
);
}
}
}
NewStores/Store/Migrations/AppDbContextModelSnapshot.cs
View file @
85a80e47
...
@@ -22,7 +22,33 @@ namespace Store.Migrations
...
@@ -22,7 +22,33 @@ namespace Store.Migrations
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
NpgsqlModelBuilderExtensions
.
UseIdentityByDefaultColumns
(
modelBuilder
);
modelBuilder
.
Entity
(
"Store.Models.Users.Role"
,
b
=>
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Name"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"NormalizedName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"NormalizedName"
)
.
IsUnique
()
.
HasDatabaseName
(
"RoleNameIndex"
);
b
.
ToTable
(
"AspNetRoles"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
{
b
.
Property
<
int
>(
"Id"
)
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
ValueGeneratedOnAdd
()
...
@@ -30,28 +56,24 @@ namespace Store.Migrations
...
@@ -30,28 +56,24 @@ namespace Store.Migrations
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Name"
)
b
.
Property
<
string
>(
"ClaimType"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ClaimValue"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"RoleId"
)
.
IsRequired
()
.
IsRequired
()
.
HasColumnType
(
"text"
);
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"Id"
);
b
.
HasKey
(
"Id"
);
b
.
ToTable
(
"Roles
"
);
b
.
HasIndex
(
"RoleId
"
);
b
.
HasData
(
b
.
ToTable
(
"AspNetRoleClaims"
,
(
string
)
null
);
new
{
Id
=
1
,
Name
=
"admin"
},
new
{
Id
=
2
,
Name
=
"user"
});
});
});
modelBuilder
.
Entity
(
"
Store.Models.Users.User
"
,
b
=>
modelBuilder
.
Entity
(
"
Microsoft.AspNetCore.Identity.IdentityUserClaim<string>
"
,
b
=>
{
{
b
.
Property
<
int
>(
"Id"
)
b
.
Property
<
int
>(
"Id"
)
.
ValueGeneratedOnAdd
()
.
ValueGeneratedOnAdd
()
...
@@ -59,45 +81,195 @@ namespace Store.Migrations
...
@@ -59,45 +81,195 @@ namespace Store.Migrations
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
NpgsqlPropertyBuilderExtensions
.
UseIdentityByDefaultColumn
(
b
.
Property
<
int
>(
"Id"
));
b
.
Property
<
string
>(
"Email"
)
b
.
Property
<
string
>(
"ClaimType"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ClaimValue"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
()
.
IsRequired
()
.
HasColumnType
(
"text"
);
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Password"
)
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserClaims"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
Property
<
string
>(
"LoginProvider"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ProviderKey"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"ProviderDisplayName"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"UserId"
)
.
IsRequired
()
.
IsRequired
()
.
HasColumnType
(
"text"
);
.
HasColumnType
(
"text"
);
b
.
Property
<
int
?>(
"RoleId"
)
b
.
HasKey
(
"LoginProvider"
,
"ProviderKey"
);
b
.
HasIndex
(
"UserId"
);
b
.
ToTable
(
"AspNetUserLogins"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserRole<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"RoleId"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"UserId"
,
"RoleId"
);
b
.
HasIndex
(
"RoleId"
);
b
.
ToTable
(
"AspNetUserRoles"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserToken<string>"
,
b
=>
{
b
.
Property
<
string
>(
"UserId"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"LoginProvider"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Name"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Value"
)
.
HasColumnType
(
"text"
);
b
.
HasKey
(
"UserId"
,
"LoginProvider"
,
"Name"
);
b
.
ToTable
(
"AspNetUserTokens"
,
(
string
)
null
);
});
modelBuilder
.
Entity
(
"Store.Models.Users.User"
,
b
=>
{
b
.
Property
<
string
>(
"Id"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
int
>(
"AccessFailedCount"
)
.
HasColumnType
(
"integer"
);
.
HasColumnType
(
"integer"
);
b
.
Property
<
DateTime
>(
"BirthDate"
)
.
HasColumnType
(
"date"
);
b
.
Property
<
string
>(
"ConcurrencyStamp"
)
.
IsConcurrencyToken
()
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"Email"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
bool
>(
"EmailConfirmed"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
bool
>(
"LockoutEnabled"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
DateTimeOffset
?>(
"LockoutEnd"
)
.
HasColumnType
(
"timestamp with time zone"
);
b
.
Property
<
string
>(
"NormalizedEmail"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"NormalizedUserName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
Property
<
string
>(
"PasswordHash"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
string
>(
"PhoneNumber"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
bool
>(
"PhoneNumberConfirmed"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
string
>(
"SecurityStamp"
)
.
HasColumnType
(
"text"
);
b
.
Property
<
bool
>(
"TwoFactorEnabled"
)
.
HasColumnType
(
"boolean"
);
b
.
Property
<
string
>(
"UserName"
)
.
HasMaxLength
(
256
)
.
HasColumnType
(
"character varying(256)"
);
b
.
HasKey
(
"Id"
);
b
.
HasKey
(
"Id"
);
b
.
HasIndex
(
"RoleId"
);
b
.
HasIndex
(
"NormalizedEmail"
)
.
HasDatabaseName
(
"EmailIndex"
);
b
.
HasIndex
(
"NormalizedUserName"
)
.
IsUnique
()
.
HasDatabaseName
(
"UserNameIndex"
);
b
.
ToTable
(
"AspNetUsers"
,
(
string
)
null
);
});
b
.
ToTable
(
"Users"
);
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>"
,
b
=>
{
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
b
.
HasData
(
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserClaim<string>"
,
b
=>
new
{
{
Id
=
1
,
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
Email
=
"email@test"
,
.
WithMany
()
Password
=
"1234"
,
.
HasForeignKey
(
"UserId"
)
RoleId
=
1
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
});
modelBuilder
.
Entity
(
"Microsoft.AspNetCore.Identity.IdentityUserLogin<string>"
,
b
=>
{
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
});
modelBuilder
.
Entity
(
"
Store.Models.Users.User
"
,
b
=>
modelBuilder
.
Entity
(
"
Microsoft.AspNetCore.Identity.IdentityUserRole<string>
"
,
b
=>
{
{
b
.
HasOne
(
"Store.Models.Users.Role"
,
"Role"
)
b
.
HasOne
(
"Microsoft.AspNetCore.Identity.IdentityRole"
,
null
)
.
WithMany
(
"Users"
)
.
WithMany
()
.
HasForeignKey
(
"RoleId"
);
.
HasForeignKey
(
"RoleId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
b
.
Navigation
(
"Role"
);
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
});
modelBuilder
.
Entity
(
"
Store.Models.Users.Role
"
,
b
=>
modelBuilder
.
Entity
(
"
Microsoft.AspNetCore.Identity.IdentityUserToken<string>
"
,
b
=>
{
{
b
.
Navigation
(
"Users"
);
b
.
HasOne
(
"Store.Models.Users.User"
,
null
)
.
WithMany
()
.
HasForeignKey
(
"UserId"
)
.
OnDelete
(
DeleteBehavior
.
Cascade
)
.
IsRequired
();
});
});
#pragma warning restore 612, 618
#pragma warning restore 612, 618
}
}
...
...
NewStores/Store/Models/AppDbContext.cs
View file @
85a80e47
using
Microsoft.AspNetCore.Identity.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Microsoft.EntityFrameworkCore
;
using
Store.Models.Users
;
using
Store.Models.Users
;
namespace
Store.Models
;
namespace
Store.Models
;
public
class
AppDbContext
:
DbContext
public
class
AppDbContext
:
IdentityDbContext
<
User
>
{
{
public
DbSet
<
User
>
Users
{
get
;
set
;
}
public
DbSet
<
User
>
Users
{
get
;
set
;
}
public
DbSet
<
Role
>
Roles
{
get
;
set
;
}
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
contextOptions
)
:
base
(
contextOptions
)
public
AppDbContext
(
DbContextOptions
<
AppDbContext
>
contextOptions
)
:
base
(
contextOptions
)
{
{
...
@@ -15,9 +15,7 @@ public class AppDbContext : DbContext
...
@@ -15,9 +15,7 @@ public class AppDbContext : DbContext
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
protected
override
void
OnModelCreating
(
ModelBuilder
modelBuilder
)
{
{
modelBuilder
.
Entity
<
Role
>().
HasData
(
new
Role
{
Id
=
1
,
Name
=
"admin"
});
base
.
OnModelCreating
(
modelBuilder
);
modelBuilder
.
Entity
<
Role
>().
HasData
(
new
Role
{
Id
=
2
,
Name
=
"user"
});
modelBuilder
.
Entity
<
User
>().
HasData
(
new
User
{
Id
=
1
,
Email
=
"email@test"
,
Password
=
"1234"
,
RoleId
=
1
});
}
}
}
}
\ No newline at end of file
NewStores/Store/Models/Users/Role.cs
deleted
100644 → 0
View file @
355dfcbe
namespace
Store.Models.Users
;
public
class
Role
{
public
int
Id
{
get
;
set
;
}
public
string
Name
{
get
;
set
;
}
public
List
<
User
>
Users
{
get
;
set
;
}
public
Role
()
{
Users
=
new
List
<
User
>();
}
}
\ No newline at end of file
NewStores/Store/Models/Users/User.cs
View file @
85a80e47
using
Microsoft.AspNetCore.Identity
;
namespace
Store.Models.Users
;
namespace
Store.Models.Users
;
public
class
User
public
class
User
:
IdentityUser
{
{
public
int
Id
{
get
;
set
;
}
public
DateTime
BirthDate
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
public
int
?
RoleId
{
get
;
set
;
}
public
Role
?
Role
{
get
;
set
;
}
}
}
\ No newline at end of file
NewStores/Store/Repositories/Interfaces/IUserRepository.cs
deleted
100644 → 0
View file @
355dfcbe
using
Store.Models
;
using
Store.Models.Users
;
namespace
Store.Repositories.Interfaces
;
public
interface
IUserRepository
:
IRepository
<
User
>
{
User
?
GetUserById
(
int
id
);
User
?
GetUserByEmail
(
string
email
);
List
<
Role
>
GetRoles
();
}
\ No newline at end of file
NewStores/Store/Repositories/UserRepository.cs
deleted
100644 → 0
View file @
355dfcbe
using
Microsoft.EntityFrameworkCore
;
using
Store.Models
;
using
Store.Models.Users
;
using
Store.Repositories.Interfaces
;
namespace
Store.Repositories
;
public
class
UserRepository
:
IUserRepository
{
private
readonly
AppDbContext
_context
;
public
UserRepository
(
AppDbContext
context
)
{
_context
=
context
;
}
public
void
Create
(
User
item
)
{
_context
.
Users
.
Add
(
item
);
}
public
void
Update
(
User
item
)
{
_context
.
Users
.
Update
(
item
);
}
public
void
Remove
(
User
item
)
{
_context
.
Users
.
Remove
(
item
);
}
public
void
Save
()
{
_context
.
SaveChanges
();
}
public
User
?
GetUserById
(
int
id
)
{
return
_context
.
Users
.
Include
(
u
=>
u
.
Role
).
FirstOrDefault
(
s
=>
s
.
Id
==
id
);
}
public
User
?
GetUserByEmail
(
string
email
)
{
return
_context
.
Users
.
Include
(
u
=>
u
.
Role
).
FirstOrDefault
(
s
=>
s
.
Email
==
email
);
}
public
List
<
Role
>
GetRoles
()
=>
_context
.
Roles
.
ToList
();
}
\ No newline at end of file
NewStores/Store/Store.csproj
View file @
85a80e47
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.7">
<PrivateAssets>all</PrivateAssets>
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
...
...
NewStores/Store/ViewModels/Auths/RegisterViewModel.cs
View file @
85a80e47
...
@@ -6,6 +6,10 @@ public class RegisterViewModel
...
@@ -6,6 +6,10 @@ public class RegisterViewModel
{
{
[
Required
(
ErrorMessage
=
"Введите email"
)]
[
Required
(
ErrorMessage
=
"Введите email"
)]
public
string
Email
{
get
;
set
;
}
public
string
Email
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Введите username"
)]
public
string
UserName
{
get
;
set
;
}
[
Required
]
public
DateTime
BirthDate
{
get
;
set
;
}
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
[
Required
(
ErrorMessage
=
"Введите пароль"
)]
[
DataType
(
DataType
.
Password
)]
[
DataType
(
DataType
.
Password
)]
public
string
Password
{
get
;
set
;
}
public
string
Password
{
get
;
set
;
}
...
...
NewStores/Store/Views/Accounts/Register.cshtml
View file @
85a80e47
@using Microsoft.AspNetCore.Mvc.TagHelpers
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model Store.ViewModels.Auths.RegisterViewModel
@model Store.ViewModels.Auths.RegisterViewModel
@{
ViewBag.Title = "Регистрация";
}
<h2>Регистрация</h2>
<h2>Регистрация нового пользователя</h2>
<form method="post" asp-controller="Accounts" asp-action="Register">
<form asp-action="Register" asp-controller="Accounts" asp-anti-forgery="true">
<div asp-validation-summary="ModelOnly"></div>
<div class="validation" asp-validation-summary="ModelOnly"></div>
<div>
<div>
<div>
<label asp-for="Email">Введите Email</label><br
/>
<label asp-for="Email"></label><br
/>
<input type="text" asp-for="Email"
/>
<input asp-for="Email"
/>
<span asp-validation-for="Email"></span>
<span asp-validation-for="Email"></span>
</div>
</div>
<div>
<div>
<label asp-for="Password">Введите пароль</label><br />
<label asp-for="UserName"></label><br/>
<input asp-for="Password" />
<input asp-for="UserName"/>
<span asp-validation-for="UserName"></span>
</div>
<div>
<label asp-for="BirthDate"></label><br/>
<input asp-for="BirthDate" type="date"/>
<span asp-validation-for="BirthDate"></span>
</div>
<div>
<label asp-for="Password"></label><br/>
<input asp-for="Password"/>
<span asp-validation-for="Password"></span>
<span asp-validation-for="Password"></span>
</div>
</div>
<div>
<div>
<label asp-for="ConfirmPassword">Повторите пароль</label><br
/>
<label asp-for="ConfirmPassword"></label><br
/>
<input asp-for="ConfirmPassword"
/>
<input asp-for="ConfirmPassword"
/>
<span asp-validation-for="ConfirmPassword"></span>
<span asp-validation-for="ConfirmPassword"></span>
</div>
</div>
<div>
<div>
<input type="submit" value="Регистрация" />
<input type="submit" value="Регистрация"/>
</div>
</div>
</div>
</form>
</form>
\ No newline at end of file
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