using HH.AutoBom.Core;
|
using HH.WMS.Common;
|
using HH.WMS.Entitys.Func;
|
using HH.WMS.Utils;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Web;
|
|
namespace HH.WMS.WebUI.AppCode
|
{
|
|
public class sys_userService
|
{
|
#region 登录方法
|
/// <summary>
|
/// 登录方法
|
/// </summary>
|
/// <param name="request"></param>
|
/// <param name="appCode"></param>
|
/// <param name="flag"></param>
|
/// <param name="login"></param>
|
/// <returns></returns>
|
public object Login(JObject request, string appCode)
|
{
|
var UserCode = request.Value<string>("usercode");
|
var Password = request.Value<string>("password");
|
|
//用户名密码验证
|
AccountEntity acEntity = Login(UserCode, Password, appCode);
|
if (acEntity != null)
|
{
|
if (acEntity.Code == "0")
|
{
|
return SaveUserEntity(UserCode, acEntity);
|
}
|
else
|
{
|
return new { status = "1", message = acEntity.Data, flag = "" };
|
}
|
}
|
else
|
{
|
return new { status = "1", message = "登录失败!", flag = "" };
|
}
|
}
|
#endregion
|
|
#region 保存用户信息
|
/// <summary>
|
/// 保存用户信息
|
/// </summary>
|
/// <param name="UserCode"></param>
|
/// <param name="acEntity"></param>
|
/// <param name="flag"></param>
|
/// <param name="login"></param>
|
/// <returns></returns>
|
public static object SaveUserEntity(string UserCode, AccountEntity acEntity)
|
{
|
////调用框架中的登陆机制
|
var loginer = new LoginerBase
|
{
|
UserCode = acEntity.Login,
|
UserName = acEntity.UserName,
|
Flag = acEntity.Flag,
|
OrgFlag = acEntity.userExt.OrgFlag,//组织机构标识
|
DepartCode = acEntity.userExt.OrgCode,//所属组织机构
|
ParentOrgCode = acEntity.userExt.Parent_OrgCode_Public,//上级组织机构是否发布为Y的
|
OrgRank = acEntity.userExt.OrgRank, //组织机构价格等级
|
Extend1 = acEntity.Token,//扩展字段 -token
|
Token = acEntity.Token
|
};
|
//var effectiveHours = ZConfig.GetConfigInt("LoginEffectiveHours");
|
//定加密cookie的有效时长
|
FormsAuth.SignIn(loginer.UserCode, loginer, 3600);
|
|
//返回登陆状态
|
return new { status = acEntity.Code, message = acEntity.Data, flag = acEntity.Flag };
|
}
|
#endregion
|
|
#region 默认用户的界面设计
|
/// <summary>
|
/// 默认用户的界面设计
|
/// </summary>
|
/// <returns></returns>
|
public Dictionary<string, object> GetDefaultUserSetttins()
|
{
|
var defaults = new Dictionary<string, object>();
|
defaults.Add("theme", "default");
|
defaults.Add("navigation", "accordion");
|
defaults.Add("gridrows", "20");
|
return defaults;
|
}
|
#endregion
|
|
#region 验证登录
|
/// <summary>
|
/// 验证登录
|
/// </summary>
|
/// <param name="userName"></param>
|
/// <param name="userPwd"></param>
|
/// <param name="appCode"></param>
|
/// <returns></returns>
|
private AccountEntity Login(string userName, string userPwd, string appCode)
|
{
|
//用于返回
|
AccountEntity accEntity = new AccountEntity();
|
//验证当前系统权限
|
MsgEntity msgEntity = new MsgEntity() { Success = true };// VisionLic();
|
if (msgEntity.Success)//如果验证成功
|
{
|
accEntity = VisionLogin(userName, userPwd, appCode);
|
}
|
else
|
{
|
accEntity.Code = "1";
|
accEntity.Data = msgEntity.Msg;
|
}
|
return accEntity;
|
}
|
#endregion
|
|
#region 验证当前系统硬件权限
|
/// <summary>
|
/// 验证当前系统硬件权限
|
/// </summary>
|
/// <returns></returns>
|
private MsgEntity VisionLic()
|
{
|
MsgEntity msgEntity = new MsgEntity() { Success = true };
|
try
|
{
|
string path = System.Web.HttpContext.Current.Server.MapPath("bin\\license.lic");
|
if (System.IO.File.Exists(path))
|
{
|
string desString = System.IO.File.ReadAllText(path, Encoding.Default);
|
string jsonString = "{\"EncryText\":\"" + desString + "\"}";
|
string result = HH.WMS.Common.WebApiManager.HttpAutoBom_Post(jsonString, "api/Account/DecryptLic");
|
msgEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<MsgEntity>(result);
|
}
|
else
|
{
|
msgEntity.Success = false;
|
msgEntity.Msg = "未找到加密文件";
|
}
|
}
|
catch (Exception ex)
|
{
|
msgEntity.Success = false;
|
msgEntity.Msg = ex.Message;
|
}
|
return msgEntity;
|
}
|
#endregion
|
|
#region 验证当前登录用户
|
/// <summary>
|
/// 验证当前登录用户
|
/// </summary>
|
/// <param name="userName"></param>
|
/// <param name="userPwd"></param>
|
/// <param name="appCode"></param>
|
/// <returns></returns>
|
private AccountEntity VisionLogin(string userName, string userPwd, string appCode)
|
{
|
string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
|
var entity = new
|
{
|
userName = userName,
|
userPwd = userPwd,
|
appCode = appCode,
|
ip = ip
|
};
|
string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(entity);//"{\"userName\": \"" + userName + "\", \"userPwd\": \"" + userPwd + "\", \"appCode\": \"" + appCode + "\",\"ip\":\"" + ip + "\"}";
|
|
Log.Info("jsonString", jsonString);
|
string result = HH.WMS.Common.WebApiManager.HttpAutoBom_Post("api/Account/Login", jsonString);
|
Log.Info("result", result);
|
AccountEntity accEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<AccountEntity>(result);
|
|
return accEntity;
|
}
|
#endregion
|
|
}
|
}
|