Skip to content

Instantly share code, notes, and snippets.

@JayArrowz
Created August 3, 2020 20:51
Show Gist options
  • Save JayArrowz/5dc7bc3b53eae46a52deeed759bdb035 to your computer and use it in GitHub Desktop.
Save JayArrowz/5dc7bc3b53eae46a52deeed759bdb035 to your computer and use it in GitHub Desktop.
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Ripple.Abstractions.Model;
using Serilog;
using System;
using System.Threading.Tasks;
namespace Ripple.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class AuthorizeController : ControllerBase
{
private readonly Business.Login.AuthenticationState _state;
public AuthorizeController(Business.Login.AuthenticationState state)
{
_state = state;
}
[HttpPost]
public async Task<IActionResult> Login(LoginParameters parameters)
{
try
{
await _state.Login(parameters);
}
catch (Exception e)
{
Log.Logger.Error(e, nameof(Login));
return BadRequest(e.Message);
}
return Redirect("/dashboard");
}
[HttpPost]
public async Task<IActionResult> Register(RegisterParameters parameters)
{
try
{
await _state.Register(parameters);
}
catch (Exception e)
{
Log.Logger.Error(e, nameof(Register));
return BadRequest(e.Message);
}
return Ok();
}
[Authorize]
[HttpGet]
public async Task<IActionResult> Logout()
{
await _state.Logout();
return Redirect("/login");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment