You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB
C#

using AuthStudy.WebApp.VModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AuthStudy.WebApp.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class AccountsController : ControllerBase
{
public AccountsController()
{
}
[Authorize]
[HttpGet]
public IActionResult GetAll()
{
//输出认证信息
foreach (var claim in User.Claims)
{
Console.WriteLine($"{claim.Type}={claim.Value}");
}
List<AccountVM> accounts = new()
{
new AccountVM(){ Name="张三", Email="zhangsan@qq.com", Password="123456"},
new AccountVM(){ Name="小明", Email="xiaoming@qq.com", Password="123456"},
new AccountVM(){ Name="癫子", Email="dianzi@qq.com", Password="123456"}
};
return new JsonResult(accounts);
}
[HttpPost]
public IActionResult Login(string LoginName, string LoginPassword)
{
var info = new { Name = LoginName, Roles = "Admin" };
return new JsonResult(info);
}
}
}