Skip to content

Commit 8c31828

Browse files
author
Paul Frank
committed
Merge branch 'feature/pawel' into backend-dev
2 parents 5f34dd8 + d8db01d commit 8c31828

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

TableBookingAPI/TableBooking/Controllers/BookingController.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,49 @@
11
using System.Security.Claims;
22
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Identity;
34
using Microsoft.AspNetCore.Mvc;
45
using TableBooking.Api.Interfaces;
6+
using TableBooking.Api.Services;
57
using TableBooking.Model.Dtos.BookingDtos;
8+
using TableBooking.Model.Models;
69

7-
namespace TableBooking.Controllers
10+
11+
namespace TableBooking.Api.Controllers
812
{
9-
[Authorize]
1013
[Route("[controller]")]
1114
[ApiController]
15+
[Authorize]
1216
public class BookingController : ControllerBase
1317
{
14-
private IBookingService _bookingService;
15-
public BookingController(IBookingService bookingService)
18+
private readonly IBookingService _bookingService;
19+
private readonly UserManager<AppUser> _userManager;
20+
21+
public BookingController(IBookingService bookingService, UserManager<AppUser> userManager)
1622
{
1723
_bookingService = bookingService;
24+
_userManager = userManager;
1825
}
1926

27+
// private async Task<AppUser> GetCurrentUserAsync()
28+
// {
29+
// //_userService.GetUserAsync(HttpContext.User);
30+
// //_userService.
31+
// }
32+
33+
2034
[HttpGet("GetAllUserBookings")]
2135
public async Task<IActionResult> GetUserBookings()
2236
{
2337
var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
38+
2439
return await _bookingService.GetAllBookings(userId);
2540
}
2641

2742
[HttpGet("GetById/{id}")]
2843
public async Task<IActionResult> GetUserBookingById(Guid id)
2944
{
3045
var userId = Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
46+
3147
return await _bookingService.GetBookingByIdAsync(id, userId);
3248
}
3349

TableBookingAPI/TableBooking/Controllers/UserController.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.Security.Claims;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
24
using TableBooking.Api.Interfaces;
35
using TableBooking.Model.Dtos.UserDtos;
46

57
namespace TableBooking.Controllers
68
{
79
[Route("[controller]")]
810
[ApiController]
11+
[Authorize]
912
public class UserController : ControllerBase
1013
{
1114
private IUserService _userService;
@@ -17,16 +20,25 @@ public UserController(IUserService userService)
1720

1821
[HttpPost]
1922
[Route("register")]
23+
[AllowAnonymous]
2024
public async Task<IActionResult> Register([FromBody] UserRegisterDto userRegisterDTO)
2125
{
2226
return await _userService.Register(userRegisterDTO);
2327
}
2428

2529
[HttpPost]
30+
[AllowAnonymous]
2631
[Route("login")]
2732
public async Task<IActionResult> Login([FromBody] UserLoginDto userLoginDTO)
2833
{
2934
return await _userService.Login(userLoginDTO);
3035
}
36+
37+
[HttpPost]
38+
[Route("logout")]
39+
public async Task<IActionResult> Logout()
40+
{
41+
throw new NotImplementedException();
42+
}
3143
}
3244
}

TableBookingAPI/TableBooking/Program.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using TableBooking.Logic.Converters.TableConverters;
1818
using TableBooking.Logic.Converters.RatingConverters;
1919
using TableBooking.Logic.Converters.UserConverters;
20+
using System.Security.Claims;
2021

2122
var builder = WebApplication.CreateBuilder(args);
2223

@@ -116,13 +117,15 @@
116117
};
117118
});
118119

119-
builder.Services.AddAuthorization();
120-
121120
builder.Services.Configure<IdentityOptions>(options =>
122121
{
123122
options.User.RequireUniqueEmail = true;
123+
options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier;
124124
});
125125

126+
//builder.Services.AddHttpContextAccessor();
127+
builder.Services.AddAuthorization();
128+
126129
builder.Services.AddScoped<IUnitOfWork, UnitOfWork>();
127130

128131
builder.Services.AddTransient<ITableConverter, TableConverter>(); // doczytaj debilu

TableBookingAPI/TableBooking/Services/UserService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public async Task<IActionResult> Login(UserLoginDto dto)
5959
var authClaims = new List<Claim>
6060
{
6161
new Claim(ClaimTypes.Name, user.UserName),
62-
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
62+
new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
63+
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
6364
};
6465

6566
var token = GetToken(authClaims);
@@ -82,7 +83,7 @@ private JwtSecurityToken GetToken(List<Claim> authClaims)
8283
claims: authClaims,
8384
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
8485
);
85-
86+
8687
return token;
8788
}
8889

0 commit comments

Comments
 (0)