Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
uness126 committed Oct 14, 2022
1 parent 71b4fce commit a7ab718
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "6.0.9",
"commands": [
"dotnet-ef"
]
}
}
}
1 change: 1 addition & 0 deletions Controllers/WeatherController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public IActionResult Authenticate(AuthenticateRequest model)

[Authorize]
[HttpGet("[action]/{city}")]
[ResponseCache(CacheProfileName = "Cache1min")]
public IActionResult Get(string city)
{
var weather = _weatherForecast.GetForecast(city);
Expand Down
2 changes: 0 additions & 2 deletions Helpers/JwtMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ private void attachUserToContext(HttpContext context, IUserService userService,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false,
// set clockskew to zero so tokens expire exactly at token expiration time (instead of 5 minutes later)
ClockSkew = TimeSpan.Zero
}, out SecurityToken validatedToken);

var jwtToken = (JwtSecurityToken)validatedToken;
var userId = int.Parse(jwtToken.Claims.First(x => x.Type == "id").Value);

// attach user to context on successful jwt validation
context.Items["User"] = userService.GetById(userId);
}
catch
Expand Down
14 changes: 13 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
using log4net.Core;
using Microsoft.AspNetCore.Mvc;
using Weather;
using Weather.Extensions;
using Weather.Helpers;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors();
builder.Services.AddControllers();
builder.Services.AddControllers(options =>
{
options.CacheProfiles.Add("Cache1min",
new CacheProfile
{
Duration = 60,
Location = ResponseCacheLocation.Client
});
});

#region Add Services

Expand All @@ -25,6 +34,8 @@
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddResponseCaching();

var app = builder.Build();

// Configure the HTTP request pipeline.
Expand All @@ -47,5 +58,6 @@
app.UseMiddleware<JwtMiddleware>();

app.MapControllers();
app.UseResponseCaching();

app.Run();
2 changes: 1 addition & 1 deletion Weather.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<NameOfLastUsedPublishProfile>F:\Uness\Programming\C# program\Weather\Weather\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
<NameOfLastUsedPublishProfile>FolderProfile</NameOfLastUsedPublishProfile>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"OpenWeatherMap": {
"Api": "YOUR API FOR WEBSERVICE"
//YOUR API FOR WEBSERVICE
},
"AllowedHosts": "*"
}

0 comments on commit a7ab718

Please sign in to comment.