Ignore:
Timestamp:
08/23/24 15:40:14 (5 weeks ago)
Author:
ElenaMoskova <elena.moskova99@…>
Branches:
main
Children:
e9bb9d1
Parents:
72b1da2
Message:

fix access

implement multiple access pages with different roles
optimize present three structure of BlogPost and Answer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • PostgreSqlDotnetCore/Controllers/BlogController.cs

    r72b1da2 r118e414  
    1313
    1414        {
    15            
     15
    1616        }
    1717
     
    4949         }*/
    5050
    51           public async Task<ActionResult> Index()
    52           {
    53               // Проверка за автентикација
    54               bool isAuthenticated = User.Identity.IsAuthenticated;
    55 
    56               if (!isAuthenticated)
    57               {
    58                   return RedirectToAction("AccessDenied", "Error");
    59               }
    60 
    61               // Список на блог постови
    62               var blogPosts = await db.BlogPostControllerObj.ToListAsync();
    63 
    64               // Вземи тековниот корисник
    65               var currentUser = await _userManager.GetUserAsync(User);
    66               var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email);
    67 
    68               // Предавање на ViewBag за проверка на автентикација и корисничкиот ID
    69               ViewBag.isAuthenticated = isAuthenticated;
    70               ViewBag.CurrentUserId = customerClass?.id;
    71 
    72               return View(blogPosts);
    73           }
    74        
    75 
    76        
     51        public async Task<ActionResult> Index()
     52        {
     53            // Проверка за автентикација
     54            bool isAuthenticated = User.Identity.IsAuthenticated;
     55
     56            if (!isAuthenticated)
     57            {
     58                return RedirectToAction("AccessDenied", "Error");
     59            }
     60
     61            // Список на блог постови
     62            var blogPosts = await db.BlogPostControllerObj.ToListAsync();
     63
     64            // Вземи тековниот корисник
     65            var currentUser = await _userManager.GetUserAsync(User);
     66            var customerClass = await db.CustomerObj.SingleOrDefaultAsync(x => x.email == currentUser.Email);
     67
     68            // Предавање на ViewBag за проверка на автентикација и корисничкиот ID
     69            ViewBag.isAuthenticated = isAuthenticated;
     70            // no access for standard user
     71            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     72
     73            ViewBag.CurrentUserId = customerClass?.id;
     74
     75            return View(blogPosts);
     76        }
     77
     78
     79
    7780
    7881
     
    121124            // set if is authenticated
    122125            ViewBag.isAuthenticated = customerClass;
     126            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     127
    123128            return View();
    124129        }
     
    197202                }
    198203            }
     204            // no access for standard user
     205            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     206
    199207
    200208            return View(blogClass);
     
    217225         }*/
    218226
    219        
     227
    220228        public async Task<ActionResult> EditAsync(int id, [Bind(include: "id,date_askes,title,description")] BlogPostConsultation blogClass)
    221229        {
     
    239247
    240248        // GET: Customer/Delete/5
    241         public async Task<ActionResult> DeleteAsync(int? id) {
    242           //  UsersClass customerClass = await checkAuthorizationAsync();
    243 
    244         ViewBag.isAuthenticated = await getCrrentUser();
    245        
     249        public async Task<ActionResult> DeleteAsync(int? id)
     250        {
     251            //  UsersClass customerClass = await checkAuthorizationAsync();
     252
     253            ViewBag.isAuthenticated = await getCrrentUser();
     254
    246255            if (id == null)
    247            {
    248                return View(null);
    249               //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    250             }
    251            BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id);
     256            {
     257                return View(null);
     258                //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     259            }
     260            BlogPostConsultation blogClass = db.BlogPostControllerObj.Find(id);
    252261            if (blogClass == null)
    253262            {
    254263                return View(null);
    255                //return HttpNotFound();
     264                //return HttpNotFound();
    256265            }
    257266            // check for permission
     
    271280                }
    272281            }
     282            // no access for standard user
     283            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     284
    273285            return View(blogClass);
    274286        }
    275287
    276288        // POST: Customer/Delete/5
    277      
     289
    278290
    279291        [HttpPost, ActionName("Delete")]
Note: See TracChangeset for help on using the changeset viewer.