-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
2,362 additions
and
260 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file added
BIN
+1.97 MB
.vs/Identity/FileContentIndex/0bd64750-db32-4d33-8c84-44308c996fe0.vsidx
Binary file not shown.
Binary file added
BIN
+12.5 KB
.vs/Identity/FileContentIndex/58027ddd-fd79-4fae-bcd3-31da4c0a37b8.vsidx
Binary file not shown.
Binary file added
BIN
+10.4 KB
.vs/Identity/FileContentIndex/79caf7f4-43ca-4593-ae03-728204b2ad1e.vsidx
Binary file not shown.
Binary file added
BIN
+7.75 KB
.vs/Identity/FileContentIndex/7c159fb5-b6db-44f3-a009-d964a3f57d4e.vsidx
Binary file not shown.
Binary file added
BIN
+33.4 KB
.vs/Identity/FileContentIndex/99604241-349e-42f4-aaed-b1cb95507d44.vsidx
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
{ | ||
"Version": 1, | ||
"WorkspaceRootPath": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\", | ||
"Documents": [ | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\views\\userroles\\manage.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:views\\userroles\\manage.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\controllers\\userrolescontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:controllers\\userrolescontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\models\\userrolesviewmodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:models\\userrolesviewmodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\views\\userroles\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:views\\userroles\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\views\\rolemanager\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:views\\rolemanager\\index.cshtml||{40D31677-CBC0-4297-A9EF-89D907823A98}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\models\\manageuserrolesviewmodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:models\\manageuserrolesviewmodel.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" | ||
}, | ||
{ | ||
"AbsoluteMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|c:\\users\\szalk\\documents\\github\\identity\\controllers\\rolemanagercontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}", | ||
"RelativeMoniker": "D:0:0:{0B954BD0-5237-409B-8B38-09B4FB91B11F}|Identity.csproj|solutionrelative:controllers\\rolemanagercontroller.cs||{A6C744A8-0E4A-4FC6-886A-064283054674}" | ||
} | ||
], | ||
"DocumentGroupContainers": [ | ||
{ | ||
"Orientation": 0, | ||
"VerticalTabListWidth": 256, | ||
"DocumentGroups": [ | ||
{ | ||
"DockedWidth": 200, | ||
"SelectedChildIndex": 3, | ||
"Children": [ | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 2, | ||
"Title": "UserRolesViewModel.cs", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Models\\UserRolesViewModel.cs", | ||
"RelativeDocumentMoniker": "Models\\UserRolesViewModel.cs", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Models\\UserRolesViewModel.cs", | ||
"RelativeToolTip": "Models\\UserRolesViewModel.cs", | ||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", | ||
"WhenOpened": "2024-03-05T11:24:13.203Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 6, | ||
"Title": "RoleManagerController.cs", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Controllers\\RoleManagerController.cs", | ||
"RelativeDocumentMoniker": "Controllers\\RoleManagerController.cs", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Controllers\\RoleManagerController.cs", | ||
"RelativeToolTip": "Controllers\\RoleManagerController.cs", | ||
"ViewState": "AQIAAAMAAAAAAAAAAAAAAAAAAAAAAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", | ||
"WhenOpened": "2024-03-05T11:19:24.994Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 1, | ||
"Title": "UserRolesController.cs", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Controllers\\UserRolesController.cs", | ||
"RelativeDocumentMoniker": "Controllers\\UserRolesController.cs", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Controllers\\UserRolesController.cs", | ||
"RelativeToolTip": "Controllers\\UserRolesController.cs", | ||
"ViewState": "AQIAAEAAAAAAAAAAAAAIwFkAAAAJAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", | ||
"WhenOpened": "2024-03-05T11:19:23.717Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 0, | ||
"Title": "Manage.cshtml", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\UserRoles\\Manage.cshtml", | ||
"RelativeDocumentMoniker": "Views\\UserRoles\\Manage.cshtml", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\UserRoles\\Manage.cshtml", | ||
"RelativeToolTip": "Views\\UserRoles\\Manage.cshtml", | ||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAoAAAAOAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|", | ||
"WhenOpened": "2024-03-05T11:18:51.876Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 3, | ||
"Title": "Index.cshtml", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\UserRoles\\Index.cshtml", | ||
"RelativeDocumentMoniker": "Views\\UserRoles\\Index.cshtml", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\UserRoles\\Index.cshtml", | ||
"RelativeToolTip": "Views\\UserRoles\\Index.cshtml", | ||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAkAAAAMAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|", | ||
"WhenOpened": "2024-03-05T11:18:44.661Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 4, | ||
"Title": "Index.cshtml", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\RoleManager\\Index.cshtml", | ||
"RelativeDocumentMoniker": "Views\\RoleManager\\Index.cshtml", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Views\\RoleManager\\Index.cshtml", | ||
"RelativeToolTip": "Views\\RoleManager\\Index.cshtml", | ||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000759|", | ||
"WhenOpened": "2024-03-05T11:22:50.059Z", | ||
"EditorCaption": "" | ||
}, | ||
{ | ||
"$type": "Document", | ||
"DocumentIndex": 5, | ||
"Title": "ManageUserRolesViewModel.cs", | ||
"DocumentMoniker": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Models\\ManageUserRolesViewModel.cs", | ||
"RelativeDocumentMoniker": "Models\\ManageUserRolesViewModel.cs", | ||
"ToolTip": "C:\\Users\\szalk\\Documents\\GitHub\\Identity\\Models\\ManageUserRolesViewModel.cs", | ||
"RelativeToolTip": "Models\\ManageUserRolesViewModel.cs", | ||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", | ||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000738|", | ||
"WhenOpened": "2024-03-05T11:20:25.019Z", | ||
"EditorCaption": "" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"CurrentProjectSetting": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"ExpandedNodes": [ | ||
"" | ||
], | ||
"SelectedNode": "\\Program.cs", | ||
"PreviewInSolutionExplorer": false | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Identity.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
|
||
namespace Identity | ||
{ | ||
public class ContextSeed | ||
{ | ||
public static async Task SeedRolesAsync(UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager) | ||
{ | ||
//Seed Roles | ||
await roleManager.CreateAsync(new IdentityRole(Enums.Roles.SuperAdmin.ToString())); | ||
await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Admin.ToString())); | ||
await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Moderator.ToString())); | ||
await roleManager.CreateAsync(new IdentityRole(Enums.Roles.Basic.ToString())); | ||
} | ||
public static async Task SeedSuperAdminAsync(UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager) | ||
{ | ||
//Seed Default User | ||
var defaultUser = new ApplicationUser | ||
{ | ||
UserName = "superadmin", | ||
Email = "superadmin@gmail.com", | ||
FirstName = "Mukesh", | ||
LastName = "Murugan", | ||
EmailConfirmed = true, | ||
PhoneNumberConfirmed = true | ||
}; | ||
if (userManager.Users.All(u => u.Id != defaultUser.Id)) | ||
{ | ||
var user = await userManager.FindByEmailAsync(defaultUser.Email); | ||
if (user == null) | ||
{ | ||
await userManager.CreateAsync(defaultUser, "123Pa$$word."); | ||
await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Basic.ToString()); | ||
await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Moderator.ToString()); | ||
await userManager.AddToRoleAsync(defaultUser, Enums.Roles.Admin.ToString()); | ||
await userManager.AddToRoleAsync(defaultUser, Enums.Roles.SuperAdmin.ToString()); | ||
} | ||
|
||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Internal; | ||
|
||
namespace Identity.Controllers | ||
{ | ||
public class RoleManagerController:Controller | ||
{ | ||
private readonly RoleManager<IdentityRole> _roleManager; | ||
public RoleManagerController(RoleManager<IdentityRole> roleManager) | ||
{ | ||
_roleManager = roleManager; | ||
} | ||
public async Task<IActionResult> Index() | ||
{ | ||
var roles = await _roleManager.Roles.ToListAsync(); | ||
return View(roles); | ||
} | ||
[HttpPost] | ||
public async Task<IActionResult> AddRole(string roleName) | ||
{ | ||
if (roleName != null) | ||
{ | ||
await _roleManager.CreateAsync(new IdentityRole(roleName.Trim())); | ||
} | ||
return RedirectToAction("Index"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using Identity.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Identity.Controllers | ||
{ | ||
public class UserRolesController : Controller | ||
{ | ||
private readonly UserManager<ApplicationUser> _userManager; | ||
private readonly RoleManager<IdentityRole> _roleManager; | ||
|
||
public UserRolesController(UserManager<ApplicationUser> userManager, RoleManager<IdentityRole> roleManager) | ||
{ | ||
_roleManager = roleManager; | ||
_userManager = userManager; | ||
} | ||
public async Task<IActionResult> Index() | ||
{ | ||
var users = await _userManager.Users.ToListAsync(); | ||
var userRolesViewModel = new List<UserRolesViewModel>(); | ||
foreach (ApplicationUser user in users) | ||
{ | ||
var thisViewModel = new UserRolesViewModel(); | ||
thisViewModel.UserId = user.Id; | ||
thisViewModel.Email = user.Email; | ||
thisViewModel.FirstName = user.FirstName; | ||
thisViewModel.LastName = user.LastName; | ||
thisViewModel.Roles = await GetUserRoles(user); | ||
userRolesViewModel.Add(thisViewModel); | ||
} | ||
return View(userRolesViewModel); | ||
} | ||
private async Task<List<string>> GetUserRoles(ApplicationUser user) | ||
{ | ||
return new List<string>(await _userManager.GetRolesAsync(user)); | ||
} | ||
public async Task<IActionResult> Manage(string userId) | ||
{ | ||
ViewBag.userId = userId; | ||
var user = await _userManager.FindByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
ViewBag.ErrorMessage = $"User with Id = {userId} cannot be found"; | ||
return View("NotFound"); | ||
} | ||
ViewBag.UserName = user.UserName; | ||
var model = new List<ManageUserRolesViewModel>(); | ||
foreach (var role in _roleManager.Roles) | ||
{ | ||
var userRolesViewModel = new ManageUserRolesViewModel | ||
{ | ||
RoleId = role.Id, | ||
RoleName = role.Name | ||
}; | ||
if (await _userManager.IsInRoleAsync(user, role.Name)) | ||
{ | ||
userRolesViewModel.Selected = true; | ||
} | ||
else | ||
{ | ||
userRolesViewModel.Selected = false; | ||
} | ||
model.Add(userRolesViewModel); | ||
} | ||
return View(model); | ||
} | ||
[HttpPost] | ||
public async Task<IActionResult> Manage(List<ManageUserRolesViewModel> model, string userId) | ||
{ | ||
var user = await _userManager.FindByIdAsync(userId); | ||
if (user == null) | ||
{ | ||
return View(); | ||
} | ||
var roles = await _userManager.GetRolesAsync(user); | ||
var result = await _userManager.RemoveFromRolesAsync(user, roles); | ||
if (!result.Succeeded) | ||
{ | ||
ModelState.AddModelError("", "Cannot remove user existing roles"); | ||
return View(model); | ||
} | ||
result = await _userManager.AddToRolesAsync(user, model.Where(x => x.Selected).Select(y => y.RoleName)); | ||
if (!result.Succeeded) | ||
{ | ||
ModelState.AddModelError("", "Cannot add selected roles to user"); | ||
return View(model); | ||
} | ||
return RedirectToAction("Index"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace Identity.Enums | ||
{ | ||
public enum Roles | ||
{ | ||
SuperAdmin, | ||
Admin, | ||
Moderator, | ||
Basic | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34622.214 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Identity", "Identity.csproj", "{0B954BD0-5237-409B-8B38-09B4FB91B11F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0B954BD0-5237-409B-8B38-09B4FB91B11F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0B954BD0-5237-409B-8B38-09B4FB91B11F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0B954BD0-5237-409B-8B38-09B4FB91B11F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0B954BD0-5237-409B-8B38-09B4FB91B11F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C3C6415E-4A8B-48C7-9B02-0C1411BDB6CA} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Identity.Models | ||
{ | ||
public class ManageUserRolesViewModel | ||
{ | ||
public string RoleId { get; set; } | ||
public string RoleName { get; set; } | ||
public bool Selected { get; set; } | ||
} | ||
} |
Oops, something went wrong.