Merge branch 'master' into dev/multiple-notes
This commit is contained in:
54
Controllers/LoginController.cs
Normal file
54
Controllers/LoginController.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace BinaryDad.Notes.Controllers
|
||||
{
|
||||
public class LoginController : Controller
|
||||
{
|
||||
[Route("login")]
|
||||
public IActionResult Login()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[ActionName(nameof(Login))]
|
||||
[Route("login")]
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> LoginPost([Required] string passphrase, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var appPassphrase = Environment.GetEnvironmentVariable("APP_PASSPHRASE");
|
||||
|
||||
if (passphrase == appPassphrase)
|
||||
{
|
||||
var claims = new List<Claim>
|
||||
{
|
||||
new Claim(ClaimTypes.GivenName, "Ryan")
|
||||
};
|
||||
|
||||
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
|
||||
await HttpContext.SignInAsync(new ClaimsPrincipal(claimsIdentity));
|
||||
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
|
||||
ModelState.AddModelError("", "Invalid login");
|
||||
}
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
[Route("logout")]
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
await HttpContext.SignOutAsync();
|
||||
|
||||
return Redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,16 @@
|
||||
using BinaryDad.Notes.Models;
|
||||
using BinaryDad.Notes.Models;
|
||||
using BinaryDad.Notes.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace BinaryDad.Notes.Controllers;
|
||||
|
||||
public class HomeController : Controller
|
||||
[Authorize]
|
||||
public class NoteController : Controller
|
||||
{
|
||||
private readonly INoteService noteService;
|
||||
|
||||
public HomeController(INoteService noteService)
|
||||
public NoteController(INoteService noteService)
|
||||
{
|
||||
this.noteService = noteService;
|
||||
}
|
Reference in New Issue
Block a user