コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(
            IApplicationBuilder app,
            IWebHostEnvironment env,
            IAppUserService appUserService,
            IAppUserRoleService appUserRoleService,
            IAppRoleService appRoleService
            )
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseExceptionHandler("/Error");

            JwtIdentityInitializer.Seed(appUserService, appUserRoleService, appRoleService).Wait();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
コード例 #2
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto,
                                                 [FromServices] IAppUserRoleService appUserRoleService,
                                                 [FromServices] IAppRoleService appRoleService)
        {
            var appUser = await _appUserService.FindByUserName
                              (appUserAddDto.UserName);

            if (appUser == null)
            {
                return(BadRequest($"{appUserAddDto.UserName} already taken"));
            }

            await _appUserService.AddAsync(_mapper.Map <AppUser>(appUserAddDto));

            var user = await _appUserService.FindByUserName(appUserAddDto.UserName);

            var role = await appRoleService.FindByName(RoleInfo.Member);

            await appUserRoleService.AddAsync(new AppUserRole
            {
                AppRoleId = role.Id,
                AppUserId = user.Id
            });

            return(Created("", appUserAddDto));
        }
コード例 #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IAppUserService appUserService, IAppUserRoleService appUserRoleService
                              , IAppRoleService appRoleService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //addSwagger
            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            app.UseExceptionHandler("/Error"); //Bir hata olunca buraya git. localhost/error

            JwtIdentityInitializer.Seed(appUserService, appUserRoleService, appRoleService).Wait();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication(); //token için authorization üstünde olmalý

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
コード例 #4
0
 public RoleController(IAppRoleService appRoleService)
 {
     this._appRoleService    = appRoleService;
     _jsonSerializerSettings = new JsonSerializerSettings
     {
         Formatting = Formatting.Indented
     };
 }
コード例 #5
0
 public AuthController(IAppUserService appUserService, IAppRoleService appRoleService, IAppUserRoleService appUserRoleService, IJwtService jwtService, IWebHostEnvironment hostingEnvironment)
 {
     _appUserService = appUserService;
     _appRoleService = appRoleService;
     _appUserRoleService = appUserRoleService;
     _jwtService = jwtService;
     _hostingEnvironment = hostingEnvironment;
 }
コード例 #6
0
ファイル: AppRoleStore.cs プロジェクト: aidanmatheney/archia
        public AppRoleStore(IAppRoleService roleService, ILogger <AppRoleStore> logger)
        {
            ThrowIf.Null(roleService, nameof(roleService));
            ThrowIf.Null(logger, nameof(logger));

            _roleService = roleService;
            _logger      = logger;
        }
コード例 #7
0
 public AppGroupController(IErrorService errorService,
                           IAppGroupService appGroupService,
                           IAppRoleService appRoleService,
                           ApplicationUserManager userManager
                           ) : base(errorService)
 {
     _appGroupService = appGroupService;
     _appRoleService  = appRoleService;
     _userManager     = userManager;
 }
コード例 #8
0
 public AppGroupController(IErrorService errorService,
                           IAppRoleService appRoleService,
                           ApplicationUserManager userManager,
                           IAppGroupService appGroupService, IUnitOfWork unitOfWork) : base(errorService)
 {
     _userManager     = userManager;
     _appGroupService = appGroupService;
     _appRoleService  = appRoleService;
     _unitOfWork      = unitOfWork;
 }
コード例 #9
0
 public UserController(IAppUserService appUserService, IAppRoleService appRoleService, ITokenService tokenService)
 {
     _appUserService         = appUserService;
     _appRoleService         = appRoleService;
     _tokenService           = tokenService;
     _jsonSerializerSettings = new JsonSerializerSettings
     {
         Formatting = Formatting.Indented
     };
 }
