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

parent 20fd6d08
...@@ -66,5 +66,13 @@ namespace PhoneStore.Controllers ...@@ -66,5 +66,13 @@ namespace PhoneStore.Controllers
return View(model); 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; using Microsoft.EntityFrameworkCore;
namespace PhoneStore.Models namespace PhoneStore.Models
{ {
public class MobileContext : DbContext public class MobileContext : IdentityDbContext<User, Role, int>
{ {
public DbSet<Phone> Phones { get; set; } public DbSet<Phone> Phones { get; set; }
public DbSet<Order> Orders { get; set; } public DbSet<Order> Orders { get; set; }
......
...@@ -24,7 +24,7 @@ namespace PhoneStore ...@@ -24,7 +24,7 @@ namespace PhoneStore
{ {
var userManager = services.GetRequiredService<UserManager<User>>(); var userManager = services.GetRequiredService<UserManager<User>>();
RoleManager<Role> rolesManager = services.GetRequiredService<RoleManager<Role>>(); RoleManager<Role> rolesManager = services.GetRequiredService<RoleManager<Role>>();
await AdminInitializer.SeedAdminUser(rolesManager, userManager); await AdminInitializerService.SeedAdminUser(rolesManager, userManager);
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -8,6 +8,6 @@ namespace PhoneStore.Services.Abstractions ...@@ -8,6 +8,6 @@ namespace PhoneStore.Services.Abstractions
{ {
Task<IdentityResult> Register(RegisterViewModel model); Task<IdentityResult> Register(RegisterViewModel model);
Task<IdentityResult> LogIn(LoginViewModel model); Task<IdentityResult> LogIn(LoginViewModel model);
Task<IdentityResult> LogOf(); Task LogOf();
} }
} }
\ No newline at end of file
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Security.Policy;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using PhoneStore.Enums; using PhoneStore.Enums;
...@@ -73,9 +72,7 @@ namespace PhoneStore.Services ...@@ -73,9 +72,7 @@ namespace PhoneStore.Services
}; };
} }
public Task<IdentityResult> LogOf() public async Task LogOf()
{ => await _signInManager.SignOutAsync();
throw new System.NotImplementedException();
}
} }
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ using PhoneStore.Models; ...@@ -4,7 +4,7 @@ using PhoneStore.Models;
namespace PhoneStore.Services namespace PhoneStore.Services
{ {
public class AdminInitializer public class AdminInitializerService
{ {
public static async Task SeedAdminUser( public static async Task SeedAdminUser(
RoleManager<Role> roleManager, RoleManager<Role> roleManager,
......
...@@ -50,7 +50,7 @@ namespace PhoneStore ...@@ -50,7 +50,7 @@ namespace PhoneStore
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRouting(); app.UseRouting();
app.UseAuthorization().UseAuthentication();
app.UseEndpoints(endpoints => app.UseEndpoints(endpoints =>
{ {
endpoints.MapControllerRoute( endpoints.MapControllerRoute(
......
...@@ -29,6 +29,21 @@ ...@@ -29,6 +29,21 @@
</li> </li>
</ul> </ul>
</div> </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> </div>
</nav> </nav>
</header> </header>
......
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Server=localhost;Port=54320;database=lesson55;Username=postgres;Password=postgres;" "DefaultConnection": "Server=localhost;Port=54320;database=lesson58;Username=postgres;Password=postgres;"
}, },
"Logging": { "Logging": {
"LogLevel": { "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