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/CityController.cs

    r72b1da2 r118e414  
    1616        // GET: Customer
    1717        public async Task<ActionResult> IndexAsync()
    18          {
    19            // check for permission
    20           UsersClass customerClass = await checkAuthorizationAsync();
     18        {
     19            // check for permission
     20            UsersClass customerClass = await checkAuthorizationAsync();
     21            ViewBag.isAuthenticated = User.Identity.IsAuthenticated;
    2122
    22 
    23            if (customerClass == null)
    24              {
    25                  return RedirectToAction("AccessDenied", "Error");
    26              }
     23            if (customerClass == null)
     24            {
     25                return RedirectToAction("AccessDenied", "Error");
     26            }
    2727
    2828            var citiess = await db.CitiesObj.ToListAsync();
     29            // проба на 23.08
     30            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    2931
    3032            return View(citiess);
    3133        }
    32        
     34
    3335
    3436
     
    5052
    5153        // GET: Customer/Details/5
    52         public ActionResult Details(int? id)
     54        //public ActionResult Details(int? id)
     55        public async Task<ActionResult> Details(int? id)
    5356        {
    5457            if (id == null)
     
    5760            }
    5861            CitiesClass cityClass = db.CitiesObj.Find(id);
     62            UsersClass customerClass = await getCrrentUser();
     63            ViewBag.isAuthenticated = customerClass;
    5964            if (cityClass == null)
    6065            {
    6166                return RedirectToAction("NotExist", "Error");
    6267            }
     68            // no access for standard user
     69            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     70
    6371            return View(cityClass);
    6472        }
     
    7078        //}
    7179
    72         public ActionResult Create()
     80        //public ActionResult Create()
     81        public async Task<ActionResult> CreateAsync()
    7382        {
    74            
     83            UsersClass customerClass = await getCrrentUser();
     84            // set if is authenticated
     85            ViewBag.isAuthenticated = customerClass;
     86            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
    7587            return View();
    7688        }
     
    8395        public ActionResult Create([Bind(include: "id,name")] CitiesClass cityClass)
    8496        {
     97
    8598            if (ModelState.IsValid)
    8699            {
     
    94107
    95108        // GET: Customer/Edit/5
    96         public ActionResult Edit(int? id)
     109        //  public ActionResult Edit(int? id)
     110        public async Task<ActionResult> Edit(int? id)
    97111        {
    98112            if (id == null)
     
    101115            }
    102116            CitiesClass cityClass = db.CitiesObj.Find(id);
     117            //22.08
     118            ViewBag.isAuthenticated = await getCrrentUser();
    103119            if (cityClass == null)
    104120            {
    105121                return RedirectToAction("NotExist", "Error");
    106122            }
     123            // no access for standard user
     124            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     125
    107126            return View(cityClass);
    108127        }
     
    125144
    126145        // GET: Customer/Delete/5
    127         public ActionResult Delete(int? id)
     146        // public ActionResult Delete(int? id)
     147        public async Task<ActionResult> Delete(int? id)
    128148        {
     149
     150            UsersClass customerClass = await checkAuthorizationAsync();
     151
     152            ViewBag.isAuthenticated = await getCrrentUser();
    129153            if (id == null)
    130154            {
     
    136160                return RedirectToAction("NotExist", "Error");
    137161            }
     162            // no access for standard user
     163            ViewBag.OnlyAdminManager = await checkAuthorizationSpecificRoleAsync(RoleConstants.Admin) ?? await checkAuthorizationSpecificRoleAsync(RoleConstants.Manager);
     164
    138165            return View(cityClass);
    139166        }
     
    161188
    162189
    163        
     190
    164191    }
    165192}
Note: See TracChangeset for help on using the changeset viewer.