private void LoadRoles(string roleName)
 {
     if (string.IsNullOrEmpty(roleName))
     {
         RolesList = RolesService.GetAll();
     }
 }
Exemple #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool UserHasRequiredRole = false;
            var  userName            = filterContext.HttpContext.User.Identity.Name;

            var userRoles = RolesService.GetUserRoles(userName);

            if (string.IsNullOrWhiteSpace(RequiredRoles))
            {
                UserHasRequiredRole = true;
            }
            else
            {
                var roles = RequiredRoles.Split('|');
                foreach (var role in roles)
                {
                    if (userRoles.Contains(role.ToLower()))
                    {
                        UserHasRequiredRole = true;
                        break;
                    }
                }
            }

            if (!UserHasRequiredRole)
            {
                var routeValues = new RouteValueDictionary();
                filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "User", action = "Home", MissingRole = RequiredRoles }));
            }
        }
Exemple #3
0
        /// <summary>
        /// 登录功能
        /// </summary>
        /// <param name="model">登陆对象</param>
        /// <returns></returns>
        public async Task <AdminDto> AdminLogin(AdminDto model)
        {
            var data = _service.QueryAllAsync(m => m.AdminName.Equals(model.AdminName) &&
                                              m.AdminPassword.Equals(model.AdminPassword) &&
                                              m.IsRemove == false).FirstOrDefault();

            if (data == null)
            {
                return(null);
            }

            var admin = new AdminDto()
            {
                Id        = data.Id,
                AdminName = data.AdminName,
                ImagePath = data.ImagePath,
                RolesId   = data.RolesId
            };
            IRolesService service = new RolesService();
            var           roles   = await service.QueryAsync(admin.RolesId);

            admin.RolesName = roles.RolesName;

            return(admin);
        }
        public async Task GetAllRoles_Returns_Roles()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "InMemoryDatabase")
                          .Options;

            var mockUserInfoProvider = new MockUserInfoProvider("Test User");

            // Setup some data
            using (var context = new ApplicationDbContext(options, mockUserInfoProvider))
            {
                context.Roles.Add(new Role("TestUser")
                {
                    Name        = "SomeRole",
                    Description = "SomeRole"
                });
                await context.SaveChangesAsync();
            }

            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ApplicationDbContext(options, mockUserInfoProvider))
            {
                // Arrange
                var service = new RolesService(context, mockUserInfoProvider);

                // Act
                var roles = (await service.GetRoles()).ToList();

                // Assert
                Assert.Equal(1, roles.Count);
                Assert.Equal("SomeRole", roles.First().Name);
                Assert.Equal("TestUser", roles.First().CreatedBy);
            }
        }
Exemple #5
0
 public LibrariesController(LibrariesService librariesService, IMapper mapper, LocationsService locationsService, RolesService rolesService)
 {
     Locations = locationsService;
     Libraries = librariesService;
     Roles     = rolesService;
     Mapper    = mapper;
 }
Exemple #6
0
 public RolesController(IMapper mapper, RolesService rolesService, LibrariesService librariesService, UsersService usersService)
 {
     Users     = usersService;
     Mapper    = mapper;
     Roles     = rolesService;
     Libraries = librariesService;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider serviceProvider, AppDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/errors/Error500");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseSession();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseStatusCodePagesWithRedirects("/Errors/{0}");
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });

            RolesService.CreateRoles(serviceProvider).Wait();
            RolesService.CreateRootUser(serviceProvider, Configuration).Wait();
        }
Exemple #8
0
 public BorrowsController(BorrowsService borrowsService, IMapper mapper, UsersService usersService, BooksService booksService, RolesService rolesService)
 {
     Roles   = rolesService;
     Books   = booksService;
     Users   = usersService;
     Mapper  = mapper;
     Borrows = borrowsService;
 }
Exemple #9
0
 public AdministrationController(IQueryBus queryBus, UsersService usersService, DirectMessagesService directMessagesService, MessagesServiceFactory messagesServiceFactory, RolesService rolesService)
 {
     this._queryBus               = queryBus;
     this._usersService           = usersService;
     this._directMessagesService  = directMessagesService;
     this._messagesServiceFactory = messagesServiceFactory;
     this._rolesService           = rolesService;
 }
Exemple #10
0
 public UsersController(IMapper mapper, UsersService usersService, BorrowsService borrowsService, ReviewsService reviewsService, RolesService rolesService)
 {
     Borrows = borrowsService;
     Reviews = reviewsService;
     Mapper  = mapper;
     Users   = usersService;
     Roles   = rolesService;
 }
Exemple #11
0
 public BooksController(IMapper mapper, LibrariesService librariesService, BooksService booksService, ReviewsService reviewsService, RolesService rolesService)
 {
     Mapper    = mapper;
     Libraries = librariesService;
     Books     = booksService;
     Reviews   = reviewsService;
     Roles     = rolesService;
 }
