Skip to content

Commit 2339a63

Browse files
committed
#501 Added check for user authentication, changed redirect accordingly
1 parent 3470beb commit 2339a63

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.Web.Services;
@@ -169,12 +162,17 @@ public virtual async Task<IActionResult> Index(
169162
}
170163
// page is not null at this point
171164

172-
if ((!string.IsNullOrEmpty(page.ViewRoles)))
165+
if (!string.IsNullOrEmpty(page.ViewRoles))
173166
{
174-
if (!User.IsInRoles(page.ViewRoles))
167+
if (!User.Identity.IsAuthenticated)
175168
{
176-
Log.LogWarning($"page {page.Title} is protected by roles that user is not in so returning 404");
177-
return NotFound();
169+
Log.LogWarning($"page {page.Title} is protected and user is not authenticated, returning login page and 302");
170+
return View("NotFound", 401);
171+
}
172+
else if (!User.IsInRoles(page.ViewRoles))
173+
{
174+
Log.LogWarning($"page {page.Title} is protected by roles that user is not in so returning 403");
175+
return View("NotFound", 403);
178176
}
179177
}
180178

0 commit comments

Comments
 (0)