using Microsoft.AspNetCore.Mvc;
|
using Microsoft.Extensions.Logging;
|
using System.Collections.Generic;
|
using System.Threading.Tasks;
|
using Model.ModelVm;
|
using WMS.Entity.Context;
|
using WMS.IBLL.ISysServer;
|
using Wms.Tools;
|
using Utility;
|
|
namespace Wms.Controllers
|
{
|
[Route("api/[controller]/[action]")]
|
[ApiController]
|
[ServiceFilter(typeof(ApiResponseActionFilter))]
|
public class WeatherForecastController : ControllerBase
|
{
|
private static readonly string[] Summaries = new[]
|
{
|
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
};
|
private readonly ITokenHelper tokenHelper = null;
|
private readonly ILogger<WeatherForecastController> _logger;
|
private readonly IUserInforServer _userMan;
|
private readonly DataContext Db = new DataContext();
|
|
public WeatherForecastController(ITokenHelper _tokenHelper, ILogger<WeatherForecastController> logger, IUserInforServer userMan)
|
{
|
tokenHelper = _tokenHelper;
|
_logger = logger;
|
_userMan = userMan;
|
}
|
|
//[HttpGet]
|
//public IEnumerable<WeatherForecast> Get()
|
//{
|
// var rng = new Random();
|
// var data = Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
// {
|
// Date = DateTime.Now.AddDays(index),
|
// TemperatureC = rng.Next(-20, 55),
|
// Summary = Summaries[rng.Next(Summaries.Length)]
|
// })
|
// .ToArray();
|
// var list = JsonConvert.SerializeObject(data);
|
// _logger.LogWarning("接收物料转移任务:(" + list + "),");
|
// return data;
|
//}
|
|
/// <summary>
|
/// 登录
|
/// </summary>
|
/// <param name="model">登录名</param>
|
/// <returns></returns>
|
[HttpPost]
|
public async Task<string> Login(LoginVm model)
|
{
|
if (ModelState.IsValid)
|
{
|
var userId = await _userMan.LoginAdmin(model.LoginName, model.LoginPwd);
|
|
if (userId != -1) //
|
{
|
if (userId != 0) //正确返回
|
{
|
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
|
{
|
{"loginID", userId.ToString()},
|
{"LoginName", model.LoginName}
|
};
|
var tnToken = tokenHelper.CreateToken(keyValuePairs);
|
return tnToken.TokenStr;
|
}
|
else //当前账号被禁用
|
{
|
//return this.ErrorData($"当前账号已被禁用");
|
throw Oops.Bah("当前账号已被禁用");
|
}
|
}
|
else //账号密码错误
|
{
|
throw Oops.Bah("当前账号或密码错误");
|
}
|
}
|
else //数据格式错误
|
{
|
throw Oops.Bah("数据格式错误");
|
}
|
}
|
/// <summary>
|
/// 登录
|
/// </summary>
|
/// <returns></returns>
|
//[HttpPost]
|
//public IActionResult ceshi()
|
//{
|
// //if (ModelState.IsValid)
|
// //{
|
// try
|
// {
|
// //获取当前登录的用户ID
|
// var claimsIdentity = this.User.Identity as ClaimsIdentity;
|
// var userId = claimsIdentity.FindFirst(ClaimTypes.Name)?.Value;
|
// var bolls = _userMan.CeShi();
|
|
// return Ok(new { code = 200, data = bolls });
|
|
// }
|
// catch (Exception e)
|
// {
|
// return Ok(new { code = 400, ErrorMsg = "请联系管理员/" + e.Message });
|
// }
|
// //}
|
// //else //数据格式错误
|
// //{
|
// // return Ok(new { code = 400, ErrorMsg = "数据格式错误" });
|
// //}
|
//}
|
}
|
}
|