Exemple #12
0
 public RolesController(RolesService roleservice,
                        IFileStorage fileStorage,
                        IMapper mapper)
 {
     _roleservice = roleservice;
     _fileStorage = fileStorage;
     _mapper      = mapper;
 }
Exemple #13
0
 public UsersController(IQueryBus queryBus, MessagesServiceFactory messagesServiceFactory, RolesService rolesService, UsersService usersService, ResponsesService responsesService)
 {
     this._queryBus = queryBus;
     this._messagesServiceFactory = messagesServiceFactory;
     this._rolesService           = rolesService;
     this._usersService           = usersService;
     this._responsesService       = responsesService;
 }
Exemple #14
0
 public JwtAuthController(AuthService _authService, ILogger <JwtAuthController> _log,
                          UserManager <ApplicationUser> _userManager, RolesService _rolesService)
 {
     authService  = _authService;
     log          = _log;
     userManager  = _userManager;
     rolesService = _rolesService;
 }
Exemple #15
0
        public ActionResult ListPermissions()
        {
            var res = RolesService.ListPermissions();

            return(Json(new ResultBase <List <PermissionGroup> >()
            {
                success = true, data = res
            }));
        }
 public AccountsController(UsuarioService usuarioservice, RolesService rolservice,
     PermisosService permisoservice,
     IConfiguration configuration)
 {
     _rolservice = rolservice;
     _usuarioservice = usuarioservice;
     _permisoservice = permisoservice;
     _configuration = configuration;
 }
Exemple #17
0
        public ModificarPerfilController(UsuarioService usuarioservice,
                                         RolesService roleservice, IFileStorage fileStorage,
                                         IMapper mapper)

        {
            _usuarioservice = usuarioservice;
            _roleservice    = roleservice;
            _fileStorage    = fileStorage;
            _mapper         = mapper;
        }
Exemple #18
0
 public WindowsAuthController(AuthService _authService, ILogger <WindowsAuthController> _log,
                              ActiveDirectoryService _activeDirectoryController,
                              UserManager <ApplicationUser> _userManager, RolesService _rolesService)
 {
     authService = _authService;
     activeDirectoryController = _activeDirectoryController;
     log          = _log;
     userManager  = _userManager;
     rolesService = _rolesService;
 }
Exemple #19
0
 public UsuariosController(BandejaService bandejaservice, UsuarioService usuarioservice,
                           RolesService roleservice, IFileStorage fileStorage,
                           IMapper mapper)
 {
     _bandejaservice = bandejaservice;
     _usuarioservice = usuarioservice;
     _roleservice    = roleservice;
     _fileStorage    = fileStorage;
     _mapper         = mapper;
 }
Exemple #20
0
        private AuthorizationController GetMockRepositoryController()
        {
            var userRepository  = new TestUserRepository();
            var rolesRepository = new TestRolesRepository();

            var userService  = new UserService(userRepository);
            var rolesService = new RolesService(userRepository, rolesRepository);

            var controller = new AuthorizationController(userService, rolesService);

            return(controller);
        }
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            /* Service Validation */
            RolesService service = (RolesService)validationContext.GetService(typeof(RolesService));

            if (service.DbContext.Set <Role>().Count(r => r._IsDeleted.Equals(false) && r.Id != this.Id && r.Code.Equals(this.Code)) > 0) /* Unique */
            {
                yield return(new ValidationResult("Code already exists", new List <string> {
                    "Code"
                }));
            }
        }
Exemple #22
0
 protected override void LoadWorkerDoWork(object sender, DoWorkEventArgs e)
 {
     Utils.EnsureCulture();
     OnReloading = true;
     Dispatcher.Invoke(new Action(() => {
         aiLoader.Visibility    = Visibility.Visible;
         tbNoResults.Visibility = Visibility.Collapsed;
     }));
     e.Result = e.Argument == null
                    ? RolesService.Instanse.GetAll()
                    : RolesService.GetAllContains(e.Argument.ToString());
 }
Exemple #23
0
 public AdministrationController(IQueryBus queryBus, UsersService usersService, DirectMessagesService directMessagesService, MessagesServiceFactory messagesServiceFactory, RolesService rolesService, TrustRolesService trustRolesService, CheckUserSafetyService checkUserSafetyService, UsersRolesService usersRolesService, IConfigurationService configurationService)
 {
     this._queryBus               = queryBus;
     this._usersService           = usersService;
     this._directMessagesService  = directMessagesService;
     this._messagesServiceFactory = messagesServiceFactory;
     this._rolesService           = rolesService;
     this._trustRolesService      = trustRolesService;
     this._checkUserSafetyService = checkUserSafetyService;
     this._usersRolesService      = usersRolesService;
     this._configurationService   = configurationService;
 }
