Skip to content

Commit 5f004ef

Browse files
committed
Add project files.
1 parent ce24785 commit 5f004ef

18 files changed

+1243
-0
lines changed

AuthDemo.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34031.279
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AuthDemo", "AuthDemo\AuthDemo.csproj", "{164B5D53-1253-44ED-A9EA-00C30AA0F6E2}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{164B5D53-1253-44ED-A9EA-00C30AA0F6E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{164B5D53-1253-44ED-A9EA-00C30AA0F6E2}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{164B5D53-1253-44ED-A9EA-00C30AA0F6E2}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{164B5D53-1253-44ED-A9EA-00C30AA0F6E2}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {9341B93E-1A31-40FA-8DF3-F9CF07DBABC2}
24+
EndGlobalSection
25+
EndGlobal

AuthDemo/AuthDemo.csproj

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.12" />
11+
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.12" />
13+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.11" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
16+
<PrivateAssets>all</PrivateAssets>
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
</PackageReference>
19+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.12">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
24+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
25+
</ItemGroup>
26+
27+
</Project>

AuthDemo/Context/AuthDemoDbContext.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using AuthDemo.Models;
2+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
3+
using Microsoft.EntityFrameworkCore;
4+
5+
namespace AuthDemo.Context
6+
{
7+
public class AuthDemoDbContext : IdentityDbContext
8+
{
9+
public AuthDemoDbContext(DbContextOptions options) : base(options)
10+
{
11+
}
12+
13+
public DbSet<Employee> Employees { get; set; }
14+
}
15+
}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using AuthDemo.Models;
2+
using AuthDemo.Services;
3+
using Microsoft.AspNetCore.Mvc;
4+
5+
namespace AuthDemo.Controllers
6+
{
7+
[Route("api/[controller]")]
8+
[ApiController]
9+
public class AuthController : ControllerBase
10+
{
11+
private readonly IAuthService _authService;
12+
13+
public AuthController(IAuthService authService)
14+
{
15+
_authService = authService;
16+
}
17+
18+
[HttpPost("Register")]
19+
public async Task<IActionResult> RegisterUser(LoginUser user)
20+
{
21+
if (await _authService.RegisterUser(user))
22+
{
23+
return Ok("Successfully done");
24+
}
25+
26+
return BadRequest("Something went wrong");
27+
}
28+
29+
[HttpPost("Login")]
30+
public async Task<IActionResult> Login(LoginUser user)
31+
{
32+
if (!ModelState.IsValid)
33+
{
34+
return BadRequest();
35+
}
36+
37+
if (await _authService.Login(user))
38+
{
39+
var tokenString = _authService.GenerateTokenService(user);
40+
return Ok(tokenString);
41+
}
42+
43+
return BadRequest();
44+
}
45+
}
46+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace AuthDemo.Controllers
5+
{
6+
[Authorize]
7+
[Route("api/[controller]")]
8+
[ApiController]
9+
public class TestController : ControllerBase
10+
{
11+
[HttpGet]
12+
public string Get()
13+
{
14+
return "You hit me!";
15+
}
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
3+
namespace AuthDemo.Controllers
4+
{
5+
[ApiController]
6+
[Route("[controller]")]
7+
public class WeatherForecastController : ControllerBase
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
private readonly ILogger<WeatherForecastController> _logger;
15+
16+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
17+
{
18+
_logger = logger;
19+
}
20+
21+
[HttpGet(Name = "GetWeatherForecast")]
22+
public IEnumerable<WeatherForecast> Get()
23+
{
24+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
25+
{
26+
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
27+
TemperatureC = Random.Shared.Next(-20, 55),
28+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
29+
})
30+
.ToArray();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)