Skip to content

Commit

Permalink
Authorization added to the project and pages role control fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
aliarmaganuygun committed Oct 14, 2024
1 parent 5bafd5e commit 9cc0b5a
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
3 changes: 3 additions & 0 deletions BulkyWeb/Areas/Admin/Controllers/CategoryController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using BookBazaar.DataAccess.Repository.IRepository;
using BookBazaar.Models;
using BookBazaar.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace BookBazaar.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize(Roles = SD.Role_Admin)]
public class CategoryController : Controller
{
private readonly IUnitOfWork _unitOfWork;
Expand Down
3 changes: 3 additions & 0 deletions BulkyWeb/Areas/Admin/Controllers/ProductController.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using BookBazaar.DataAccess.Repository.IRepository;
using BookBazaar.Models;
using BookBazaar.Models.ViewModels;
using BookBazaar.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;

namespace BookBazaar.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize(Roles = SD.Role_Admin)]
public class ProductController : Controller
{
public readonly IUnitOfWork _unitOfWork;
Expand Down
1 change: 1 addition & 0 deletions BulkyWeb/Areas/Admin/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using BookBazaar
@using BookBazaar.Models
@using BookBazaar.Models.ViewModels
@using BookBazaar.Utility
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
1 change: 1 addition & 0 deletions BulkyWeb/Areas/Customer/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using BookBazaar
@using BookBazaar.Models
@using BookBazaar.Models.ViewModels
@using BookBazaar.Utility
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions BulkyWeb/Areas/Identity/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@using Microsoft.AspNetCore.Identity
@using BookBazaar.Areas.Identity
@using BookBazaar.Areas.Identity.Pages
@using BookBazaar.Models
@using BookBazaar.Models.ViewModels
@using BookBazaar.Utility
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
6 changes: 6 additions & 0 deletions BulkyWeb/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

builder.Services.AddIdentity<IdentityUser, IdentityRole>().AddEntityFrameworkStores<ApplicationDbContext>().AddDefaultTokenProviders();
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = $"/Identity/Account/Login";
options.LogoutPath = $"/Identity/Account/Logout";
options.AccessDeniedPath = $"/Identity/Account/AccessDenied";
});
builder.Services.AddRazorPages();
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
builder.Services.AddScoped<IEmailSender, EmailSender>();
Expand Down
31 changes: 17 additions & 14 deletions BulkyWeb/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@
<li class="nav-item">
<a class="nav-link" asp-area="Customer" asp-controller="Home" asp-action="Privacy">Privacy</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Content Management
</a>
<ul class="dropdown-menu">
<li class="nav-item">
<a class="dropdown-item" asp-area="Admin" asp-controller="Category" asp-action="Index">Category</a>
</li>
<li><hr class="dropdown-divider"></li>
<li class="nav-item">
<a class="dropdown-item" asp-area="Admin" asp-controller="Product" asp-action="Index">Book</a>
</li>
</ul>
</li>
@if (User.IsInRole(SD.Role_Admin))
{
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Content Management
</a>
<ul class="dropdown-menu">
<li class="nav-item">
<a class="dropdown-item" asp-area="Admin" asp-controller="Category" asp-action="Index">Category</a>
</li>
<li><hr class="dropdown-divider"></li>
<li class="nav-item">
<a class="dropdown-item" asp-area="Admin" asp-controller="Product" asp-action="Index">Book</a>
</li>
</ul>
</li>
}
</ul>
<partial name="_LoginPartial" />
</div>
Expand Down
1 change: 1 addition & 0 deletions BulkyWeb/Views/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using BookBazaar
@using BookBazaar.Models
@using BookBazaar.Models.ViewModels
@using BookBazaar.Utility
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

0 comments on commit 9cc0b5a

Please sign in to comment.