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);
 | 
					            await _channel.BasicConsumeAsync(_queue, true, consumer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			while (true);
 | 
								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
 | 
					        // Connects to rabbitMQ
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@ using Api.Models;
 | 
				
			|||||||
using Api.DBAccess;
 | 
					using Api.DBAccess;
 | 
				
			||||||
using Microsoft.AspNetCore.Authorization;
 | 
					using Microsoft.AspNetCore.Authorization;
 | 
				
			||||||
using Api.BusinessLogic;
 | 
					using Api.BusinessLogic;
 | 
				
			||||||
 | 
					using System.Security.Claims;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Api.Controllers
 | 
					namespace Api.Controllers
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -21,17 +22,23 @@ namespace Api.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Sends the userId to deviceLogic
 | 
					        // Sends the userId to deviceLogic
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [HttpGet("{userId}")]
 | 
					        [HttpGet]
 | 
				
			||||||
        public async Task<IActionResult> GetDevices(int userId)
 | 
					        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);
 | 
					            return await _deviceLogic.GetDevices(userId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Sends the device and userId to deviceLogic
 | 
					        // Sends the device and userId to deviceLogic
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [HttpPost("adddevice/{userId}")]
 | 
					        [HttpPost("adddevice")]
 | 
				
			||||||
        public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
 | 
					        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);
 | 
					            return await _deviceLogic.AddDevice(device, userId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -37,17 +37,23 @@ namespace Api.Controllers
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Sends the user and userId to userLogic
 | 
					        // Sends the user and userId to userLogic
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [HttpPut("Edit/{userId}")]
 | 
					        [HttpPut("Edit")]
 | 
				
			||||||
        public async Task<IActionResult> EditUser([FromBody] User user, int userId)
 | 
					        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);
 | 
					            return await _userLogic.EditProfile(user, userId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Sends the userId to userLogic
 | 
					        // Sends the userId to userLogic
 | 
				
			||||||
        [Authorize]
 | 
					        [Authorize]
 | 
				
			||||||
        [HttpDelete("Delete/{userId}")]
 | 
					        [HttpDelete("Delete")]
 | 
				
			||||||
        public async Task<IActionResult> DeleteUser(int userId)
 | 
					        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);
 | 
					            return await _userLogic.DeleteUser(userId);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user