Compare commits
3 Commits
e63309e5e3
...
1d4e17dcef
Author | SHA1 | Date | |
---|---|---|---|
|
1d4e17dcef | ||
|
743b3d6941 | ||
|
928c4e7a42 |
@ -1,11 +1,12 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Api.Models;
|
using Api.Models;
|
||||||
using Api.DBAccess;
|
using Api.DBAccess;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace Api.Controllers
|
namespace Api.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("[controller]")]
|
||||||
public class DeviceController : Controller
|
public class DeviceController : Controller
|
||||||
{
|
{
|
||||||
private readonly DBContext _context;
|
private readonly DBContext _context;
|
||||||
@ -15,7 +16,7 @@ namespace Api.Controllers
|
|||||||
_context = context;
|
_context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For at få json webtokens til at virke skriv [Authorize] over de endpoints
|
[Authorize]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetDevices(int userId)
|
public async Task<IActionResult> GetDevices(int userId)
|
||||||
{
|
{
|
||||||
@ -25,6 +26,7 @@ namespace Api.Controllers
|
|||||||
return Ok(devices);
|
return Ok(devices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpPost("adddevice/{userId}")]
|
[HttpPost("adddevice/{userId}")]
|
||||||
public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
|
public async Task<IActionResult> AddDevice([FromBody] Device device, int userId)
|
||||||
{
|
{
|
||||||
@ -34,6 +36,7 @@ namespace Api.Controllers
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpGet("logs/{deviceId}")]
|
[HttpGet("logs/{deviceId}")]
|
||||||
public async Task<IActionResult> GetLogs(int deviceId)
|
public async Task<IActionResult> GetLogs(int deviceId)
|
||||||
{
|
{
|
||||||
@ -43,6 +46,7 @@ namespace Api.Controllers
|
|||||||
return Ok(logs);
|
return Ok(logs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpPut("Edit/{deviceId}")]
|
[HttpPut("Edit/{deviceId}")]
|
||||||
public async Task<IActionResult> EditDevice([FromBody] Device device, int deviceId)
|
public async Task<IActionResult> EditDevice([FromBody] Device device, int deviceId)
|
||||||
{
|
{
|
||||||
|
12
backend/Api/Controllers/HealthController.cs
Normal file
12
backend/Api/Controllers/HealthController.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Api.Controllers
|
||||||
|
{
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class HealthController : Controller
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> Health() { return Ok(); }
|
||||||
|
}
|
||||||
|
}
|
@ -5,11 +5,12 @@ using Microsoft.IdentityModel.Tokens;
|
|||||||
using System.IdentityModel.Tokens.Jwt;
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
namespace Api.Controllers
|
namespace Api.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("[controller]")]
|
||||||
public class UserController : Controller
|
public class UserController : Controller
|
||||||
{
|
{
|
||||||
private readonly DBContext _context;
|
private readonly DBContext _context;
|
||||||
@ -40,6 +41,7 @@ namespace Api.Controllers
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpPut("Edit/{userId}")]
|
[HttpPut("Edit/{userId}")]
|
||||||
public async Task<IActionResult> EditUser([FromBody] User user, int userId)
|
public async Task<IActionResult> EditUser([FromBody] User user, int userId)
|
||||||
{
|
{
|
||||||
@ -49,6 +51,7 @@ namespace Api.Controllers
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize]
|
||||||
[HttpDelete("Delete/{userId}")]
|
[HttpDelete("Delete/{userId}")]
|
||||||
public async Task<IActionResult> DeleteUser(int userId)
|
public async Task<IActionResult> DeleteUser(int userId)
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,11 @@ namespace Api.DBAccess
|
|||||||
public async Task<User> Login(User user)
|
public async Task<User> Login(User user)
|
||||||
{
|
{
|
||||||
var profile = await _context.Users.FirstAsync(u => u.UserName == user.UserName);
|
var profile = await _context.Users.FirstAsync(u => u.UserName == user.UserName);
|
||||||
|
if (profile == null)
|
||||||
|
{
|
||||||
|
profile = await _context.Users.FirstAsync(u => u.Email == user.Email);
|
||||||
|
}
|
||||||
|
|
||||||
string hashedPassword = ComputeHash(user.Password, SHA256.Create(), profile.Salt);
|
string hashedPassword = ComputeHash(user.Password, SHA256.Create(), profile.Salt);
|
||||||
|
|
||||||
if (hashedPassword == user.Password)
|
if (hashedPassword == user.Password)
|
||||||
|
9
backend/Api/Models/Login.cs
Normal file
9
backend/Api/Models/Login.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace Api.Models
|
||||||
|
{
|
||||||
|
public class Login
|
||||||
|
{
|
||||||
|
public string Login { get; set; }
|
||||||
|
|
||||||
|
public string Password { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user