|
|
|
|
@ -1,26 +1,72 @@
|
|
|
|
|
using EVABackend.Models; |
|
|
|
|
using EVABackend.Areas.Identity.Data; |
|
|
|
|
using EVABackend.Models; |
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
|
using Microsoft.AspNetCore.Identity; |
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
|
|
namespace EVABackend.Controllers |
|
|
|
|
{ |
|
|
|
|
[ApiController] |
|
|
|
|
public class EVAController : ControllerBase |
|
|
|
|
{ |
|
|
|
|
EVAContext context = new EVAContext(); |
|
|
|
|
private readonly EVAContext _context; |
|
|
|
|
private readonly UserManager<EVABackendUser> _userManager; |
|
|
|
|
private readonly RoleManager<IdentityRole> _roleManager; |
|
|
|
|
private readonly SignInManager<EVABackendUser> _signInManager; |
|
|
|
|
|
|
|
|
|
public EVAController(UserManager<EVABackendUser> userManager, RoleManager<IdentityRole> roleManager, SignInManager<EVABackendUser> signInManager) |
|
|
|
|
{ |
|
|
|
|
_userManager = userManager; |
|
|
|
|
_roleManager = roleManager; |
|
|
|
|
_signInManager = signInManager; |
|
|
|
|
|
|
|
|
|
_context = new EVAContext(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
|
[Route("login")] |
|
|
|
|
public ActionResult Login() |
|
|
|
|
{ |
|
|
|
|
return Ok(new { status = "Nicht unterstützt" }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
|
[Route("create_dummy_data")] |
|
|
|
|
public async Task<ActionResult> CreateDummyData() |
|
|
|
|
{ |
|
|
|
|
var user = new EVABackendUser |
|
|
|
|
{ |
|
|
|
|
UserName = "Test", |
|
|
|
|
Email = "info@test.de" |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if ((await _userManager.CreateAsync(user, "123Abc!&")).Succeeded) |
|
|
|
|
return Ok(); |
|
|
|
|
|
|
|
|
|
return StatusCode(500); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
|
[Route("login")] |
|
|
|
|
public ActionResult Login([FromBody] string username, string password) |
|
|
|
|
public async Task<ActionResult> Login([FromForm] string username, [FromForm] string password) |
|
|
|
|
{ |
|
|
|
|
return Ok(new { success = true }); |
|
|
|
|
var result = await _signInManager.PasswordSignInAsync(username, password, false, false); |
|
|
|
|
if (result.Succeeded) |
|
|
|
|
{ |
|
|
|
|
return Ok(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return Unauthorized(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
|
[Route("instruments")] |
|
|
|
|
[Authorize] |
|
|
|
|
public ActionResult Instruments() |
|
|
|
|
{ |
|
|
|
|
var instruments = context.Instrumente.ToList(); |
|
|
|
|
var instruments = _context.Instrumente.ToList(); |
|
|
|
|
|
|
|
|
|
return Ok(instruments.ToArray()); |
|
|
|
|
} |
|
|
|
|
|