Created
August 3, 2020 20:51
-
-
Save JayArrowz/5dc7bc3b53eae46a52deeed759bdb035 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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