Exemple #24
0
        protected override void RemoveWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (dgvResults.SelectedItems.Count == 0 || dgvResults.SelectedItem == null)
            {
                return;
            }

            OnReloading = true;

            var roles = dgvResults.SelectedItems.OfType <Role>().ToList();

            if (roles.Count > 0)
            {
                var failed       = false;
                var removedCount = 0;
                if (Global.DeleteQuestion(this))
                {
                    var progressResources = new ProgressWindow(roles.Count);
                    progressResources.Show(this);
                    foreach (var role in roles)
                    {
                        if (RolesService.ReferencedToOther(role.RoleID))
                        {
                            Global.ReferenceFound(this, RolesResources.Referenced);
                        }
                        else if (!RolesService.Instanse.Remove(role))
                        {
                            failed = true;
                            Global.DeletionFailed(this);
                        }
                        else
                        {
                            removedCount++;
                        }
                        progressResources.IncreaseProgress();
                    }
                    progressResources.Close();
                    if (roles.Count > 1 && failed)
                    {
                        Global.DeletionSuceededWithSomeFailures(this);
                    }
                    else if (removedCount > 0 & !failed)
                    {
                        Global.DeletionSuceeded(this);
                    }
                    ResetFields();
                    TryToLoad();
                }
            }

            OnReloading = false;
        }
Exemple #25
0
        /// <summary>
        /// 获取权限列表
        /// </summary>
        /// <returns></returns>
        public IQueryable <RolesDto> GetRoles()
        {
            IRolesService service = new RolesService();

            var data = service.QueryAllAsync().Where(m => m.IsRemove == false)
                       .Select(m => new RolesDto()
            {
                Id        = m.Id,
                RolesName = m.RolesName
            });

            return(data);
        }
 static void Main(string[] args)
 {
     try
     {
         var baseUrl      = "https://localhost:44325/api/v1/";
         var rolesService = new RolesService(baseUrl);
         var role         = rolesService.GetRole(1);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Exemple #27
0
        public async Task HasRoleWithIdTest()
        {
            var context   = EssayCompetitionContextInMemoryFactory.InitializeContext();
            var roleName1 = "Ninja1";
            var role      = await this.seeder.SeedRoleAsync(context, roleName1);

            var roleRepository = new EfDeletableEntityRepository <ApplicationRole>(context);
            var service        = new RolesService(roleRepository);

            var result = service.HasRoleWithId(role.Id);

            Assert.True(result == true, "HasRoleWithId method does not work correctly");
        }
        public async Task <IActionResult> OnGet(string roleId)
        {
            var result = await RolesService.GetById(roleId);

            ModelState.Merge(result);

            if (!ModelState.IsValid)
            {
                ShowMessage(CoreEnumerations.MessageTypes.danger, ModelState.GetErrors(" , "));

                return(RedirectToPage("/Roles/Index", new { area = "UserManagementAdmin" }));
            }
            Input = result.Value;
            return(Page());
        }
Exemple #29
0
        public async Task CreateRoleAsyncTest()
        {
            var context       = EssayCompetitionContextInMemoryFactory.InitializeContext();
            var roleName      = "Ninja";
            var roleViewModel = new CreateViewModel()
            {
                Name = roleName
            };
            var roleRepository = new EfDeletableEntityRepository <ApplicationRole>(context);
            var service        = new RolesService(roleRepository);

            await service.CreateRoleAsync <CreateViewModel>(roleViewModel.ToQueryable());

            Assert.True(roleRepository.All().Any(x => x.Name == roleName), "CreateRoleAsync method does not work correctly");
        }
Exemple #30
0
        public UnitOfWork(ApplicationDbContext dbContext)
        {
            this.dbContext = dbContext;

            DocumentsService             = new DocumentsService(dbContext);
            DocumentsStatesService       = new DocumentsStatesService(dbContext);
            DocumentsTemplateItemService = new DocumentsTemplateItemService(dbContext);
            DocumentsTemplateService     = new DocumentsTemplateService(dbContext);
            DocumentTaskTemplatesService = new DocumentTaskTemplatesService(dbContext);
            DocumentTasksService         = new DocumentTasksService(dbContext);
            LogsService       = new LogsService(dbContext);
            RolesService      = new RolesService(dbContext);
            TagsService       = new TagsService(dbContext);
            UsersService      = new UsersService(dbContext);
            UserGroupsService = new UserGroupsService(dbContext);
        }
        // public static IEnumerable<SelectListItem> FilldllPayPlanSetup()
        // {
        //     var service = new PayPlanSetup();
        //     var PayPlanSetups = service.GetAll();
        //     var listitems = PayPlanSetups.Select(x =>
        public static IEnumerable<SelectListItem> FillddlRoles()
        {
            var service = new RolesService();
            var ethenics = service.GetAll();
            var listitems = ethenics.Select(x =>

               //         new SelectListItem
               //         {
               //             Text = x.PayPlanSetupName,
               //             Value = x.Id.ToString()
               //         });
               //     return listitems;
               // }

                new SelectListItem
                {
                    Text = x.RoleName,
                    Value = x.Id.ToString()
                });
            return listitems;
        }
 public RolesController()
 {
     service = new RolesService();
 }