コード例 #10
0
 public AuthController(IServiceProvider serviceProvider)
 {
     appUserService        = serviceProvider.GetService <IAppUserService>();
     userService           = serviceProvider.GetService <IGenericService <AppUser> >();
     userRoleService       = serviceProvider.GetService <IGenericService <UserRole> >();
     appRoleService        = serviceProvider.GetService <IAppRoleService>();
     mapper                = serviceProvider.GetService <IMapper>();
     logger                = serviceProvider.GetService <ILogger <AuthController> >();
     appUserSessionService = serviceProvider.GetService <IAppUserSessionService>();
     accountHelper         = serviceProvider.GetService <AccountHelper>();
 }
コード例 #11
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService
                                      , IAppRoleService appRoleService)
        {
            //Rol varsa eklemicem yoksa eklicem
            var adminRole = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }
            var memberRole = await appRoleService.FindByNameAsync(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            //admin kullanıcı eklmedim.
            var adminUser = await appUserService.FindByUserNameAsync("ADMIN");

            if (adminUser == null)
            {
                await appUserService.Add(new AppUser
                {
                    UserName = "******",
                    Password = "******"
                });
            }
            //appuserrole tablosuna bu ilişkiyi eklemem lazım
            var role = await appRoleService.FindByNameAsync(RoleInfo.Admin);

            var admin = await appUserService.FindByUserNameAsync("ADMIN");

            //daha önce eklenmiş mi
            var allUSerRole = await appUserRoleService.GetAll();

            int kontrol = allUSerRole.Where(x => x.AppRoleId == role.Id && x.AppUserId == admin.Id).Count();

            if (kontrol == 0)
            {
                await appUserRoleService.Add(new AppUserRole
                {
                    AppRoleId = role.Id,
                    AppUserId = admin.Id
                });
            }
        }
コード例 #12
0
 public AccountController(
     ApplicationUserManager userManager,
     ApplicationSignInManager signInManager,
     IAppGroupService appGroupService,
     IAppRoleService appRoleService,
     IErrorService errorService)
     : base(errorService)
 {
     _userManager     = userManager;
     _appGroupService = appGroupService;
     _signInManager   = signInManager;
     _appRoleService  = appRoleService;
 }
コード例 #13
0
        public TokenController(IConfiguration configuration, ITokenService tokenService, IAppUserService appUserService, SignInManager <AppUser> signInManager, IAppRoleService appRoleService)
        {
            _configuration  = configuration;
            _tokenService   = tokenService;
            _appUserService = appUserService;
            _signInManager  = signInManager;
            _appRoleService = appRoleService;

            JsonSettings = new JsonSerializerSettings()
            {
                Formatting = Formatting.Indented
            };
        }
コード例 #14
0
 public AdminController(IGenericService <AppRole> genericServiceR, IApplicationUserRoleService applicationUserRoleService, IAppRoleService appRoleService, UserManager <AppUser> userManager, RoleManager <AppRole> roleManager, IMapper mapper, IYaziService yaziService, ITagService tagService, IAppUserService appUserService, IGenericService <Yazi> genericService)
 {
     _genericServiceR            = genericServiceR;
     _applicationUserRoleService = applicationUserRoleService;
     _userManager    = userManager;
     _roleManager    = roleManager;
     _appRoleService = appRoleService;
     _genericService = genericService;
     _mapper         = mapper;
     _yaziService    = yaziService;
     _tagService     = tagService;
     _appUserService = appUserService;
 }
コード例 #15
0
        private static async Task <AppRole> CheckRole(IAppRoleService appRoleService, IGenericService <AppRole> roleService, string roleName)
        {
            AppRole role = await appRoleService.FindByName(roleName);

            if (role == null)
            {
                role = new AppRole()
                {
                    Name = roleName
                };
                await roleService.AddAsync(role);
            }
            return(role);
        }
