Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar65
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Нурбек Созоев
webinar65
Commits
8105692c
Commit
8105692c
authored
Jun 27, 2019
by
Нурбек Созоев
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Разграничил доступы к ресурсам посредством ролей
parent
04706103
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
1 deletion
+30
-1
AccountController.cs
webinar65/Controllers/AccountController.cs
+6
-0
HomeController.cs
webinar65/Controllers/HomeController.cs
+1
-1
RoleController.cs
webinar65/Controllers/RoleController.cs
+2
-0
UserController.cs
webinar65/Controllers/UserController.cs
+5
-0
AccessDenied.cshtml
webinar65/Views/Account/AccessDenied.cshtml
+16
-0
No files found.
webinar65/Controllers/AccountController.cs
View file @
8105692c
...
...
@@ -55,5 +55,11 @@ namespace webinar65.Controllers
return
RedirectToAction
(
"Login"
);
}
public
IActionResult
AccessDenied
(
string
returnUrl
)
{
ViewBag
.
returnUrl
=
returnUrl
;
return
View
();
}
}
}
webinar65/Controllers/HomeController.cs
View file @
8105692c
...
...
@@ -5,7 +5,7 @@ using webinar65.Models;
namespace
webinar65.Controllers
{
[
Authorize
]
[
Authorize
(
Roles
=
"Users,Admins"
)
]
public
class
HomeController
:
Controller
{
public
IActionResult
Index
()
...
...
webinar65/Controllers/RoleController.cs
View file @
8105692c
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
webinar65.ViewModels
;
namespace
webinar65.Controllers
{
[
Authorize
(
Roles
=
"Admins"
)]
public
class
RoleController
:
Controller
{
private
RoleManager
<
IdentityRole
>
_roleManager
;
...
...
webinar65/Controllers/UserController.cs
View file @
8105692c
using
System.Linq
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Identity
;
using
Microsoft.AspNetCore.Mvc
;
using
webinar65.Models
;
...
...
@@ -7,6 +8,7 @@ using webinar65.ViewModels;
namespace
webinar65.Controllers
{
[
Authorize
(
Roles
=
"Admins"
)]
public
class
UserController
:
Controller
{
private
UserManager
<
User
>
_userManager
;
...
...
@@ -44,7 +46,10 @@ namespace webinar65.Controllers
var
result
=
await
_userManager
.
CreateAsync
(
newUser
,
model
.
Password
);
if
(
result
.
Succeeded
)
{
await
_userManager
.
AddToRoleAsync
(
newUser
,
model
.
RoleName
);
return
RedirectToAction
(
"Index"
);
}
foreach
(
var
error
in
result
.
Errors
)
{
...
...
webinar65/Views/Account/AccessDenied.cshtml
0 → 100644
View file @
8105692c
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>
Forbidden
</title>
</head>
<body>
<div>
<h1>
Access Denied
</h1>
</div>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment