This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Configuration;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
|
using Icarus.Controllers.Managers;
|
||||||
|
using Icarus.Controllers.Utilities;
|
||||||
|
using Icarus.Models;
|
||||||
|
using Icarus.Models.Context;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/login")]
|
||||||
|
[ApiController]
|
||||||
|
public class LoginController : ControllerBase
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private IConfiguration _config;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Contructors
|
||||||
|
public LoginController(IConfiguration config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region HTTP endpoints
|
||||||
|
public IActionResult Post([FromBody] User user)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Username: {user.Username}");
|
||||||
|
|
||||||
|
TokenManager tk = new TokenManager(_config);
|
||||||
|
|
||||||
|
LoginResult loginRes = tk.RetrieveLoginResult(user);
|
||||||
|
|
||||||
|
return Ok(loginRes);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
using Icarus.Models;
|
||||||
|
|
||||||
|
namespace Icarus.Controllers.Managers
|
||||||
|
{
|
||||||
|
public class TokenManager
|
||||||
|
{
|
||||||
|
#region Fields
|
||||||
|
private IConfiguration _config;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Properties
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
public TokenManager(IConfiguration config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
InitializeValues();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
#region Methods
|
||||||
|
public LoginResult RetrieveLoginResult(User user)
|
||||||
|
{
|
||||||
|
// TODO: Request a token from Auth0
|
||||||
|
|
||||||
|
return new LoginResult
|
||||||
|
{
|
||||||
|
UserId = 0,
|
||||||
|
Username = user.Username,
|
||||||
|
Token = "gggg",
|
||||||
|
Expiration = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeValues()
|
||||||
|
{
|
||||||
|
// TODO: implement parse values necessary to
|
||||||
|
// retrieve a token from the appSettings using
|
||||||
|
// the _config object
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
|
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
|
||||||
<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.15" />
|
<PackageReference Include="MySql.Data.EntityFrameworkCore.Design" Version="8.0.15" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||||
|
<PackageReference Include="RestSharp" Version="106.6.9" />
|
||||||
<PackageReference Include="SevenZip" Version="19.0.0" />
|
<PackageReference Include="SevenZip" Version="19.0.0" />
|
||||||
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.4.0" />
|
||||||
<PackageReference Include="taglib" Version="2.1.0" />
|
<PackageReference Include="taglib" Version="2.1.0" />
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Icarus.Models
|
||||||
|
{
|
||||||
|
public class LoginResult
|
||||||
|
{
|
||||||
|
[JsonProperty("id")]
|
||||||
|
public int UserId { get; set; }
|
||||||
|
[JsonProperty("username")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
[JsonProperty("token")]
|
||||||
|
public string Token { get; set; }
|
||||||
|
[JsonProperty("expiration")]
|
||||||
|
public int Expiration { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user