Skip to content

Commit 1e28324

Browse files
authored
Merge pull request #641 from cloudscribe/feature/501
#501 Added check for user authentication, changed redirect accordingly
2 parents cd9175b + 0c7d154 commit 1e28324

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

src/cloudscribe.SimpleContent.Web/Controllers/PageController.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
// Copyright (c) Source Tree Solutions, LLC. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3-
// Author: Joe Audette
4-
// Created: 2016-02-24
5-
// Last Modified: 2019-02-17
6-
//
7-
8-
using cloudscribe.DateTimeUtils;
1+
using cloudscribe.DateTimeUtils;
92
using cloudscribe.SimpleContent.Models;
103
using cloudscribe.SimpleContent.Models.Versioning;
114
using cloudscribe.SimpleContent.Services;
@@ -174,12 +167,17 @@ public virtual async Task<IActionResult> Index(
174167
}
175168
// page is not null at this point
176169

177-
if ((!string.IsNullOrEmpty(page.ViewRoles)))
170+
if (!string.IsNullOrEmpty(page.ViewRoles))
178171
{
179-
if (!User.IsInRoles(page.ViewRoles))
172+
if (!User.Identity.IsAuthenticated)
180173
{
181-
Log.LogWarning($"page {page.Title} is protected by roles that user is not in so returning 404");
182-
return NotFound();
174+
Log.LogWarning($"page {page.Title} is protected and user is not authenticated, returning login page and 302");
175+
return View("NotFound", 401);
176+
}
177+
else if (!User.IsInRoles(page.ViewRoles))
178+
{
179+
Log.LogWarning($"page {page.Title} is protected by roles that user is not in so returning 403");
180+
return View("NotFound", 403);
183181
}
184182
}
185183

0 commit comments

Comments
 (0)