fix: пофиксил ошибку из-за того, что не изменил наследование пользователя на IdentityUser.

parent 20fd6d08
......@@ -66,5 +66,13 @@ namespace PhoneStore.Controllers
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> LogOff()
{
await _accountService.LogOf();
return RedirectToAction("Index", "Phones");
}
}
}
\ No newline at end of file
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace PhoneStore.Models
{
public class MobileContext : DbContext
public class MobileContext : IdentityDbContext<User, Role, int>
{
public DbSet<Phone> Phones { get; set; }
public DbSet<Order> Orders { get; set; }
......
......@@ -24,7 +24,7 @@ namespace PhoneStore
{
var userManager = services.GetRequiredService<UserManager<User>>();
RoleManager<Role> rolesManager = services.GetRequiredService<RoleManager<Role>>();
await AdminInitializer.SeedAdminUser(rolesManager, userManager);
await AdminInitializerService.SeedAdminUser(rolesManager, userManager);
}
catch (Exception ex)
{
......
......@@ -8,6 +8,6 @@ namespace PhoneStore.Services.Abstractions
{
Task<IdentityResult> Register(RegisterViewModel model);
Task<IdentityResult> LogIn(LoginViewModel model);
Task<IdentityResult> LogOf();
Task LogOf();
}
}
\ No newline at end of file
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using PhoneStore.Enums;
......@@ -73,9 +72,7 @@ namespace PhoneStore.Services
};
}
public Task<IdentityResult> LogOf()
{
throw new System.NotImplementedException();
}
public async Task LogOf()
=> await _signInManager.SignOutAsync();
}
}
\ No newline at end of file
......@@ -4,7 +4,7 @@ using PhoneStore.Models;
namespace PhoneStore.Services
{
public class AdminInitializer
public class AdminInitializerService
{
public static async Task SeedAdminUser(
RoleManager<Role> roleManager,
......
......@@ -50,7 +50,7 @@ namespace PhoneStore
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization().UseAuthentication();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
......
......@@ -29,6 +29,21 @@
</li>
</ul>
</div>
<div class="login_group">
@if(User.Identity.IsAuthenticated)
{
<p>@User.Identity.Name</p>
<form method="post" asp-controller="Account" asp-action="LogOff">
<input type="submit" value="Выход" />
</form>
}
else
{
<a asp-controller="Account" asp-action="Login">Вход</a>
<a asp-controller="Account" asp-action="Register">Регистрация</a>
}
</div>
</div>
</nav>
</header>
......
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=54320;database=lesson55;Username=postgres;Password=postgres;"
"DefaultConnection": "Server=localhost;Port=54320;database=lesson58;Username=postgres;Password=postgres;"
},
"Logging": {
"LogLevel": {
......
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