Exemplo n.º 1
0
        public void Configure(IApplicationBuilder app,
                              IHostingEnvironment env, ILoggerFactory loggerFactory,
                              CadCliDataContext dataContext)
        {
            loggerFactory.AddConsole();

            app.UseExceptionHandler(appBuilder =>
            {
                appBuilder.Use(async(context, next) =>
                {
                    var error = context.Features[typeof(IExceptionHandlerFeature)] as IExceptionHandlerFeature;
                    if (error != null && error.Error is SecurityTokenExpiredException)
                    {
                        context.Response.StatusCode  = 401;
                        context.Response.ContentType = "application/json";
                        await context.Response.WriteAsync(
                            JsonConvert.SerializeObject(
                                new { authenticated = false, tokenExpired = true }));
                    }
                    else if (error != null && error.Error != null)
                    {
                        context.Response.StatusCode  = 500;
                        context.Response.ContentType = "application/json";
                        await context.Response.WriteAsync(
                            JsonConvert.SerializeObject
                                (new { success = false, error = error.Error.Message }));
                    }
                    else
                    {
                        await next();
                    }
                });
            });

            app.UseJwtBearerAuthentication(new JwtBearerOptions
            {
                TokenValidationParameters = new TokenValidationParameters
                {
                    IssuerSigningKey = _key,
                    ValidAudience    = _tokenOptions.Audience,
                    ValidIssuer      = _tokenOptions.Issuer,
                    ValidateLifetime = true,
                    ClockSkew        = TimeSpan.FromMinutes(0)
                }
            });

            app.UseCors(options =>
            {
                options.AllowAnyHeader();
                options.AllowAnyMethod();
                options.AllowAnyOrigin();
            });



            app.UseMvc();

            DbInitializer.Initialize(dataContext);

            app.Run(async(context) =>
            {
                context.Response.StatusCode = (int)HttpStatusCode.NotFound;
                await context.Response.WriteAsync("Recurso não encontrado!");
            });
        }
Exemplo n.º 2
0
 public ClienteRepository(CadCliDataContext context) : base(context)
 {
 }
Exemplo n.º 3
0
 public UsuarioRepository(CadCliDataContext context) : base(context)
 {
 }
Exemplo n.º 4
0
 public ClientesController(CadCliDataContext ctx)
 {
     _ctx = ctx;
 }
Exemplo n.º 5
0
 public ClienteRepository(CadCliDataContext ctx) : base(ctx) => _db = ctx.Set <Cliente>();
Exemplo n.º 6
0
 public Repository(CadCliDataContext context)
 {
     _context = context;
 }
Exemplo n.º 7
0
 public Repository(CadCliDataContext ctx) => _ctx = ctx;