diff --git a/Sledgemapper.Api/Infrastructure/Data/SledgemapperDbContext.cs b/Sledgemapper.Api/Infrastructure/Data/SledgemapperDbContext.cs index 265d446..195b192 100644 --- a/Sledgemapper.Api/Infrastructure/Data/SledgemapperDbContext.cs +++ b/Sledgemapper.Api/Infrastructure/Data/SledgemapperDbContext.cs @@ -37,19 +37,19 @@ namespace Sledgemapper.Api.Infrastructure.Data // options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName); // }); - optionsBuilder.UseSqlite("Filename=Sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); + optionsBuilder.UseSqlite("Filename=db/sledgemapper.db").UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); base.OnConfiguring(optionsBuilder); } protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasOne(e=>e.Owner); - -modelBuilder.Entity().HasMany(e=>e.InvitedUsers).WithMany(e=>e.Campaigns); + modelBuilder.Entity().HasOne(e => e.Owner); - modelBuilder.Entity() //Use your application user class here - .ToTable( "Users" ); //Set the table name here + modelBuilder.Entity().HasMany(e => e.InvitedUsers).WithMany(e => e.Campaigns); + + modelBuilder.Entity() //Use your application user class here + .ToTable("Users"); //Set the table name here // // Map table names // modelBuilder.Entity().ToTable("MapLog", "dbo"); diff --git a/Sledgemapper.Api/Startup.cs b/Sledgemapper.Api/Startup.cs index 84bf827..0928fd3 100644 --- a/Sledgemapper.Api/Startup.cs +++ b/Sledgemapper.Api/Startup.cs @@ -1,30 +1,57 @@ using System; +using System.Text; +using MediatR; +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Sledgemapper.Api.Infrastructure.Data; -using Microsoft.EntityFrameworkCore; -using MediatR; using Microsoft.IdentityModel.Tokens; -using Microsoft.AspNetCore.Authentication.JwtBearer; -using System.Text; -using Sledgemapper.Api.Hubs; using Microsoft.OpenApi.Models; using Newtonsoft.Json; using Sledgemapper.Api.Core.Entities; +using Sledgemapper.Api.Hubs; +using Sledgemapper.Api.Infrastructure.Data; namespace Sledgemapper.Api { public class Startup { private readonly IWebHostEnvironment _env; - public IConfiguration Configuration { get; } + public Startup(IWebHostEnvironment env, IConfiguration configuration) { Configuration = configuration; _env = env; + } + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SledgemapperDbContext dataContext) + { + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(); + + // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), + // specifying the Swagger JSON endpoint. + app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); + + dataContext.Database.Migrate(); + + app.UseRouting(); + + app.UseCors(x => x + .AllowAnyOrigin() + .AllowAnyMethod() + .AllowAnyHeader()); + app.UseAuthentication(); + app.UseAuthorization(); + + app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); + + app.UseEndpoints(endpoints => { endpoints.MapHub("/sledgemapperhub"); }); } // This method gets called by the runtime. Use this method to add services to the container. @@ -34,14 +61,16 @@ namespace Sledgemapper.Api services.AddControllers().AddNewtonsoftJson(o => { o.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; - }); ; - - + }); services.AddSignalR(); services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); services.AddMediatR(typeof(Startup)); - services.AddDbContext(options => { options.UseSqlite("Data Source=db/sledgemapper.db"); options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); }); + services.AddDbContext(options => + { + options.UseSqlite("Data Source=db/sledgemapper.db"); + options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking); + }); services.Configure(Configuration.GetSection("JwtConfig")); @@ -49,29 +78,30 @@ namespace Sledgemapper.Api // within this section we are configuring the authentication and setting the default scheme services.AddAuthentication(options => - { - options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; - }) - .AddJwtBearer(jwt => - { - var key = Encoding.ASCII.GetBytes(Configuration["JwtConfig:Secret"]); - - jwt.SaveToken = true; - jwt.TokenValidationParameters = new TokenValidationParameters { - ValidateIssuerSigningKey = true, // this will validate the 3rd part of the jwt token using the secret that we added in the appsettings and verify we have generated the jwt token - IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption - ValidateIssuer = false, - ValidateAudience = false, - RequireExpirationTime = false, - ValidateLifetime = true - }; - }); + options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; + options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; + }) + .AddJwtBearer(jwt => + { + var key = Encoding.ASCII.GetBytes(Configuration["JwtConfig:Secret"]); + + jwt.SaveToken = true; + jwt.TokenValidationParameters = new TokenValidationParameters + { + ValidateIssuerSigningKey = + true, // this will validate the 3rd part of the jwt token using the secret that we added in the appsettings and verify we have generated the jwt token + IssuerSigningKey = new SymmetricSecurityKey(key), // Add the secret key to our Jwt encryption + ValidateIssuer = false, + ValidateAudience = false, + RequireExpirationTime = false, + ValidateLifetime = true + }; + }); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = false) - .AddEntityFrameworkStores(); + .AddEntityFrameworkStores(); services.AddSwaggerGen(c => { @@ -87,57 +117,21 @@ namespace Sledgemapper.Api Name = "Authorization", Type = SecuritySchemeType.ApiKey }); - c.AddSecurityRequirement(new OpenApiSecurityRequirement { - { new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "Bearer" - } - }, - Array.Empty() + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + } + }, + Array.Empty() } - }); - }); - - - - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SledgemapperDbContext dataContext) - { - // Enable middleware to serve generated Swagger as a JSON endpoint. - app.UseSwagger(); - - // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), - // specifying the Swagger JSON endpoint. - app.UseSwaggerUI(c => - { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); - }); - - dataContext.Database.Migrate(); - - app.UseRouting(); - - app.UseCors(x => x - .AllowAnyOrigin() - .AllowAnyMethod() - .AllowAnyHeader()); - app.UseAuthentication(); - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - - app.UseEndpoints(endpoints => - { - endpoints.MapHub("/sledgemapperhub"); + }); }); } } -} +} \ No newline at end of file diff --git a/Sledgemapper.Api/appsettings.Development.json b/Sledgemapper.Api/appsettings.Development.json index 996eb73..f66b5e3 100644 --- a/Sledgemapper.Api/appsettings.Development.json +++ b/Sledgemapper.Api/appsettings.Development.json @@ -1,12 +1,12 @@ -{ - "ConnectionStrings": { - "WebApiDatabase": "Data Source=db/LocalDatabase.db" - }, - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" +{ + "ConnectionStrings": { + "WebApiDatabase": "Data Source=db/sledgemapper.db" + }, + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } } - } } diff --git a/Sledgemapper.Api/appsettings.Production.json b/Sledgemapper.Api/appsettings.Production.json index 996eb73..f66b5e3 100644 --- a/Sledgemapper.Api/appsettings.Production.json +++ b/Sledgemapper.Api/appsettings.Production.json @@ -1,12 +1,12 @@ -{ - "ConnectionStrings": { - "WebApiDatabase": "Data Source=db/LocalDatabase.db" - }, - "Logging": { - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" +{ + "ConnectionStrings": { + "WebApiDatabase": "Data Source=db/sledgemapper.db" + }, + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } } - } } diff --git a/Sledgemapper/CommunicationManager.cs b/Sledgemapper/CommunicationManager.cs index ec61b0e..36adb4b 100644 --- a/Sledgemapper/CommunicationManager.cs +++ b/Sledgemapper/CommunicationManager.cs @@ -35,11 +35,12 @@ namespace Sledgemapper _queue = new ChannelsQueue(Messenger); #if DEBUG var baseAddress = "http://localhost:5000"; + baseAddress = "http://hub.michelescandura.com:5001"; #else - var baseAddress = "http://hub.michelescandura.com:5000"; + var baseAddress = "http://hub.michelescandura.com:5001"; #endif - CheckLogin(); + CheckLogin(); _retryPolicy = Policy .Handle(ex => ex.StatusCode == HttpStatusCode.RequestTimeout) diff --git a/Sledgemapper/UI/LoginRegisterWindow.Custom.cs b/Sledgemapper/UI/LoginRegisterWindow.Custom.cs index 73dee30..de7d04e 100644 --- a/Sledgemapper/UI/LoginRegisterWindow.Custom.cs +++ b/Sledgemapper/UI/LoginRegisterWindow.Custom.cs @@ -21,7 +21,7 @@ namespace Sledgemapper.UI _messenger = messenger; #if DEBUG - TxtEmail.Text = "michele.scandura@outlook.com"; + TxtEmail.Text = "michele.scandura@sloutlook.com"; TxtPassword.Text = "slePharland!79"; #endif