Exemple #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, IStudentDBService service)
        {
            //strona z opisem błędu
            app.UseDeveloperExceptionPage();

            app.UseRouting();

            //doklejanie do nagłówka http
            app.Use(async(context, c) =>
            { //klasa http context do odpowiedzi serwera do nagłówka dodanie
                context.Response.Headers.Add("Secret", "s17557");
                await c.Invoke();
            });
            app.UseMiddleware <ExceptionMiddlewares>();
            app.UseSwagger();
            app.UseSwaggerUI(config =>
            {
                config.SwaggerEndpoint("/swagger/v1/swagger.json", "Students App API");
            });

            app.UseMiddleware <LoggingMiddlewares>();
            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Musisz podaæ nr indeksu");
                    return;
                }
                string index = context.Request.Headers["Index"].ToString();
                var student  = service.GetStudent(index);
                if (student == null)
                {
                    context.Response.StatusCode = StatusCodes.Status403Forbidden;
                    await context.Response.WriteAsync("Nie ma takiego numeru indeksu");
                    return;
                }
                await next();
            });

            app.UseMiddleware <CustomMiddlewear>();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStudentDBService sdB)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //api/v1/students domyslny api/studnets
            //api/v2/students         m


            app.UseSwagger();
            app.UseSwaggerUI(config =>
            {
                config.SwaggerEndpoint("/swagger/v1/swagger.json", "Students App Api");
            });

            app.UseMiddleware <LoggingMiddleware>();

            app.Use(async(contex, next) =>
            {
                if (!contex.Request.Headers.ContainsKey("Index"))
                {
                    contex.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await contex.Response.WriteAsync("Muszisz podac nr inesku..");
                    return;
                }
                else
                {
                    if (!sdB.StudentExist(contex.Request.Headers["Index"].ToString()))
                    {
                        contex.Response.StatusCode = StatusCodes.Status401Unauthorized;
                        await contex.Response.WriteAsync("NIe istnieje student o danym numerze indeksu");
                        return;
                    }
                } await next();
            });



            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #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, IStudentDBService studentDbService)
        {
            // app.UseWhen(context => context.Request.Path.ToString().Contains("secret"), app =>
            // {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }



            app.UseMiddleware <LoggingMiddleware>();
            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Student not found :(");
                    return;
                }

                string index = context.Request.Headers["Index"].ToString();
                var student  = studentDbService.GetStudent(index);
                Console.WriteLine(student.FirstName);
                if (student == null)
                {
                    context.Response.StatusCode = StatusCodes.Status404NotFound;
                    await context.Response.WriteAsync("Musisz podać prawidłowy numer indeksu");
                    return;
                }


                await next();
            });
            //  });


            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #4
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStudentDBService service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseMiddleware <LoggingMiddleware>();

            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Nie podano indeksu");
                    return;
                }

                var index = context.Request.Headers["Index"].ToString();

                if (!service.CheckIndex(index))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Indeks nie znajduje siê w bazie");
                    return;
                }

                await next();
            });

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #5
0
 public EnrollmentsController(IStudentDBService idb)
 {
     iDB = idb;
 }
 public EnrollmentsController(IStudentDBService service)
 {
     _service = service;
 }
 public PromotionsController(IStudentDBService service)
 {
     _service = service;
 }
 public StudentsController(IStudentDBService studentService)
 {
     this.studentService = studentService;
 }
Exemple #9
0
 public StudentsController(IConfiguration configuration, IStudentDBService dbService)
 {
     Configuration = configuration;
     _dbService    = dbService;
 }