public ActionResult Index(string searchKey = "") { var permissions = _nccPermissionService.LoadAll(); ViewBag.RoleList = new SelectList(permissions, "Id", "Name"); searchKey = searchKey ?? ""; searchKey = searchKey.Trim(); var users = GetUsersViewModelList(searchKey); ViewBag.SearchKey = searchKey; return(View(users)); }
private NccPermission GetRandomPermission() { var itemList = _nccPermissionService.LoadAll(); int r = rnd.Next(itemList.Count); return(itemList[r]); }
public ActionResult ManageUserRoles() { var permissions = _nccPermissionService.LoadAll(); var permissionViewModels = new List <PermissionViewModel>(); foreach (var item in permissions) { var moduleCount = item.PermissionDetails.GroupBy(x => x.ModuleName).Count(); var menuCount = item.PermissionDetails.GroupBy(x => x.Action).Count(); var userCount = item.Users.Count; var pvm = new PermissionViewModel() { Id = item.Id, Group = item.Group, Name = item.Name, Description = item.Description, ModuleCount = moduleCount, MenuCount = menuCount, UserCount = userCount }; permissionViewModels.Add(pvm); } return(View(permissionViewModels)); }
public ActionResult CreateEdit(string userName = "") { var activeModules = GlobalContext.GetActiveModules(); ViewBag.Modules = activeModules; var permissions = _nccPermissionService.LoadAll(); ViewBag.Roles = new SelectList(permissions, "Id", "Name"); var user = new UserViewModel(); if (!string.IsNullOrEmpty(userName)) { NccUser nccUser = _nccUserService.GetByUserName(userName); user = new UserViewModel(nccUser); ViewBag.Roles = new SelectList(permissions, "Id", "Name", nccUser.Permissions.Select(x => x.PermissionId).ToArray()); } return(View(user)); }
public StartupViewModel PrepareStartupViewData() { var setupConfig = SetupHelper.LoadSetup(); var model = new StartupViewModel(); var moduleSiteMenuList = new List <SiteMenuItem>(); var roleList = _nccPermissionService.LoadAll().Select(x => new { Name = x.Name, Value = x.Id }).ToList(); model.Url = setupConfig.StartupUrl; model.StartupType = setupConfig.StartupType; //original was Slug , Title model.Pages = new SelectList(_pageService.LoadAll(true), "Id", "Name", setupConfig.StartupData); model.Posts = new SelectList(_postService.Load(0, 100, true, true), "Id", "Name", setupConfig.StartupData); model.Categories = new SelectList(_categoryService.LoadAll(true), "Id", "Name", setupConfig.StartupData); NccMenuHelper.GetModulesSiteMenus().Select(x => x.Value).ToList().ForEach(x => moduleSiteMenuList.AddRange(x)); model.ModuleSiteMenus = new SelectList(moduleSiteMenuList, "Url", "Url", setupConfig.StartupData); model.Roles = new SelectList(roleList, "Value", "Name"); ViewBag.RoleStartups = _startupService.LoadAll(true, 0, "", false); ViewBag.DefaultChecked = ""; ViewBag.PageChecked = ""; ViewBag.CategoryChecked = ""; ViewBag.PostChecked = ""; ViewBag.ModuleChecked = ""; if (setupConfig.StartupType == StartupTypeText.Page) { ViewBag.PageChecked = "checked"; } else if (setupConfig.StartupType == StartupTypeText.Post) { ViewBag.PostChecked = "checked"; } else if (setupConfig.StartupType == StartupTypeText.Category) { ViewBag.CategoryChecked = "checked"; } else if (setupConfig.StartupType == StartupTypeText.Module) { ViewBag.ModuleChecked = "checked"; } else { ViewBag.DefaultChecked = "checked"; } return(model); }
public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null) { if (string.IsNullOrEmpty(returnUrl)) { returnUrl = NccUrlHelper.AddLanguageToUrl(CurrentLanguage, "/CmsHome"); } ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, set lockoutOnFailure: true var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { _logger.LogInformation("User logged in."); var user = _nccUserService.GetByUserName(model.Email); var roles = _nccPermissionService.LoadAll(); var rsp = FireEvent(UserActivity.Type.Logedin, model.Email, user, roles.Select(x => x.Name).ToList(), returnUrl); if (rsp != null) { returnUrl = rsp.ReturnUrl; } foreach (var item in user.Roles) { if (item.Role.Name == NccCmsRoles.SuperAdmin) { return(RedirectToLocal("/Admin")); } } var startups = _startupService.LoadAll(); foreach (var item in startups) { if (user.Permissions.Where(x => x.Permission.Name == item.Permission.Name).Count() > 0) { return(Redirect(item.StartupUrl)); } } return(RedirectToLocal(returnUrl)); } if (result.RequiresTwoFactor) { return(RedirectToAction(nameof(LoginWith2fa), new { returnUrl, model.RememberMe })); } if (result.IsLockedOut) { _logger.LogWarning("User account locked out."); return(RedirectToAction(nameof(Lockout))); } else { ModelState.AddModelError(string.Empty, "Invalid login attempt."); return(View(model)); } } // If we got this far, something failed, redisplay form return(View(model)); }