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
using System.Web.Mvc;
using HH.AutoBom.Core;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HH.WMS.WebUI.AppCode;
using HH.WMS.Common;
using System.Text;
using HH.WMS.Entitys.Func;
using System.Net;
using System.Configuration;
using Newtonsoft.Json;
using HH.WMS.Entitys;
using HH.WMS.Entitys.Sys;
using HH.WMS.Common.External; 
 
namespace HH.WMS.WebUI.Controllers
{
    [AllowAnonymous]
    [MvcMenuFilter(false)]
 
    public class LoginController : Controller
    {
 
        public ActionResult Index()
        {
            ViewBag.CnName =Constants.SysConfig.APP_NAME +"-WMS";
            ViewBag.EnName = "HanHeIntelligent-WMS";
            ViewBag.Company = "合肥汉和智能物流科技有限公司";
            ViewBag.isDisplayTechnicalSupport = ProjectConfigs.isDisplayTechnicalSupport;
            ViewBag.isDisplaySystemIcon = ProjectConfigs.isDisplaySystemIcon;
            ViewBag.projectCode = Constants.SysConfig.PROJECT_CODE;
            if (string.IsNullOrEmpty(Constants.SysConfig.WMS_API) ||string.IsNullOrEmpty(Constants.SysConfig.APP_CODE))
            {
                //ViewData["CN_S_WMS_API"] = Constants.GetConfig("CN_S_WMS_API");
                //ViewData["IsNeedConfig"] = 1;
                return RedirectToAction("SysConfig", "Sys/SysSet");
                return View();
            }
            else
            {
                //HttpWebResponse response = null;
                //try
                //{
                //    HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://" + Constants.config["CN_S_WMS_API"]);
                //    response = (HttpWebResponse)myReq.GetResponse();
                //}
                //catch (Exception ex)
                //{
                //    return View("../../Areas/Sys/Views/SysSet/SysConfig");
                //}
                //if (response.StatusCode == HttpStatusCode.OK)
                //{
                //    //通
                //    WebApiManager.HttpWMS_Get("api/Login/InitConfig");
                return View("Index");
                //}
                //else
                //{
                //    //不通
                //    return View("../../Areas/Sys/Views/SysSet/SysConfig");
                //}
            }
        }
 
        public ActionResult Location()
        {
            return View("Location");
        }
 
        #region 登录接口
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public JsonResult DoAction(JObject request)
        {
            try
            {
                string appCode = HH.WMS.Common.Constants.SysConfig.APP_CODE;
                var message = new sys_userService().Login(request, appCode);
                return Json(message, JsonRequestBehavior.DenyGet);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion
 
        #region 验证登录
        /// <summary>
        /// 验证登录
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="userFlag"></param>
        /// <param name="appCode"></param>
        /// <returns></returns>
        public ActionResult Validator(string userName, string flag, string appCode)
        {
            var entity = new
            {
                userName = userName,
                flag = flag,
                appCode = appCode,
                EncryText = ""
            };
            string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(entity);
            string ReturnJson = HH.WMS.Common.WebApiManager.HttpAutoBom_Post("api/Account/Validator", jsonString);
            AccountEntity accountEntity = Newtonsoft.Json.JsonConvert.DeserializeObject<AccountEntity>(ReturnJson);
            var message = sys_userService.SaveUserEntity(userName, accountEntity);
 
            HttpCookie tokenCookie = new HttpCookie("UserToken", accountEntity.Flag);
            Response.AppendCookie(tokenCookie);
 
            return Json(accountEntity);
        }
        #endregion
 
        public ActionResult Logout()
        {
            FormsAuth.SingOut();
            return Redirect("~/Login");
        }
 
    }
}