60 lines
1.9 KiB
C#
Executable File
60 lines
1.9 KiB
C#
Executable File
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Cors;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Opsoft.NetCore.O3App.Domain.Models;
|
|
|
|
namespace Opsoft.NetCore.O3App.WebApi.Controllers
|
|
{
|
|
[EnableCors("any")]
|
|
public class AuthenticationController : Controller
|
|
{
|
|
private readonly IAuthenticateService _authService;
|
|
public AuthenticationController(IAuthenticateService authService)
|
|
{
|
|
this._authService = authService;
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public ActionResult RequestToken([FromBody] LoginRequest request)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest("Invalid Request");
|
|
}
|
|
string token;
|
|
if (_authService.IsAuthenticated(request, out token))
|
|
{
|
|
return Ok(new { ErrCode = 0, Data = new {request.UserName, request.errtype, token } });
|
|
}
|
|
else
|
|
{
|
|
return Ok(new { ErrCode = 0, Data = new { request.UserName, request.errtype, token = "" } });
|
|
}
|
|
}
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost]
|
|
public ActionResult FaceRequestToken([FromBody] LoginRequest request)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest("Invalid Request");
|
|
}
|
|
string token;
|
|
if (_authService.IsAuthenticated(request, out token))
|
|
{
|
|
return Ok(new { ErrCode = 0, Data = new { request.UserName, request.errtype, token } });
|
|
}
|
|
else
|
|
{
|
|
return Ok(new { ErrCode = 0, Data = new { request.UserName, request.errtype, token = "" } });
|
|
}
|
|
}
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
return Ok("AuthenticationController");
|
|
}
|
|
}
|
|
} |