jt
2021-06-10 5d0d028456874576560552f5a5c4e8b801786f11
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
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
 
    }
}