|
@@ -24,6 +24,9 @@ namespace WebAPIBase.API.Controllers
|
|
|
[ServiceFilter(typeof(Filter.TokenAuthorize))]
|
|
|
public class UserController : BaseController
|
|
|
{
|
|
|
+ /// <summary>
|
|
|
+ /// webservice地址
|
|
|
+ /// </summary>
|
|
|
private string webserviceUrl;
|
|
|
/// <summary>
|
|
|
/// 授权校验服务地址
|
|
@@ -36,6 +39,10 @@ namespace WebAPIBase.API.Controllers
|
|
|
private readonly UserManager<AppUser> _userManager;
|
|
|
private readonly IConfiguration _configuration;
|
|
|
/// <summary>
|
|
|
+ /// 供应商登录接口地址
|
|
|
+ /// </summary>
|
|
|
+ private string supplyUrl;
|
|
|
+ /// <summary>
|
|
|
/// 令牌获取和验证类
|
|
|
/// </summary>
|
|
|
private readonly ITokenHelper tokenHelper = null;
|
|
@@ -49,8 +56,8 @@ namespace WebAPIBase.API.Controllers
|
|
|
|
|
|
|
|
|
webserviceUrl = Configuration["Logging:AppSettings:webserviceUrl"];
|
|
|
- validServiceUrl = "http://111.198.38.3:8899/license";
|
|
|
-
|
|
|
+ validServiceUrl = Configuration["Logging:AppSettings:validServiceUrl"];
|
|
|
+ supplyUrl = configuration["Logging:AppSettings:supplyUrl"];
|
|
|
_userManager = userManager;
|
|
|
_signInManager = signInManager;
|
|
|
_configuration = configuration;
|
|
@@ -137,46 +144,46 @@ namespace WebAPIBase.API.Controllers
|
|
|
|
|
|
#region 写入系统日志
|
|
|
var log = new SysBusinessLog();
|
|
|
- log.LogClass = "SystemUser";
|
|
|
- log.LogTime = DateTime.Now;
|
|
|
- log.ApplicationId2 = loginUser.User.UserCode;
|
|
|
- log.LogType = "登录";
|
|
|
- log.OperatePersonId = Convert.ToInt32(loginUser.User.UserCode);
|
|
|
- log.LogRemark = "";
|
|
|
- log.OperatePerson = loginUser.name;
|
|
|
- new SysBusinessLogManager().Insert(log); //插入系统日志
|
|
|
+ log.LogClass = "SystemUser";
|
|
|
+ log.LogTime = DateTime.Now;
|
|
|
+ log.ApplicationId2 = loginUser.User.UserCode;
|
|
|
+ log.LogType = "登录";
|
|
|
+ log.OperatePersonId = Convert.ToInt32(loginUser.User.UserCode);
|
|
|
+ log.LogRemark = "";
|
|
|
+ log.OperatePerson = loginUser.name;
|
|
|
+ new SysBusinessLogManager().Insert(log); //插入系统日志
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
else //登录失败,则判断是否供应商登录
|
|
|
{
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- var res1 = new ApiResponse
|
|
|
- {
|
|
|
- Code = 200,
|
|
|
- IsSuccess = false,
|
|
|
- ErrMsg = login.msg
|
|
|
|
|
|
- };
|
|
|
- return Json(res1);
|
|
|
-
|
|
|
+
|
|
|
+ var res1 = new ApiResponse
|
|
|
+ {
|
|
|
+ Code = 200,
|
|
|
+ IsSuccess = false,
|
|
|
+ ErrMsg = login.msg
|
|
|
+
|
|
|
+ };
|
|
|
+ return Json(res1);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
TnToken tnToken;
|
|
|
-
|
|
|
- //获取令牌,返回客户端
|
|
|
- Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
|
|
|
+
|
|
|
+ //获取令牌,返回客户端
|
|
|
+ Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
|
|
|
{
|
|
|
{ "UserID", user.UserID }
|
|
|
};
|
|
|
- tnToken = tokenHelper.CreateToken(keyValuePairs);
|
|
|
+ tnToken = tokenHelper.CreateToken(keyValuePairs);
|
|
|
+
|
|
|
+ new Utils.CacheHelper(_memoryCache).SetCache(loginUser.User.UserID, loginUser.User);
|
|
|
+
|
|
|
|
|
|
- new Utils.CacheHelper(_memoryCache).SetCache(loginUser.User.UserID, loginUser.User);
|
|
|
-
|
|
|
-
|
|
|
var res = new ApiResponse
|
|
|
{
|
|
|
Code = 200,
|
|
@@ -308,32 +315,57 @@ namespace WebAPIBase.API.Controllers
|
|
|
//}
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+ #region 请求供应商系统登录
|
|
|
+ var list = new List<Dictionary<string, string>>();
|
|
|
+ var dic1 = new Dictionary<string, string>();
|
|
|
+ dic1.Add("loginName", request.UserName);
|
|
|
+ dic1.Add("pwd", request.Password);
|
|
|
+ list.Add(dic1);
|
|
|
+ var res2 = HttpWebRequestHelper.RequestGet(supplyUrl, list);
|
|
|
+ logger.Info("res2:" + res2);
|
|
|
+ var obj = JsonConvert.DeserializeObject<dynamic>(res2);
|
|
|
+ if (obj.body.code != 200)
|
|
|
+ {
|
|
|
+ var res1 = new ApiResponse
|
|
|
+ {
|
|
|
+ Code = 500,
|
|
|
+ IsSuccess = false,
|
|
|
+ ErrMsg = obj.body.msg
|
|
|
+
|
|
|
+ };
|
|
|
+ return Json(res1);
|
|
|
+ }
|
|
|
+ var supplierCode = (string)obj.body.msg.supplierCode;
|
|
|
+ logger.Info($"suppliercode:{supplierCode}");
|
|
|
+
|
|
|
+ if (supplierCode.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ var res1 = new ApiResponse
|
|
|
+ {
|
|
|
+ Code = 200,
|
|
|
+ IsSuccess = false,
|
|
|
+ ErrMsg = "供应商不存在"
|
|
|
+
|
|
|
+ };
|
|
|
+ return Json(res1);
|
|
|
+ }
|
|
|
+ #endregion
|
|
|
+
|
|
|
+
|
|
|
var loginUser = new LoginUserDTO();
|
|
|
|
|
|
//loginUser.IsSuccess = false;
|
|
|
-
|
|
|
|
|
|
- if (true)
|
|
|
+
|
|
|
+ if (true)
|
|
|
+ {
|
|
|
+ string suppliercode = supplierCode;
|
|
|
+ var service = new SupplierManager();
|
|
|
+ var supplier = service.GetById(suppliercode);
|
|
|
+ if (supplier != null) //登录成功
|
|
|
{
|
|
|
- string suppliercode = "100004";
|
|
|
- var service = new SupplierManager();
|
|
|
- var supplier = service.GetById(suppliercode);
|
|
|
- if (supplier != null) //登录成功
|
|
|
- {
|
|
|
- loginUser.Supplier = supplier;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- var res1 = new ApiResponse
|
|
|
- {
|
|
|
- Code = 200,
|
|
|
- IsSuccess = false,
|
|
|
- ErrMsg = "登录失败,无此供应商"
|
|
|
-
|
|
|
- };
|
|
|
- return Json(res1);
|
|
|
- }
|
|
|
+ loginUser.Supplier = supplier;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -341,25 +373,37 @@ namespace WebAPIBase.API.Controllers
|
|
|
{
|
|
|
Code = 200,
|
|
|
IsSuccess = false,
|
|
|
- ErrMsg = "登录失败"
|
|
|
+ ErrMsg = "登录失败,无此供应商"
|
|
|
|
|
|
};
|
|
|
return Json(res1);
|
|
|
}
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var res1 = new ApiResponse
|
|
|
+ {
|
|
|
+ Code = 200,
|
|
|
+ IsSuccess = false,
|
|
|
+ ErrMsg = "登录失败"
|
|
|
+
|
|
|
+ };
|
|
|
+ return Json(res1);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
TnToken tnToken;
|
|
|
-
|
|
|
- //获取令牌,返回客户端
|
|
|
- Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
|
|
|
+
|
|
|
+ //获取令牌,返回客户端
|
|
|
+ Dictionary<string, string> keyValuePairs = new Dictionary<string, string>
|
|
|
{
|
|
|
{ "UserID", "supplier"+loginUser.Supplier.SupplierCode }
|
|
|
};
|
|
|
- tnToken = tokenHelper.CreateToken(keyValuePairs);
|
|
|
+ tnToken = tokenHelper.CreateToken(keyValuePairs);
|
|
|
+
|
|
|
+ new Utils.CacheHelper(_memoryCache).SetCache("supplier" + loginUser.Supplier.SupplierCode, loginUser.Supplier);
|
|
|
|
|
|
- new Utils.CacheHelper(_memoryCache).SetCache("supplier" + loginUser.Supplier.SupplierCode, loginUser.Supplier);
|
|
|
-
|
|
|
|
|
|
var res = new ApiResponse
|
|
|
{
|
|
@@ -460,4 +504,14 @@ namespace WebAPIBase.API.Controllers
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 供应商应答
|
|
|
+ /// </summary>
|
|
|
+ public class SupplyResponse
|
|
|
+ {
|
|
|
+ public string code { get; set; }
|
|
|
+ public string message { get; set; }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|