学习ASP.NET Core的身份认证(基于JwtBearer的身份认证9)
[HttpPost]
public async Task<ApiResult> Login([FromBody]UserInfo info)
{
try
{
if (_dbClient.Queryable<AppUser>().Any(r => (r.Account == info.Name) && (r.Password == info.Password)))
{
AppUser curUser = _dbClient.Queryable<AppUser>().First(r => (r.Account == info.Name) && (r.Password == info.Password));
ApiResult result = new ApiResult();
result.UserName = curUser.Name;
result.Msg = GetToken(info.Name);
return result;
}
else
{
return new ApiResult("身份验证失败", 500, false);
}
}
catch(Exception ex)
{
return new ApiResult(ex.Message, 500, false);
}
}
[Authorize]
[HttpGet]
public async Task<ApiResult> GetDataByPage(int page,int limit)
{
ApiResult result = new ApiResult();
result.StatusCode = 0;
Records data = new Records();
data.Count=_dbClient.Queryable<EnvironmentRecord>().Count();
data.Data = _dbClient.Queryable<EnvironmentRecord>().ToPageList(Convert.ToInt32(page), limit).ToList();
result.Data = data;
return result;
}