/*
* 测试
*/
using System;
using System.Web;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using MySystem.Models.Bs;
using Library;
using LitJson;
using Microsoft.AspNetCore.Authorization;
using MySystem.Service.Bs;
namespace MySystem.Areas.Api.Controllers.v1
{
[Area("Api")]
[Route("Api/v1/[controller]/[action]")]
public class TestController : BaseController
{
public TestController(IHttpContextAccessor accessor) : base(accessor)
{
}
#region 测试方法
///
/// 产品库列表
///
///
// [HttpPost]
// [Authorize]
[Route("/main/test/all")]
public JsonResult List(string value)
{
value = PublicFunction.DesDecrypt(value);
JsonData data = JsonMapper.ToObject(value);
string userName = "root"; //账号
string pwd = "123456"; //密码
SysAdmin sys = SysAdminService.Query(userName, function.MD5_32(pwd));
if (sys.Id == 0)
{
return Json(new AppResultJson() { Status = "-1", Info = "账号或密码不正确" });
}
int RoleId = int.Parse(function.CheckInt(sys.Role));
SysAdminRole Role = SysAdminRoleService.Query(RoleId);
string RightInfo = function.CheckNull(Role.RightInfo);
Dictionary obj = new Dictionary(); //返回字段
obj.Add("rightList", new AdminRightList().GetRight(sys.Role, RightInfo)); //权限列表
obj.Add("apiToken", PublicFunction.AppToken(sys.AdminName)); //后台所有接口API所需的token
obj.Add("apiTokenExpiredDate", DateTime.Now.AddDays(10).ToString("yyyy-MM-dd HH:mm:ss"));
string token = dbconn.Encrypt3DES(sys.Id.ToString() + "-" + function.ConvertDateTimeInt(DateTime.Now));
RefreshTokens check = RefreshTokensService.Query(sys.Id);
if (check.UserId == 0)
{
Dictionary Fields = new Dictionary();
Fields.Add("UserId", sys.Id);
Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
Fields.Add("RefreshToken", token);
RefreshTokensService.Add(Fields);
}
else
{
Dictionary Fields = new Dictionary();
Fields.Add("ExpiredDate", DateTime.Now.AddDays(10));
Fields.Add("RefreshToken", token);
RefreshTokensService.Edit(Fields, sys.Id);
}
List roles = new List();
roles.Add(sys.Role);
obj.Add("roles", roles);
obj.Add("realName", sys.RealName);
obj.Add("refreshToken", token); //主token,用于刷新apiToken
AppConfig.LoginSession.sysId = sys.Id;
AppConfig.LoginSession.sysAdminName = sys.AdminName;
AppConfig.LoginSession.sysRealName = sys.RealName;
return Json(new AppResultJson() { Status = "1", Info = "", Data = obj });
}
#endregion
}
}