2020-03-30 17:14:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
using TestWeb.Models;
|
2020-12-21 16:34:48 +08:00
|
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
|
|
|
using System.Security.Claims;
|
2020-03-30 17:14:07 +08:00
|
|
|
|
|
|
|
|
|
|
namespace TestWeb.Controllers
|
|
|
|
|
|
{
|
|
|
|
|
|
public class HomeController : Controller
|
|
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<HomeController> _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public HomeController(ILogger<HomeController> logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-12-21 16:34:48 +08:00
|
|
|
|
public async Task<IActionResult> Index()
|
2020-03-30 17:14:07 +08:00
|
|
|
|
{
|
2020-12-21 16:34:48 +08:00
|
|
|
|
if (!User.Identity.IsAuthenticated) {
|
|
|
|
|
|
var identity = new ClaimsIdentity("form");
|
|
|
|
|
|
identity.AddClaims(new Claim[] {
|
|
|
|
|
|
new Claim(ClaimTypes.Sid,"uk"),
|
|
|
|
|
|
new Claim(ClaimTypes.Name,"admin")
|
|
|
|
|
|
});
|
|
|
|
|
|
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,new ClaimsPrincipal(identity),new AuthenticationProperties() { IsPersistent=true });
|
|
|
|
|
|
}
|
2020-03-30 17:14:07 +08:00
|
|
|
|
return View();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult Privacy()
|
|
|
|
|
|
{
|
|
|
|
|
|
return View();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
|
|
|
|
public IActionResult Error()
|
|
|
|
|
|
{
|
|
|
|
|
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|