コード例 #16
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService,
                                      IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }



            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserName("veysel");

            if (adminUser == null)
            {
                await appUserService.Add(new AppUser()
                {
                    FullName = "ahmet veysel bozoğlu",
                    Password = "******",
                    UserName = "******"
                });


                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var admin = await appUserService.FindByUserName("veysel");

                await appUserRoleService.Add(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
コード例 #17
0
        public static async Task Seed(IAppUserService appUserService, IAppRoleService appRoleService, IAppUserRoleService appUserRoleService)
        {
            //have a role
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserName("enesb");

            if (adminUser == null)
            {
                await appUserService.Add(new AppUser
                {
                    UserName = "******",
                    FullName = "enes baysal",
                    Password = "******"
                });

                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var admin = await appUserService.FindByUserName("enesb");

                await appUserRoleService.Add(new AppUserRole
                {
                    AppRoleId = role.Id,
                    AppUserId = admin.Id
                });
            }
        }
コード例 #18
0
        public async static Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService,
                                      IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName("Admin");

            var memberRole = await appRoleService.FindByName("Member");

            if (adminRole == null)
            {
                await appRoleService.InsertAsync(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            if (memberRole == null)
            {
                await appRoleService.InsertAsync(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserNameAsync("pcparticle");

            if (adminUser == null)
            {
                await appUserService.InsertAsync(new AppUser
                {
                    FullName = "Erol Aksoy",
                    Password = "******",
                    UserName = "******"
                });

                var admin = await appUserService.FindByUserNameAsync("pcparticle");

                var role = await appRoleService.FindByName("Admin");

                await appUserRoleService.InsertAsync(new AppUserRole
                {
                    AppRoleId = role.Id,
                    AppUserId = admin.Id
                });
            }
        }
コード例 #19
0
        public static async Task Seed(IAppUserService appUserService,
                                      IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (adminRole == null)
            {
                await appRoleService.AddAsync(new Entities.Concrete.AppRole
                {
                    Name = RoleInfo.Member
                });
            }
            var adminUser = await appUserService.FindByUserName("Uzay");

            if (adminUser == null)
            {
                await appUserService.AddAsync(new AppUser
                {
                    FullName = "Uzay KAHRAMAN",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var admin = await appUserService.FindByUserName("Uzay");

                await appUserRoleService.AddAsync(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
コード例 #20
0
        public AppUsersController
        (
            IAppUserService appUserService,
            IAppRoleService appRoleService,
            IEmailSender emailSender,
            UserManager <AppUser> userManager,
            RoleManager <AppRole> roleManager,
            ILogger <AppUsersController> logger
        ) : base
            (
                userManager,
                roleManager,
                logger
            )
        {
            Guard.Argument(appUserService, nameof(appUserService)).NotNull();
            Guard.Argument(appRoleService, nameof(appRoleService)).NotNull();
            Guard.Argument(emailSender, nameof(emailSender)).NotNull();

            _appUserService = appUserService;
            _appRoleService = appRoleService;
            _emailSender    = emailSender;
        }
コード例 #21
0
        public static async Task Seed(IServiceProvider serviceProvider)
        {
            IAppUserService            appUserService  = serviceProvider.GetService <IAppUserService>();
            IUserRoleService           UserRoleService = serviceProvider.GetService <IUserRoleService>();
            IAppRoleService            appRoleService  = serviceProvider.GetService <IAppRoleService>();
            IGenericService <AppUser>  userService     = serviceProvider.GetService <IGenericService <AppUser> >();
            IGenericService <AppRole>  roleService     = serviceProvider.GetService <IGenericService <AppRole> >();
            IGenericService <UserRole> userRoleService = serviceProvider.GetService <IGenericService <UserRole> >();


            AppRole adminRole = await CheckRole(appRoleService, roleService, RoleInfo.Admin);

            await CheckRole(appRoleService, roleService, RoleInfo.Member);//Member Role

            AppRole developerRole = await CheckRole(appRoleService, roleService, RoleInfo.Developer);

            AppUser developerUser = await CheckUser(appUserService, userService, new AppUserAddDto()
            {
                UserName = "******", Password = "******", FullName = "Recep Şen"
            });

            await UserAddRole(UserRoleService, userRoleService, developerUser, developerRole);
            await UserAddRole(UserRoleService, userRoleService, developerUser, adminRole);
        }
コード例 #22
0
        public async Task <IActionResult> Register([FromQuery] AppUserAddDto appUserAddDto,
                                                   [FromServices] IAppUserRoleService appUserRoleService,
                                                   [FromServices] IAppRoleService appRoleService)
        {
            var user = await this.appUserService.FindByUserNameAsync(appUserAddDto.Name);

            if (user != null)
            {
                return(BadRequest($"{appUserAddDto.UserName} is already registered in the system"));
            }
            await this.appUserService.Add(this.mapper.Map <AppUser>(appUserAddDto));

            var appuser = await this.appUserService.FindByUserNameAsync(appUserAddDto.Name);

            var role = await appRoleService.FindByNameAsync(RoleInfo.Member);

            await appUserRoleService.Add(new AppUserRole
            {
                AppUserId = appuser.Id,
                AppRoleId = role.Id
            });

            return(Created("", appUserAddDto));
        }
コード例 #23
0
 public TestController(IAppRoleService appRoleService, IAppUserService appUserService, ISchoolManagerService corporationManagerService)
 {
     _appRoleService            = appRoleService;
     _appUserService            = appUserService;
     _corporationManagerService = corporationManagerService;
 }
コード例 #24
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            //ilgili rol varmı?
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserName("sametirkoren");

            if (adminUser == null)
            {
                await appUserService.Add(new AppUser
                {
                    FullName = "Samet İrkören",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var admin = await appUserService.FindByUserName("sametirkoren");

                await appUserRoleService.Add(new AppUserRole
                {
                    AppUserId = admin.Id,
                    AppRoleId = role.Id
                });
            }
        }
コード例 #25
0
 public AppRoleController(IErrorService errorService
                          , IAppRoleService appRoleService) : base(errorService)
 {
     _appRoleService = appRoleService;
 }
コード例 #26
0
ファイル: PermisionController.cs プロジェクト: nxlap97/Smart
 public PermisionController(IConfiguration configuaration, IAppRoleService roleService, IViewEnginerService viewEngineService)
 {
     _configuration     = configuaration;
     _roleService       = roleService;
     _viewEngineService = viewEngineService;
 }
コード例 #27
0
 public AppRoleController(IErrorService errorService, IAppRoleService appRoleService, IPermissionService permissionService, IFunctionService functionService) : base(errorService)
 {
     _functionService   = functionService;
     _permissionService = permissionService;
     _appRoleService    = appRoleService;
 }
コード例 #28
0
 public HomeController(IAppRoleService roleService)
 {
     _roleService = roleService;
 }
コード例 #29
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppUserRoleService appUserRoleService, [FromServices] IAppRoleService appRoleService)
        {
            var checkAppUser = await _appUserService.FindByUserName(appUserAddDto.UserName);

            if (checkAppUser != null)
            {
                return(BadRequest($"{checkAppUser.UserName} kullanıcı adı zaten alınmış."));
            }

            var appUser = _iMapper.Map <AppUser>(appUserAddDto);
            await _appUserService.Add(appUser);


            var role = await appRoleService.FindByName(RoleInfo.Member);

            await appUserRoleService.Add(new AppUserRole()
            {
                AppRoleId = role.Id,
                AppUserId = appUser.Id
            });

            return(Created("", appUserAddDto));
        }
コード例 #30
0
        public static async Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService, IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName(RoleInfo.Admin);

            if (adminRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            var memberRole = await appRoleService.FindByName(RoleInfo.Member);

            if (memberRole == null)
            {
                await appRoleService.Add(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserName("savas.ev");

            if (adminUser == null)
            {
                await appUserService.Add(new AppUser
                {
                    FullName = "Savaş Ev",
                    UserName = "******",
                    Password = "******"
                });

                var role = await appRoleService.FindByName(RoleInfo.Admin);

                var user = await appUserService.FindByUserName("savas.ev");

                await appUserRoleService.Add(new AppUserRole
                {
                    AppUserId = user.Id,
                    AppRoleId = role.Id
                });
            }
        }