Gets userId from the jwttoken
This commit is contained in:
parent
b8bb86edca
commit
f6e2c8f450
@ -70,18 +70,6 @@ namespace Api.AMQPReciever
|
||||
await _channel.BasicConsumeAsync(_queue, true, consumer);
|
||||
|
||||
while (true);
|
||||
|
||||
await Dispose();
|
||||
}
|
||||
|
||||
// Disconnects from rabbitMQ
|
||||
private async Task<bool> Dispose()
|
||||
{
|
||||
await _channel.CloseAsync();
|
||||
await _conn.CloseAsync();
|
||||
await _channel.DisposeAsync();
|
||||
await _conn.DisposeAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Connects to rabbitMQ
|
||||
|
@ -3,6 +3,7 @@ using Api.Models;
|
||||
using Api.DBAccess;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Api.BusinessLogic;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Api.Controllers
|
||||
{
|
||||
@ -21,17 +22,23 @@ namespace Api.Controllers
|
||||
|
||||
// Sends the userId to deviceLogic
|
||||
[Authorize]
|
||||
[HttpGet("{userId}")]
|
||||
public async Task<IActionResult> GetDevices(int userId)
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> GetDevices()
|
||||
{
|
||||
var claims = HttpContext.User.Claims;
|
||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
int userId = Convert.ToInt32(userIdString);
|
||||
return await _deviceLogic.GetDevices(userId);
|
||||
}
|
||||
|
||||
// Sends the device and userId to deviceLogic
|
||||
[Authorize]
|
||||
[HttpPost("adddevice/{userId}")]
|
||||
public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
|
||||
[HttpPost("adddevice")]
|
||||
public async Task<IActionResult> AddDevice([FromBody] Device device)
|
||||
{
|
||||
var claims = HttpContext.User.Claims;
|
||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
int userId = Convert.ToInt32(userIdString);
|
||||
return await _deviceLogic.AddDevice(device, userId);
|
||||
}
|
||||
|
||||
|
@ -37,17 +37,23 @@ namespace Api.Controllers
|
||||
|
||||
// Sends the user and userId to userLogic
|
||||
[Authorize]
|
||||
[HttpPut("Edit/{userId}")]
|
||||
public async Task<IActionResult> EditUser([FromBody] User user, int userId)
|
||||
[HttpPut("Edit")]
|
||||
public async Task<IActionResult> EditUser([FromBody] User user)
|
||||
{
|
||||
var claims = HttpContext.User.Claims;
|
||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
int userId = Convert.ToInt32(userIdString);
|
||||
return await _userLogic.EditProfile(user, userId);
|
||||
}
|
||||
|
||||
// Sends the userId to userLogic
|
||||
[Authorize]
|
||||
[HttpDelete("Delete/{userId}")]
|
||||
public async Task<IActionResult> DeleteUser(int userId)
|
||||
[HttpDelete("Delete")]
|
||||
public async Task<IActionResult> DeleteUser()
|
||||
{
|
||||
var claims = HttpContext.User.Claims;
|
||||
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
|
||||
int userId = Convert.ToInt32(userIdString);
|
||||
return await _userLogic.DeleteUser(userId);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user